File tree 2 files changed +39
-3
lines changed
2 files changed +39
-3
lines changed Original file line number Diff line number Diff line change @@ -1984,7 +1984,9 @@ async function httpNetworkFetch (
1984
1984
const val = headersList [ n + 1 ] . toString ( 'latin1' )
1985
1985
1986
1986
if ( key . toLowerCase ( ) === 'content-encoding' ) {
1987
- codings = val . split ( ',' ) . map ( ( x ) => x . trim ( ) )
1987
+ // https://www.rfc-editor.org/rfc/rfc7231#section-3.1.2.1
1988
+ // "All content-coding values are case-insensitive..."
1989
+ codings = val . toLowerCase ( ) . split ( ',' ) . map ( ( x ) => x . trim ( ) )
1988
1990
} else if ( key . toLowerCase ( ) === 'location' ) {
1989
1991
location = val
1990
1992
}
@@ -2003,9 +2005,10 @@ async function httpNetworkFetch (
2003
2005
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Encoding
2004
2006
if ( request . method !== 'HEAD' && request . method !== 'CONNECT' && ! nullBodyStatus . includes ( status ) && ! willFollow ) {
2005
2007
for ( const coding of codings ) {
2006
- if ( / ( x - ) ? g z i p / . test ( coding ) ) {
2008
+ // https://www.rfc-editor.org/rfc/rfc9112.html#section-7.2
2009
+ if ( coding === 'x-gzip' || coding === 'gzip' ) {
2007
2010
decoders . push ( zlib . createGunzip ( ) )
2008
- } else if ( / ( x - ) ? d e f l a t e / . test ( coding ) ) {
2011
+ } else if ( coding === 'deflate' ) {
2009
2012
decoders . push ( zlib . createInflate ( ) )
2010
2013
} else if ( coding === 'br' ) {
2011
2014
decoders . push ( zlib . createBrotliDecompress ( ) )
Original file line number Diff line number Diff line change
1
+ 'use strict'
2
+
3
+ const { test } = require ( 'tap' )
4
+ const { createServer } = require ( 'http' )
5
+ const { once } = require ( 'events' )
6
+ const { fetch } = require ( '../..' )
7
+ const { createBrotliCompress, createGzip } = require ( 'zlib' )
8
+
9
+ test ( 'content-encoding header is case-iNsENsITIve' , async ( t ) => {
10
+ const contentCodings = 'GZiP, bR'
11
+ const text = 'Hello, World!'
12
+
13
+ const server = createServer ( ( req , res ) => {
14
+ const gzip = createGzip ( )
15
+ const brotli = createBrotliCompress ( )
16
+
17
+ res . setHeader ( 'Content-Encoding' , contentCodings )
18
+ res . setHeader ( 'Content-Type' , 'text/plain' )
19
+
20
+ brotli . pipe ( gzip ) . pipe ( res )
21
+
22
+ brotli . write ( text )
23
+ brotli . end ( )
24
+ } ) . listen ( 0 )
25
+
26
+ t . teardown ( server . close . bind ( server ) )
27
+ await once ( server , 'listening' )
28
+
29
+ const response = await fetch ( `http://localhost:${ server . address ( ) . port } ` )
30
+
31
+ t . equal ( await response . text ( ) , text )
32
+ t . equal ( response . headers . get ( 'content-encoding' ) , contentCodings )
33
+ } )
You can’t perform that action at this time.
0 commit comments