Skip to content

Commit

Permalink
fetch: fix content-encoding order (#3343)
Browse files Browse the repository at this point in the history
  • Loading branch information
tsctx authored Jun 19, 2024
1 parent 532b7b2 commit e5c242d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/web/fetch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2137,7 +2137,7 @@ async function httpNetworkFetch (

// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Encoding
if (codings.length !== 0 && request.method !== 'HEAD' && request.method !== 'CONNECT' && !nullBodyStatus.includes(status) && !willFollow) {
for (let i = 0; i < codings.length; ++i) {
for (let i = codings.length - 1; i >= 0; --i) {
const coding = codings[i]
// https://www.rfc-editor.org/rfc/rfc9112.html#section-7.2
if (coding === 'x-gzip' || coding === 'gzip') {
Expand Down
12 changes: 6 additions & 6 deletions test/fetch/encoding.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ test('content-encoding header is case-iNsENsITIve', async (t) => {
res.setHeader('Content-Encoding', contentCodings)
res.setHeader('Content-Type', 'text/plain')

brotli.pipe(gzip).pipe(res)
gzip.pipe(brotli).pipe(res)

brotli.write(text)
brotli.end()
gzip.write(text)
gzip.end()
}).listen(0)

t.after(closeServerAsPromise(server))
Expand All @@ -45,10 +45,10 @@ test('response decompression according to content-encoding should be handled in
res.setHeader('Content-Encoding', contentCodings)
res.setHeader('Content-Type', 'text/plain')

gzip.pipe(deflate).pipe(res)
deflate.pipe(gzip).pipe(res)

gzip.write(text)
gzip.end()
deflate.write(text)
deflate.end()
}).listen(0)

t.after(closeServerAsPromise(server))
Expand Down

0 comments on commit e5c242d

Please sign in to comment.