aboutsummaryrefslogtreecommitdiff
path: root/src/deps/libuwsockets.cpp
diff options
context:
space:
mode:
authorGravatar Dylan Conway <dylan.conway567@gmail.com> 2023-10-10 15:28:08 -0700
committerGravatar Dylan Conway <dylan.conway567@gmail.com> 2023-10-10 15:28:08 -0700
commitee2e34866e3bc0d12ba5cb1d5041524776472d71 (patch)
tree3f71bf8153545396ba38294f8577e77ce0b12439 /src/deps/libuwsockets.cpp
parente6d97f2581959d77a5b486faefbfdf094abedf9b (diff)
parent6301778a589254e2c3c0d95f768fce303f528b03 (diff)
downloadbun-ee2e34866e3bc0d12ba5cb1d5041524776472d71.tar.gz
bun-ee2e34866e3bc0d12ba5cb1d5041524776472d71.tar.zst
bun-ee2e34866e3bc0d12ba5cb1d5041524776472d71.zip
Merge branch 'main' into dylan/github-api-option
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);