Skip to content

Commit

Permalink
http: make redirect_exception work from inside futures
Browse files Browse the repository at this point in the history
Previously this was only handled from synchronous
code inside a handler, not when thrown from inside
the future returned by the handler.

Signed-off-by: John Spray <jcs@vectorized.io>
  • Loading branch information
jcsp committed Nov 3, 2021
1 parent 99b7bba commit 99f8ed2
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/http/routes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ void verify_param(const request& req, const sstring& param) {
}
}
routes::routes() : _general_handler([this](std::exception_ptr eptr) mutable {
try {
std::rethrow_exception(eptr);
} catch (const redirect_exception& _e) {
auto rep = std::make_unique<reply>();
rep->add_header("Location", _e.url).set_status(_e.status()).done(
"json");
return rep;
} catch (...) {
// Fall through to return exception reply
}

return exception_reply(eptr);
}) {}

Expand Down

0 comments on commit 99f8ed2

Please sign in to comment.