File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,15 +11,18 @@ import (
1111 "github.com/mholt/archives"
1212)
1313
14- const ContentTypeGzip = "application/gzip"
14+ var ContentTypesGzip = []string {
15+ "application/gzip" ,
16+ "application/x-gzip" ,
17+ }
1518
1619func WithGzip (out io.Writer ) requests.ResponseHandler {
1720 return func (response * http.Response ) error {
1821 log := logr .FromContextOrDiscard (response .Request .Context ())
1922 var stream io.ReadCloser
2023
2124 // if it's a gzip response, decompress it
22- if mimetype . EqualsAny (response .Header .Get ("Content-Type" ), ContentTypeGzip ) {
25+ if isGzipped (response .Header .Get ("Content-Type" )) {
2326 log .V (8 ).Info ("decompressing gzip response" )
2427 dec , err := archives.Gz {}.OpenReader (response .Body )
2528 if err != nil {
@@ -37,3 +40,7 @@ func WithGzip(out io.Writer) requests.ResponseHandler {
3740 return nil
3841 }
3942}
43+
44+ func isGzipped (s string ) bool {
45+ return mimetype .EqualsAny (s , ContentTypesGzip ... )
46+ }
Original file line number Diff line number Diff line change 1+ package requestutil
2+
3+ import (
4+ "testing"
5+
6+ "github.com/stretchr/testify/assert"
7+ )
8+
9+ func TestIsGzipped (t * testing.T ) {
10+ var cases = []struct {
11+ s string
12+ ok bool
13+ }{
14+ {
15+ "application/gzip" ,
16+ true ,
17+ },
18+ {
19+ "application/x-gzip" ,
20+ true ,
21+ },
22+ {
23+ "application/javascript" ,
24+ false ,
25+ },
26+ }
27+
28+ for _ , tt := range cases {
29+ t .Run (tt .s , func (t * testing.T ) {
30+ ok := isGzipped (tt .s )
31+ assert .EqualValues (t , tt .ok , ok )
32+ })
33+ }
34+ }
You can’t perform that action at this time.
0 commit comments