Fix response decompression

This commit is contained in:
MaxJa4
2025-02-09 16:46:02 +01:00
parent 770a033429
commit e8dbf9611e
2 changed files with 30 additions and 3 deletions

View File

@@ -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
}
}