added handling for different compression types
This commit is contained in:
@@ -0,0 +1,26 @@
|
|||||||
|
package reddit
|
||||||
|
|
||||||
|
import (
|
||||||
|
"compress/gzip"
|
||||||
|
"compress/zlib"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/andybalholm/brotli"
|
||||||
|
)
|
||||||
|
|
||||||
|
func ResponseReader(resp *http.Response) (io.ReadCloser, error) {
|
||||||
|
encoding := resp.Header.Get("Content-Encoding")
|
||||||
|
switch strings.ToLower(encoding) {
|
||||||
|
case "deflate":
|
||||||
|
return zlib.NewReader(resp.Body)
|
||||||
|
case "gzip":
|
||||||
|
return gzip.NewReader(resp.Body)
|
||||||
|
case "br":
|
||||||
|
return io.NopCloser(brotli.NewReader(resp.Body)), nil
|
||||||
|
case "zstd":
|
||||||
|
return zlib.NewReader(resp.Body)
|
||||||
|
}
|
||||||
|
return resp.Body, nil
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user