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

Call middleware during upgrade request #763

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions include/crow/http_connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ namespace crow
bool is_invalid_request = false;
add_keep_alive_ = false;

// Create context
ctx_ = detail::context<Middlewares...>();
req_.middleware_context = static_cast<void*>(&ctx_);
req_.middleware_container = static_cast<void*>(middlewares_);
req_.io_service = &adaptor_.get_io_service();

req_.remote_ip_address = adaptor_.remote_endpoint().address().to_string();

add_keep_alive_ = req_.keep_alive;
Expand All @@ -149,6 +155,9 @@ namespace crow
}
else
{

detail::middleware_call_helper<detail::middleware_call_criteria_only_global,
0, decltype(ctx_), decltype(*middlewares_)>({}, *middlewares_, req_, res, ctx_);
close_connection_ = true;
handler_->handle_upgrade(req_, res, std::move(adaptor_));
return;
Expand All @@ -167,12 +176,7 @@ namespace crow
res.is_alive_helper_ = [self]() -> bool {
return self->adaptor_.is_open();
};

ctx_ = detail::context<Middlewares...>();
req_.middleware_context = static_cast<void*>(&ctx_);
req_.middleware_container = static_cast<void*>(middlewares_);
req_.io_service = &adaptor_.get_io_service();


detail::middleware_call_helper<detail::middleware_call_criteria_only_global,
0, decltype(ctx_), decltype(*middlewares_)>({}, *middlewares_, req_, res, ctx_);

Expand Down
Loading