Skip to content

Commit

Permalink
add unit test and changelog
Browse files Browse the repository at this point in the history
Signed-off-by: Ziqi Zhao <[email protected]>
  • Loading branch information
fatsheep9146 committed Jul 14, 2022
1 parent 38f44e4 commit 9f49c65
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
- Unconfigured receivers are not identified, this was not a real problem in final binaries since the validation of the config catch this.
- Allow configurations to contain "unused" receivers. Receivers that are configured but not used in any pipeline, this was possible already for exporters and processors.
- Remove the enforcement/check that Receiver factories create the same instance for the same config.
- Fix confighttp.compression panic due to nil request.Body. (#5628)

## v0.53.0 Beta

Expand Down
34 changes: 34 additions & 0 deletions config/confighttp/compression_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,40 @@ func TestHTTPContentDecompressionHandler(t *testing.T) {
}
}

func TestHTTPContentCompressionNilRequestBody(t *testing.T) {
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(200)
})

addr := testutil.GetAvailableLocalAddress(t)
ln, err := net.Listen("tcp", addr)
require.NoError(t, err, "failed to create listener: %v", err)
srv := &http.Server{
Handler: handler,
}
go func() {
_ = srv.Serve(ln)
}()
// Wait for the servers to start
<-time.After(10 * time.Millisecond)

serverURL := fmt.Sprintf("http://%s", ln.Addr().String())

req, err := http.NewRequest("GET", serverURL, nil)
require.NoError(t, err, "failed to create request to test handler")

client := http.Client{}
client.Transport = newCompressRoundTripper(http.DefaultTransport, configcompression.Gzip)

res, err := client.Do(req)
require.NoError(t, err)

_, err = ioutil.ReadAll(res.Body)
require.NoError(t, err)
require.NoError(t, res.Body.Close(), "failed to close request body: %v", err)
require.NoError(t, srv.Close())
}

func compressGzip(body []byte) (*bytes.Buffer, error) {
var buf bytes.Buffer

Expand Down

0 comments on commit 9f49c65

Please sign in to comment.