From 22160d89266dfd2d72ebcb8e93bb5410c7aeaa50 Mon Sep 17 00:00:00 2001 From: cirospaciari Date: Fri, 15 Sep 2023 22:30:25 -0700 Subject: [PATCH] more tests --- src/http_client_async.zig | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/http_client_async.zig b/src/http_client_async.zig index 4894760451..d071bcd451 100644 --- a/src/http_client_async.zig +++ b/src/http_client_async.zig @@ -751,10 +751,14 @@ pub const HTTPThread = struct { if (socket_async_http_abort_tracker.fetchSwapRemove(http.async_http_id)) |socket_ptr| { if (http.client.isHTTPS()) { const socket = uws.SocketTLS.from(socket_ptr.value); - socket.shutdown(); + if(socket.isEstablished() and !socket.isClosed() and !socket.isShutdown()) { + socket.shutdownRead(); + } } else { const socket = uws.SocketTCP.from(socket_ptr.value); - socket.shutdown(); + if(socket.isEstablished() and !socket.isClosed() and !socket.isShutdown()) { + socket.shutdownRead(); + } } } } @@ -1068,7 +1072,7 @@ pub fn onClose( socket: NewHTTPContext(is_ssl).HTTPSocket, ) void { log("Closed {s}\n", .{client.url.href}); - + const in_progress = client.state.stage != .done and client.state.stage != .fail; if (in_progress) { @@ -1099,7 +1103,7 @@ pub fn onClose( } if (in_progress) { - client.fail(error.ConnectionClosed); + client.closeAndFail(error.ConnectionClosed, is_ssl, socket); } } pub fn onTimeout( @@ -1152,7 +1156,7 @@ pub fn onEnd( return; } } - client.fail(error.ConnectionClosed); + client.closeAndFail(error.ConnectionClosed); } pub inline fn getAllocator() std.mem.Allocator { @@ -1558,6 +1562,9 @@ pub fn isKeepAlivePossible(this: *HTTPClient) bool { if (this.http_proxy != null and this.url.isHTTPS()) { return false; } + if (this.signals.get(.aborted)) { + return false; + } return !this.disable_keepalive; } return false; @@ -1864,6 +1871,9 @@ pub const AsyncHTTP = struct { if (this.http_proxy != null and this.url.isHTTPS()) { return false; } + if (this.signals.get(.aborted)) { + return false; + } // check state if (this.state.allow_keepalive and !this.disable_keepalive) return true; }