From 6ce6cb8b1ab0755c5c55d4d8b1620a6fbb4bca54 Mon Sep 17 00:00:00 2001 From: Ciro Spaciari Date: Fri, 24 Nov 2023 16:55:08 -0300 Subject: [PATCH] fix decompress on http --- src/http_client_async.zig | 2 ++ src/js/node/http.ts | 29 ++++++++++++++++++++--------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/http_client_async.zig b/src/http_client_async.zig index a66633ab07fa78..b122e134a14e20 100644 --- a/src/http_client_async.zig +++ b/src/http_client_async.zig @@ -2621,6 +2621,8 @@ pub fn onData(this: *HTTPClient, comptime is_ssl: bool, incoming_data: []const u if (this.state.content_encoding_i < response.headers.len and !this.state.did_set_content_encoding) { // if it compressed with this header, it is no longer because we will decompress it var mutable_headers = std.ArrayListUnmanaged(picohttp.Header){ .items = response.headers, .capacity = response.headers.len }; + // we remove the content encoding header + _ = mutable_headers.swapRemove(this.state.content_encoding_i); this.state.did_set_content_encoding = true; response.headers = mutable_headers.items; this.state.content_encoding_i = std.math.maxInt(@TypeOf(this.state.content_encoding_i)); diff --git a/src/js/node/http.ts b/src/js/node/http.ts index 577b28ddb28b18..65a6f8de4c44ec 100644 --- a/src/js/node/http.ts +++ b/src/js/node/http.ts @@ -694,7 +694,7 @@ class IncomingMessage extends Readable { #bodyStream: ReadableStreamDefaultReader | undefined; #fakeSocket: FakeSocket | undefined = undefined; #noBody = false; - #aborted = false; + aborted = false; #req; url; #type; @@ -720,7 +720,7 @@ class IncomingMessage extends Readable { async #consumeStream(reader: ReadableStreamDefaultReader) { while (true) { var { done, value } = await reader.readMany(); - if (this.#aborted) return; + if (this.aborted) return; if (done) { this.push(null); process.nextTick(destroyBodyStreamNT, this); @@ -747,13 +747,10 @@ class IncomingMessage extends Readable { } } - get aborted() { - return this.#aborted; - } - + //TODO: call from abort signal handler #abort() { - if (this.#aborted) return; - this.#aborted = true; + if (this.aborted) return; + this.aborted = true; var bodyStream = this.#bodyStream; if (!bodyStream) return; bodyStream.cancel(); @@ -766,30 +763,44 @@ class IncomingMessage extends Readable { return (this.#fakeSocket ??= new FakeSocket()); } + set statusCode(val) {} + get statusCode() { return this.#req.status; } + set statusMessage(val) {} + get statusMessage() { return STATUS_CODES[this.#req.status]; } + set httpVersion(val) {} + get httpVersion() { return "1.1"; } + set rawTrailers(val) {} + get rawTrailers() { return []; } + set httpVersionMajor(val) {} + get httpVersionMajor() { return 1; } + set httpVersionMinor(val) {} + get httpVersionMinor() { return 1; } + set trailers(val) {} + get trailers() { return kEmptyObject; } @@ -1365,7 +1376,7 @@ class ClientRequest extends OutgoingMessage { // Timeouts are handled via this.setTimeout. timeout: false, - // TODO: check zlib to disable this + // should be safe to decompress by default if we remove the headers and will be faster decompress: true, }) .then(response => {