Commit 9a6d748 authored and committed Apr 1, 2023
1 parent a43b628 commit 9a6d748 Copy full SHA for 9a6d748
File tree 3 files changed +19
-1
lines changed
3 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -437,7 +437,11 @@ function parseHeaders(rawHeaders) {
437
437
var key = parts . shift ( ) . trim ( )
438
438
if ( key ) {
439
439
var value = parts . join ( ':' ) . trim ( )
440
- headers . append ( key , value )
440
+ try {
441
+ headers . append ( key , value )
442
+ } catch ( error ) {
443
+ console . warn ( 'Response ' + error . message )
444
+ }
441
445
}
442
446
} )
443
447
return headers
Original file line number Diff line number Diff line change @@ -120,6 +120,14 @@ const routes = {
120
120
'Content-Type' : 'text/html; charset=utf-8'
121
121
} )
122
122
res . end ( )
123
+ } ,
124
+ '/invalid-headers' : function ( res ) {
125
+ res . writeHead ( 200 , {
126
+ 'Content-Type' : 'text/plain' ,
127
+ 'Invalid Header' : 'valid value' ,
128
+ 'Westworld-S01' : "<3"
129
+ } )
130
+ res . end ( )
123
131
}
124
132
}
125
133
Original file line number Diff line number Diff line change @@ -1281,6 +1281,12 @@ exercise.forEach(function(exerciseMode) {
1281
1281
assert . equal ( response . headers . get ( 'Content-Type' ) , 'text/html; charset=utf-8' )
1282
1282
} )
1283
1283
} )
1284
+ test ( 'parses invalid headers' , function ( ) {
1285
+ return fetch ( '/invalid-headers' ) . then ( function ( response ) {
1286
+ assert . equal ( response . headers . get ( 'Content-Type' ) , 'text/plain' )
1287
+ assert . equal ( response . headers . get ( 'Westworld-S01' ) , '<3' )
1288
+ } )
1289
+ } )
1284
1290
} )
1285
1291
1286
1292
// https://fetch.spec.whatwg.org/#methods
You can’t perform that action at this time.
0 commit comments