File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -117,6 +117,20 @@ export default class TestServer {
117
117
res . end ( 'fake gzip string' ) ;
118
118
}
119
119
120
+ if ( p === '/invalid-header' ) {
121
+ res . setHeader ( 'Content-Type' , 'text/plain' ) ;
122
+ res . writeHead ( 200 ) ;
123
+ // HACK: add a few invalid headers to the generated header string before
124
+ // it is actually sent to the socket.
125
+ res . _header = res . _header . replace ( / \r \n $ / , [
126
+ 'Invalid-Header : abc\r\n' ,
127
+ 'Invalid-Header-Value: \x07k\r\n' ,
128
+ 'Set-Cookie: \x07k\r\n' ,
129
+ 'Set-Cookie: \x07kk\r\n' ,
130
+ ] . join ( '' ) + '\r\n' ) ;
131
+ res . end ( 'hello world\n' ) ;
132
+ }
133
+
120
134
if ( p === '/timeout' ) {
121
135
setTimeout ( function ( ) {
122
136
res . statusCode = 200 ;
Original file line number Diff line number Diff line change @@ -477,6 +477,20 @@ describe('node-fetch', () => {
477
477
} ) ;
478
478
} ) ;
479
479
480
+ it ( 'should ignore invalid headers' , function ( ) {
481
+ const url = `${ base } invalid-header` ;
482
+ return fetch ( url ) . then ( res => {
483
+ expect ( res . headers . get ( 'Invalid-Header' ) ) . to . be . null ;
484
+ expect ( res . headers . get ( 'Invalid-Header-Value' ) ) . to . be . null ;
485
+ expect ( res . headers . get ( 'Set-Cookie' ) ) . to . be . null ;
486
+ expect ( Array . from ( res . headers . keys ( ) ) . length ) . to . equal ( 4 ) ;
487
+ expect ( res . headers . has ( 'Connection' ) ) . to . be . true ;
488
+ expect ( res . headers . has ( 'Content-Type' ) ) . to . be . true ;
489
+ expect ( res . headers . has ( 'Date' ) ) . to . be . true ;
490
+ expect ( res . headers . has ( 'Transfer-Encoding' ) ) . to . be . true ;
491
+ } ) ;
492
+ } ) ;
493
+
480
494
it ( 'should handle client-error response' , function ( ) {
481
495
const url = `${ base } error/400` ;
482
496
return fetch ( url ) . then ( res => {
You can’t perform that action at this time.
0 commit comments