Skip to content
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

http: to_reply() from redirect_exception #2206

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

WillemKauf
Copy link

This PR adds redirect_exception::to_reply() for construction of a http::reply from a redirect case, with a Location header and optionally a Retry-After header.

@xemul xemul requested a review from nyh April 26, 2024 15:26
@WillemKauf WillemKauf force-pushed the http_exception_headers_syclla branch from ac23cf0 to 6a41444 Compare April 30, 2024 19:26
This function allows for the creation of an `http::reply`
from a thrown `redirect_exception`, with a url for the `Location`
header and an optional `Retry-After` timeout value.
@WillemKauf WillemKauf force-pushed the http_exception_headers_syclla branch from 6a41444 to 6196a68 Compare May 6, 2024 23:59
@xemul
Copy link
Contributor

xemul commented May 23, 2024

@nyh , please review

redirect_exception(const std::string& url, http::reply::status_type status = http::reply::status_type::moved_permanently)
: base_exception("", status), url(url) {
redirect_exception(const std::string& url, http::reply::status_type status = http::reply::status_type::moved_permanently, const std::optional<int>& retry_after = std::nullopt)
: base_exception("", status), url(url), retry_after(retry_after) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should mention in the commit message (and perhaps even split the commit into two) that one of the things that this patch does is to add to add Retry-After header (see https://datatracker.ietf.org/doc/html/rfc7231#section-7.1.3) support for redirections.
It is separate feature from the to_reply() function you are adding in this patch.

@@ -94,6 +93,9 @@ future<std::unique_ptr<http::reply> > routes::handle(const sstring& path, std::u
handler->verify_mandatory_params(*req);
auto r = handler->handle(path, std::move(req), std::move(rep));
return r.handle_exception(_general_handler);
} catch (const redirect_exception& _e) {
*rep = _e.to_reply();
rep->done("json");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This catch was missing previously. It looks like it fixes a bug - can you explain in the commit message what bug this was? Can you perhaps write a unit test for it?

@nyh
Copy link
Contributor

nyh commented May 23, 2024

The commit message made it sound like your patch only added a new API function, but as I noted in the review above, it actually included two more separate changes:

  1. It adds support for Retry-After (https://datatracker.ietf.org/doc/html/rfc7231#section-7.1.3), at least the part for 3xx (redirection), which was missing before. However, I want to ask something (because my command of the RFC is quite rusty) Is this the really only header that makes sense to put on a redirection reply? Shouldn't a redirection allow a more general set of headers to be given, and not specifically Retry-After (which isn't a particularly useful or commonly-used header, to be honest).
  2. It adds a missing catch of redirect_exception. I am guessing there was a reason to adding this, and it's a bug fixed, but it needs to be explained and justified

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants