-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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 HTTP::Server::Response#redirect
#10412
Add HTTP::Server::Response#redirect
#10412
Conversation
Co-authored-by: Sijawusz Pur Rahnama <[email protected]>
Co-authored-by: Sijawusz Pur Rahnama <[email protected]>
Ooops, I mistakenly merged this despite CI errors. 🙈 Sorry. I'll send a fixup right away. |
Or scrap that, I'll just revert it for now. |
This reverts commit abff4f7.
This reverts commit abff4f7.
|
||
url = URI.encode_path(url.to_s) | ||
context.response.headers.add "Location", url | ||
context.response.redirect url |
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.
Apparently this is where the Path
comes from. It is hard to say whether this justifies the use of unrestricted Path
s in the public API.
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.
At least I now remember the reason for adding Path
to the restriction 😅
But I think I'd still stick to the plan and just call to_s
here.
This is a proposal for a method
HTTP::Server::Response#redirect
which offers a simple way to issue redirects from HTTP server handlers.respond_with_status
is a similar convenience method.Redirects are pretty common and a helper for this would be very useful. In fact, there's already an implementation in
StaticFileHandler
. Most web frameworks probably provide a helper for this, too (example: kemal). But it would be nice to have this at hand for plain server handlers. And simple implementations like kemal's could be based on or replaced by the stdlib implementation.