summaryrefslogtreecommitdiff
path: root/http/http_connection.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'http/http_connection.hpp')
-rw-r--r--http/http_connection.hpp19
1 files changed, 15 insertions, 4 deletions
diff --git a/http/http_connection.hpp b/http/http_connection.hpp
index c28cde37ae..d5d02e545a 100644
--- a/http/http_connection.hpp
+++ b/http/http_connection.hpp
@@ -249,10 +249,21 @@ class Connection :
thisReq.getHeaderValue(boost::beast::http::field::upgrade),
"websocket"))
{
- handler->handleUpgrade(thisReq, res, std::move(adaptor));
- // delete lambda with self shared_ptr
- // to enable connection destruction
- asyncResp->res.setCompleteRequestHandler(nullptr);
+ asyncResp->res.setCompleteRequestHandler(
+ [self(shared_from_this())](crow::Response& thisRes) {
+ if (thisRes.result() != boost::beast::http::status::ok)
+ {
+ // When any error occurs before handle upgradation,
+ // the result in response will be set to respective
+ // error. By default the Result will be OK (200),
+ // which implies successful handle upgrade. Response
+ // needs to be sent over this connection only on
+ // failure.
+ self->completeRequest(thisRes);
+ return;
+ }
+ });
+ handler->handleUpgrade(thisReq, asyncResp, std::move(adaptor));
return;
}
std::string_view expected =