Skip to content

Commit f21da44

Browse files
fetch: fix content-encoding order (#3343) (#3764)
(cherry picked from commit e5c242d) Co-authored-by: tsctx <[email protected]>
1 parent e2e3fd2 commit f21da44

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

lib/web/fetch/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2137,7 +2137,7 @@ async function httpNetworkFetch (
21372137

21382138
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Encoding
21392139
if (codings.length !== 0 && request.method !== 'HEAD' && request.method !== 'CONNECT' && !nullBodyStatus.includes(status) && !willFollow) {
2140-
for (let i = 0; i < codings.length; ++i) {
2140+
for (let i = codings.length - 1; i >= 0; --i) {
21412141
const coding = codings[i]
21422142
// https://www.rfc-editor.org/rfc/rfc9112.html#section-7.2
21432143
if (coding === 'x-gzip' || coding === 'gzip') {

test/fetch/encoding.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ test('content-encoding header is case-iNsENsITIve', async (t) => {
1919
res.setHeader('Content-Encoding', contentCodings)
2020
res.setHeader('Content-Type', 'text/plain')
2121

22-
brotli.pipe(gzip).pipe(res)
22+
gzip.pipe(brotli).pipe(res)
2323

24-
brotli.write(text)
25-
brotli.end()
24+
gzip.write(text)
25+
gzip.end()
2626
}).listen(0)
2727

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

48-
gzip.pipe(deflate).pipe(res)
48+
deflate.pipe(gzip).pipe(res)
4949

50-
gzip.write(text)
51-
gzip.end()
50+
deflate.write(text)
51+
deflate.end()
5252
}).listen(0)
5353

5454
t.after(closeServerAsPromise(server))

0 commit comments

Comments
 (0)