Skip to content

Commit

Permalink
fix decompress on http
Browse files Browse the repository at this point in the history
  • Loading branch information
cirospaciari committed Nov 24, 2023
1 parent 7a5806b commit 6ce6cb8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/http_client_async.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
29 changes: 20 additions & 9 deletions src/js/node/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ class IncomingMessage extends Readable {
#bodyStream: ReadableStreamDefaultReader | undefined;
#fakeSocket: FakeSocket | undefined = undefined;
#noBody = false;
#aborted = false;
aborted = false;
#req;
url;
#type;
Expand All @@ -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);
Expand All @@ -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();
Expand All @@ -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;
}
Expand Down Expand Up @@ -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 => {
Expand Down

0 comments on commit 6ce6cb8

Please sign in to comment.