aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/http_client_async.zig4
-rw-r--r--src/zlib.zig10
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;
},