-
Notifications
You must be signed in to change notification settings - Fork 134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add redirectStatus function #402
Conversation
Thank you @hackeryarn , much appreciate the non breaking change. Will look at this asap. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think letting users redirect with an arbitrary status code is too powerful overall.
Web/Scotty/Trans/Lazy.hs
Outdated
-- OR | ||
-- | ||
-- > redirectStatus status303 "/foo/bar" | ||
redirectStatus :: (Monad m) => Status -> T.Text -> ActionT m a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not constrained enough: one could redirect with a 200 or whatever, which would not make much sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that running a check here and throwing the exception would create a bad user experience. It might be nicer to have a specific ‘redirectX’ functions for each status code, with the bare ‘redirect’ remaining as the 302 version. But that would require quite a few new functions.
@ocramz what are your thoughts on a path forward?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hackeryarn The error codes for redirect are not even that many: 300-307, 307, 308 https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#redirection_messages
I think overall providing them as individual functions would make for more solid API design (e.g redirect301
, redirect302
etc.). WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That’s the direction I was leaning to, just wanted to make sure it wouldn’t clutter the API too much.
I’ll get this updated with the new functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ocramz This should do it. I skipped codes 305
and 306
since they are both deprecated. I also moved all the redirects to their own docs section, that way it's easier for users to find everything they are looking for.
54b5ca7
to
40c02b6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it! Thank you :)
Web/Scotty/Action.hs
Outdated
redirect = E.throw . AERedirect | ||
redirect = redirect302 | ||
|
||
-- | Redirect to given URL with status 300. Like throwing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps you could add the description string to the status codes in the docstring? e.g. 300 (Multiple choices), 301 (Moved permanently) etc? For those who don't know all status codes by heart.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great idea @ocramz! Updated all the doc strings.
40c02b6
to
fa4888c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very good, thank you!
Last thing, could you please add a Changelog entry describing your changes?
fa4888c
to
1f98963
Compare
Thanks for all the reviews @ocramz. Changelog is updated and this is ready. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
This addresses issue #401.
I decided to go with a new function
redirectStatus
. Doing this makes the addition a non breaking change.