diff options
author | 2023-09-04 21:37:47 -0300 | |
---|---|---|
committer | 2023-09-04 17:37:47 -0700 | |
commit | f1afd5833874e64822560a834c3484b2aa993656 (patch) | |
tree | b62431b12410dfae2120332c9eb727bafbe79bd2 /src | |
parent | 5f34c44ec6af175889e26aa5f42c817dd3de61c4 (diff) | |
download | bun-f1afd5833874e64822560a834c3484b2aa993656.tar.gz bun-f1afd5833874e64822560a834c3484b2aa993656.tar.zst bun-f1afd5833874e64822560a834c3484b2aa993656.zip |
fix zlib deflate on fetch (#4483)
* fix zlib deflate on fetch
* mention issue on test
* more tests
* oops
Diffstat (limited to 'src')
-rw-r--r-- | src/http_client_async.zig | 4 | ||||
-rw-r--r-- | src/zlib.zig | 10 |
2 files changed, 8 insertions, 6 deletions
diff --git a/src/http_client_async.zig b/src/http_client_async.zig index 8a0e6548c..160a35716 100644 --- a/src/http_client_async.zig +++ b/src/http_client_async.zig @@ -1155,9 +1155,9 @@ pub const InternalState = struct { // TODO: add br support today we support gzip and deflate only // zlib.MAX_WBITS = 15 // to (de-)compress deflate format, use wbits = -zlib.MAX_WBITS - // to (de-)compress zlib format, use wbits = zlib.MAX_WBITS + // to (de-)compress deflate format with headers we use wbits = 0 (we can detect the first byte using 120) // to (de-)compress gzip format, use wbits = zlib.MAX_WBITS | 16 - .windowBits = if (this.encoding == Encoding.gzip) Zlib.MAX_WBITS | 16 else -Zlib.MAX_WBITS, + .windowBits = if (this.encoding == Encoding.gzip) Zlib.MAX_WBITS | 16 else (if (buffer.len > 1 and buffer[0] == 120) 0 else -Zlib.MAX_WBITS), }, ); this.zlib_reader = reader; diff --git a/src/zlib.zig b/src/zlib.zig index 6b2e9dc48..090d0f3a0 100644 --- a/src/zlib.zig +++ b/src/zlib.zig @@ -439,7 +439,8 @@ pub const ZlibReaderArrayList = struct { } pub fn end(this: *ZlibReader) void { - if (this.state == State.Inflating) { + // always free with `inflateEnd` + if (this.state != State.End) { _ = inflateEnd(&this.zlib); this.state = State.End; } @@ -846,7 +847,7 @@ pub const ZlibCompressorArrayList = struct { } pub fn end(this: *ZlibCompressor) void { - if (this.state == State.Inflating) { + if (this.state != State.End) { _ = deflateEnd(&this.zlib); this.state = State.End; } @@ -981,13 +982,13 @@ pub const ZlibCompressorArrayList = struct { switch (rc) { ReturnCode.StreamEnd => { - this.state = State.End; this.list.items.len = this.zlib.total_out; - this.end(); + return; }, ReturnCode.MemError => { + this.end(); this.state = State.Error; return error.OutOfMemory; }, @@ -998,6 +999,7 @@ pub const ZlibCompressorArrayList = struct { ReturnCode.VersionError, ReturnCode.ErrNo, => { + this.end(); this.state = State.Error; return error.ZlibError; }, |