mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2026-10-22 11:46:13 +00:00
Close the connection on an answered upgrade body in process_request (#2637)
When pre_routing_handler or pre_request_handler answers a WebSocket upgrade request, Server::process_request returns before the drain of an unread body and closes the connection only for a 4xx/5xx. A 2xx/3xx answer to an upgrade request with a framed body left that body to be parsed as the next request on the keep-alive connection. Those two early returns now close the connection when the request has a framed body, as the Expect rejection already does.
This commit is contained in:
1 parent
74ef3c4218
commit
41c85c0733
2 files changed
+63
-3
No files matched your search
@@ -15208,10 +15208,15 @@ Server::process_request(Stream &strm, const std::string &remote_addr,
|
||||
// An upgrade request has been through pre-routing before it reaches routing()
|
||||
auto is_upgrade = detail::is_websocket_upgrade(req);
|
||||
if (is_upgrade) {
|
||||
// A response given here leaves the body unread, and it would be parsed as
|
||||
// the next request.
|
||||
auto close_if_answered =
|
||||
close_after_response || detail::has_framed_body(req);
|
||||
|
||||
if (pre_routing_handler_ &&
|
||||
pre_routing_handler_(req, res) == HandlerResponse::Handled) {
|
||||
if (res.status == -1) { res.status = StatusCode::OK_200; }
|
||||
return write_response_with_content(strm, close_after_response, req, res);
|
||||
return write_response_with_content(strm, close_if_answered, req, res);
|
||||
}
|
||||
// Find matching WebSocket handler
|
||||
for (const auto &entry : websocket_handlers_) {
|
||||
@@ -15220,8 +15225,7 @@ Server::process_request(Stream &strm, const std::string &remote_addr,
|
||||
if (pre_request_handler_ &&
|
||||
pre_request_handler_(req, res) == HandlerResponse::Handled) {
|
||||
if (res.status == -1) { res.status = StatusCode::OK_200; }
|
||||
return write_response_with_content(strm, close_after_response, req,
|
||||
res);
|
||||
return write_response_with_content(strm, close_if_answered, req, res);
|
||||
}
|
||||
|
||||
// Compute accept key
|
||||
|
||||
Reference in new issue
Block a user