From 6d95188e89c4bb0df08dfbead4df29d672c7461b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Do=C4=9Fan=20Can=20Bak=C4=B1r?= Date: Wed, 17 Jul 2024 15:17:35 +0300 Subject: [PATCH 1/2] add zstd encoding support --- http/normalization.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/http/normalization.go b/http/normalization.go index 89cceac..55d6bed 100644 --- a/http/normalization.go +++ b/http/normalization.go @@ -10,6 +10,7 @@ import ( "strings" "github.com/andybalholm/brotli" + "github.com/klauspost/compress/zstd" "github.com/pkg/errors" "golang.org/x/text/encoding/simplifiedchinese" "golang.org/x/text/transform" @@ -73,6 +74,13 @@ func wrapDecodeReader(resp *http.Response) (rc io.ReadCloser, err error) { rc, err = zlib.NewReader(resp.Body) case "br": rc = io.NopCloser(brotli.NewReader(resp.Body)) + case "zstd": + var zstdReader *zstd.Decoder + zstdReader, err = zstd.NewReader(resp.Body) + if err != nil { + return nil, err + } + rc = io.NopCloser(zstdReader) default: rc = resp.Body } From e36d036848894cc79d3ca818c84f48dd43c020cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Do=C4=9Fan=20Can=20Bak=C4=B1r?= Date: Wed, 17 Jul 2024 16:54:51 +0300 Subject: [PATCH 2/2] use klauspost/compress --- http/normalization.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/http/normalization.go b/http/normalization.go index 55d6bed..9c44eb9 100644 --- a/http/normalization.go +++ b/http/normalization.go @@ -2,14 +2,14 @@ package httputil import ( "bytes" - "compress/gzip" - "compress/zlib" "fmt" "io" "net/http" "strings" - "github.com/andybalholm/brotli" + "github.com/dsnet/compress/brotli" + "github.com/klauspost/compress/gzip" + "github.com/klauspost/compress/zlib" "github.com/klauspost/compress/zstd" "github.com/pkg/errors" "golang.org/x/text/encoding/simplifiedchinese" @@ -73,7 +73,7 @@ func wrapDecodeReader(resp *http.Response) (rc io.ReadCloser, err error) { case "deflate": rc, err = zlib.NewReader(resp.Body) case "br": - rc = io.NopCloser(brotli.NewReader(resp.Body)) + rc, err = brotli.NewReader(resp.Body, nil) case "zstd": var zstdReader *zstd.Decoder zstdReader, err = zstd.NewReader(resp.Body)