Skip to content

Commit c7d2c83

Browse files
committed
fix(middleware): keep gzip match to EqualFold only
Drop TrimSpace so the change is strictly RFC 9110 case-insensitivity for content codings, per review discussion.
1 parent 4b7870f commit c7d2c83

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

middleware/decompress.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,10 @@ func (config DecompressConfig) ToMiddleware() (echo.MiddlewareFunc, error) {
129129
}
130130

131131

132-
// isGzipContentEncoding reports whether Content-Encoding is gzip (case-insensitive).
133-
// Surrounding whitespace is ignored so common proxy variations still match.
132+
// isGzipContentEncoding reports whether Content-Encoding is gzip.
133+
// Content codings are case-insensitive per RFC 9110 §8.4.1.
134134
func isGzipContentEncoding(v string) bool {
135-
return strings.EqualFold(strings.TrimSpace(v), GZIPEncoding)
135+
return strings.EqualFold(v, GZIPEncoding)
136136
}
137137

138138
// limitedGzipReader wraps a gzip reader with size limiting to prevent zip bombs

middleware/decompress_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ func TestDecompressContentEncodingCaseInsensitive(t *testing.T) {
513513
gz, err := gzipString(body)
514514
assert.NoError(t, err)
515515

516-
for _, encoding := range []string{"GZIP", "Gzip", " gzip "} {
516+
for _, encoding := range []string{"GZIP", "Gzip"} {
517517
t.Run(encoding, func(t *testing.T) {
518518
req := httptest.NewRequest(http.MethodPost, "/", bytes.NewReader(gz))
519519
req.Header.Set(echo.HeaderContentEncoding, encoding)

0 commit comments

Comments
 (0)