Skip to content

Commit 9f93f93

Browse files
authored
x-pack/filebeat/input/http_endpoint: ensure request body is closed when content is gzipped (#37091)
1 parent a473880 commit 9f93f93

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

CHANGELOG.next.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff]
8989
- Fix merging of array fields(processors, paths, parsers) in configurations generated from hints and default config. {issue}36838[36838] {pull}36857[36857]
9090
- Fix handling of response errors in HTTPJSON and CEL request trace logging. {pull}36956[36956]
9191
- Do not error when Okta API returns no data. {pull}37092[37092]
92+
- Fix request body close behaviour in HTTP_Endpoint when handling GZIP compressed content. {pull}37091[37091]
9293

9394
*Heartbeat*
9495

x-pack/filebeat/input/http_endpoint/gzip.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package http_endpoint
66

77
import (
88
"compress/gzip"
9+
"errors"
910
"io"
1011
"sync"
1112
)
@@ -18,29 +19,31 @@ var gzipDecoderPool = sync.Pool{
1819

1920
type pooledGzipReader struct {
2021
Reader *gzip.Reader
22+
closer io.Closer
2123
}
2224

23-
func newPooledGzipReader(r io.Reader) (*pooledGzipReader, error) {
25+
func newPooledGzipReader(r io.ReadCloser) (*pooledGzipReader, error) {
2426
gzipReader := gzipDecoderPool.Get().(*gzip.Reader)
2527
if err := gzipReader.Reset(r); err != nil {
2628
gzipDecoderPool.Put(gzipReader)
2729
return nil, err
2830
}
29-
return &pooledGzipReader{Reader: gzipReader}, nil
31+
return &pooledGzipReader{Reader: gzipReader, closer: r}, nil
3032
}
3133

3234
// Read implements io.Reader, reading uncompressed bytes from its underlying Reader.
3335
func (r *pooledGzipReader) Read(b []byte) (int, error) {
3436
return r.Reader.Read(b)
3537
}
3638

37-
// Close closes the Reader. It does not close the underlying io.Reader.
39+
// Close closes the Reader and the underlying source.
3840
// In order for the GZIP checksum to be verified, the reader must be
3941
// fully consumed until the io.EOF.
4042
//
4143
// After this call the reader should not be reused because it is returned to the pool.
4244
func (r *pooledGzipReader) Close() error {
4345
err := r.Reader.Close()
46+
err = errors.Join(err, r.closer.Close())
4447
gzipDecoderPool.Put(r.Reader)
4548
r.Reader = nil
4649
return err

0 commit comments

Comments
 (0)