aboutsummaryrefslogtreecommitdiff
path: root/src/deps/libuwsockets.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/deps/libuwsockets.cpp')
-rw-r--r--src/deps/libuwsockets.cpp29
1 files changed, 27 insertions, 2 deletions
diff --git a/src/deps/libuwsockets.cpp b/src/deps/libuwsockets.cpp
index bb89b33a8..a815e87df 100644
--- a/src/deps/libuwsockets.cpp
+++ b/src/deps/libuwsockets.cpp
@@ -1142,21 +1142,46 @@ extern "C"
}
}
- void uws_res_end_without_body(int ssl, uws_res_t *res)
+ void uws_res_end_without_body(int ssl, uws_res_t *res, bool close_connection)
{
if (ssl)
{
uWS::HttpResponse<true> *uwsRes = (uWS::HttpResponse<true> *)res;
auto *data = uwsRes->getHttpResponseData();
+ if (close_connection)
+ {
+ if (!(data->state & uWS::HttpResponseData<true>::HTTP_CONNECTION_CLOSE))
+ {
+ uwsRes->writeHeader("Connection", "close");
+ }
+ data->state |= uWS::HttpResponseData<true>::HTTP_CONNECTION_CLOSE;
+ }
+ if (!(data->state & uWS::HttpResponseData<true>::HTTP_END_CALLED))
+ {
+ uwsRes->AsyncSocket<true>::write("\r\n", 2);
+ }
data->state |= uWS::HttpResponseData<true>::HTTP_END_CALLED;
data->markDone();
us_socket_timeout(true, (us_socket_t *)uwsRes, uWS::HTTP_TIMEOUT_S);
}
else
{
-
uWS::HttpResponse<false> *uwsRes = (uWS::HttpResponse<false> *)res;
auto *data = uwsRes->getHttpResponseData();
+ if (close_connection)
+ {
+ if (!(data->state & uWS::HttpResponseData<false>::HTTP_CONNECTION_CLOSE))
+ {
+ uwsRes->writeHeader("Connection", "close");
+ }
+ data->state |= uWS::HttpResponseData<false>::HTTP_CONNECTION_CLOSE;
+ }
+ if (!(data->state & uWS::HttpResponseData<false>::HTTP_END_CALLED))
+ {
+ // Some HTTP clients require the complete "<header>\r\n\r\n" to be sent.
+ // If not, they may throw a ConnectionError.
+ uwsRes->AsyncSocket<false>::write("\r\n", 2);
+ }
data->state |= uWS::HttpResponseData<false>::HTTP_END_CALLED;
data->markDone();
us_socket_timeout(false, (us_socket_t *)uwsRes, uWS::HTTP_TIMEOUT_S);