Skip to content

Commit

Permalink
Reducing scope of PR
Browse files Browse the repository at this point in the history
  • Loading branch information
MovieStoreGuy committed Sep 16, 2024
1 parent 043afff commit e77f66c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
24 changes: 20 additions & 4 deletions config/confighttp/compression.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ var availableDecoders = map[string]func(body io.ReadCloser) (io.ReadCloser, erro
return nil, nil
},
"gzip": func(body io.ReadCloser) (io.ReadCloser, error) {
return gzip.NewReader(body)
gr, err := gzip.NewReader(body)
if err != nil {
return nil, err
}
return gr, nil
},
"zstd": func(body io.ReadCloser) (io.ReadCloser, error) {
zr, err := zstd.NewReader(
Expand All @@ -49,11 +53,23 @@ var availableDecoders = map[string]func(body io.ReadCloser) (io.ReadCloser, erro
return zr.IOReadCloser(), nil
},
"zlib": func(body io.ReadCloser) (io.ReadCloser, error) {
return zlib.NewReader(body)
zr, err := zlib.NewReader(body)
if err != nil {
return nil, err
}
return zr, nil
},
//nolint:unparam // Require to have error return so it can be part of map
"snappy": func(body io.ReadCloser) (io.ReadCloser, error) {
return io.NopCloser(snappy.NewReader(body)), nil
sr := snappy.NewReader(body)
sb := new(bytes.Buffer)
_, err := io.Copy(sb, sr)
if err != nil {
return nil, err
}
if err = body.Close(); err != nil {
return nil, err
}
return io.NopCloser(sb), nil
},
//nolint:unparam // Require to have error return so it can be part of map
"lz4": func(body io.ReadCloser) (io.ReadCloser, error) {
Expand Down
2 changes: 1 addition & 1 deletion config/confighttp/compression_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ func TestHTTPContentDecompressionHandler(t *testing.T) {
encoding: "snappy",
reqBody: bytes.NewBuffer(testBody),
respCode: http.StatusBadRequest,
respBody: "snappy: corrupt input",
respBody: "snappy: corrupt input\n",
},
{
name: "InvalidLz4",
Expand Down
4 changes: 2 additions & 2 deletions config/confighttp/compressor.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"bytes"
"compress/gzip"
"compress/zlib"
"fmt"
"errors"
"io"
"sync"

Expand Down Expand Up @@ -61,7 +61,7 @@ func newCompressor(compressionType configcompression.Type) (*compressor, error)
case configcompression.TypeLz4:
return lz4Pool, nil
}
return nil, fmt.Errorf("unsupported compression type %q", compressionType)
return nil, errors.New("unsupported compression type, ")
}

func (p *compressor) compress(buf *bytes.Buffer, body io.ReadCloser) error {
Expand Down

0 comments on commit e77f66c

Please sign in to comment.