Fix response decompression
This commit is contained in:
@@ -3,6 +3,11 @@ package utils
|
||||
import (
|
||||
"crypto/rand"
|
||||
"encoding/hex"
|
||||
"io"
|
||||
|
||||
"github.com/andybalholm/brotli"
|
||||
"github.com/klauspost/compress/flate"
|
||||
"github.com/klauspost/compress/gzip"
|
||||
)
|
||||
|
||||
func GenerateActivationCode() string {
|
||||
@@ -12,3 +17,16 @@ func GenerateActivationCode() string {
|
||||
}
|
||||
return hex.EncodeToString(bytes)
|
||||
}
|
||||
|
||||
func DecompressResponseBody(encoding string, body io.Reader) (io.ReadCloser, error) {
|
||||
switch encoding {
|
||||
case "gzip":
|
||||
return gzip.NewReader(body)
|
||||
case "deflate":
|
||||
return flate.NewReader(body), nil
|
||||
case "br":
|
||||
return io.NopCloser(brotli.NewReader(body)), nil
|
||||
default:
|
||||
return io.NopCloser(body), nil
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user