diff options
author | 2023-10-10 15:28:08 -0700 | |
---|---|---|
committer | 2023-10-10 15:28:08 -0700 | |
commit | ee2e34866e3bc0d12ba5cb1d5041524776472d71 (patch) | |
tree | 3f71bf8153545396ba38294f8577e77ce0b12439 /src/deps | |
parent | e6d97f2581959d77a5b486faefbfdf094abedf9b (diff) | |
parent | 6301778a589254e2c3c0d95f768fce303f528b03 (diff) | |
download | bun-ee2e34866e3bc0d12ba5cb1d5041524776472d71.tar.gz bun-ee2e34866e3bc0d12ba5cb1d5041524776472d71.tar.zst bun-ee2e34866e3bc0d12ba5cb1d5041524776472d71.zip |
Merge branch 'main' into dylan/github-api-option
Diffstat (limited to 'src/deps')
-rw-r--r-- | src/deps/_libusockets.h | 5 | ||||
-rw-r--r-- | src/deps/libuwsockets.cpp | 29 | ||||
-rw-r--r-- | src/deps/uws.zig | 12 |
3 files changed, 35 insertions, 11 deletions
diff --git a/src/deps/_libusockets.h b/src/deps/_libusockets.h index 5ca0e7df8..e9dbb6938 100644 --- a/src/deps/_libusockets.h +++ b/src/deps/_libusockets.h @@ -264,7 +264,7 @@ void uws_res_write_header(int ssl, uws_res_t *res, const char *key, void uws_res_write_header_int(int ssl, uws_res_t *res, const char *key, size_t key_length, uint64_t value); -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); void uws_res_end_stream(int ssl, uws_res_t *res, bool close_connection); bool uws_res_write(int ssl, uws_res_t *res, const char *data, size_t length); uintmax_t uws_res_get_write_offset(int ssl, uws_res_t *res); @@ -304,7 +304,6 @@ size_t uws_req_get_parameter(uws_req_t *res, unsigned short index, const char **dest); void uws_req_for_each_header(uws_req_t *res, uws_get_headers_server_handler handler, void *user_data); - struct us_loop_t *uws_get_loop(); struct us_loop_t *uws_get_loop_with_native(void* existing_native_loop); @@ -336,4 +335,4 @@ void uws_app_close(int ssl, uws_app_t *app); } #endif -#endif
\ No newline at end of file +#endif 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); diff --git a/src/deps/uws.zig b/src/deps/uws.zig index 7a79e9c0f..f3138c8b9 100644 --- a/src/deps/uws.zig +++ b/src/deps/uws.zig @@ -700,9 +700,9 @@ pub const Timer = opaque { @as(*@TypeOf(ptr), @ptrCast(@alignCast(value_ptr))).* = ptr; } - pub fn deinit(this: *Timer) void { + pub fn deinit(this: *Timer, comptime fallthrough: bool) void { debug("Timer.deinit()", .{}); - us_timer_close(this); + us_timer_close(this, @intFromBool(fallthrough)); } pub fn ext(this: *Timer, comptime Type: type) ?*Type { @@ -946,7 +946,7 @@ const uintmax_t = c_ulong; extern fn us_create_timer(loop: ?*Loop, fallthrough: i32, ext_size: c_uint) *Timer; extern fn us_timer_ext(timer: ?*Timer) *?*anyopaque; -extern fn us_timer_close(timer: ?*Timer) void; +extern fn us_timer_close(timer: ?*Timer, fallthrough: i32) void; extern fn us_timer_set(timer: ?*Timer, cb: ?*const fn (*Timer) callconv(.C) void, ms: i32, repeat_ms: i32) void; extern fn us_timer_loop(t: ?*Timer) ?*Loop; pub const us_socket_context_options_t = extern struct { @@ -1806,8 +1806,8 @@ pub fn NewApp(comptime ssl: bool) type { pub fn writeHeaderInt(res: *Response, key: []const u8, value: u64) void { uws_res_write_header_int(ssl_flag, res.downcast(), key.ptr, key.len, value); } - pub fn endWithoutBody(res: *Response, _: bool) void { - uws_res_end_without_body(ssl_flag, res.downcast()); + pub fn endWithoutBody(res: *Response, close_connection: bool) void { + uws_res_end_without_body(ssl_flag, res.downcast(), close_connection); } pub fn write(res: *Response, data: []const u8) bool { return uws_res_write(ssl_flag, res.downcast(), data.ptr, data.len); @@ -2209,7 +2209,7 @@ extern fn uws_res_write_continue(ssl: i32, res: *uws_res) void; extern fn uws_res_write_status(ssl: i32, res: *uws_res, status: [*c]const u8, length: usize) void; extern fn uws_res_write_header(ssl: i32, res: *uws_res, key: [*c]const u8, key_length: usize, value: [*c]const u8, value_length: usize) void; extern fn uws_res_write_header_int(ssl: i32, res: *uws_res, key: [*c]const u8, key_length: usize, value: u64) void; -extern fn uws_res_end_without_body(ssl: i32, res: *uws_res) void; +extern fn uws_res_end_without_body(ssl: i32, res: *uws_res, close_connection: bool) void; extern fn uws_res_write(ssl: i32, res: *uws_res, data: [*c]const u8, length: usize) bool; extern fn uws_res_get_write_offset(ssl: i32, res: *uws_res) uintmax_t; extern fn uws_res_override_write_offset(ssl: i32, res: *uws_res, uintmax_t) void; |