File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -275,6 +275,13 @@ export default function fetch(url, opts) {
275275 response = new Response ( body , response_options ) ;
276276 resolve ( response ) ;
277277 } ) ;
278+ raw . on ( 'end' , ( ) => {
279+ // some old IIS servers return zero-length OK deflate responses, so 'data' is never emitted.
280+ if ( ! response ) {
281+ response = new Response ( body , response_options ) ;
282+ resolve ( response ) ;
283+ }
284+ } )
278285 return ;
279286 }
280287
Original file line number Diff line number Diff line change @@ -120,6 +120,13 @@ export default class TestServer {
120120 } ) ;
121121 }
122122
123+ if ( p === '/empty/deflate' ) {
124+ res . statusCode = 200 ;
125+ res . setHeader ( 'Content-Type' , 'text/plain' ) ;
126+ res . setHeader ( 'Content-Encoding' , 'deflate' ) ;
127+ res . end ( ) ;
128+ }
129+
123130 if ( p === '/sdch' ) {
124131 res . statusCode = 200 ;
125132 res . setHeader ( 'Content-Type' , 'text/plain' ) ;
Original file line number Diff line number Diff line change @@ -679,6 +679,17 @@ describe('node-fetch', () => {
679679 } ) ;
680680 } ) ;
681681
682+ it ( 'should handle empty deflate response' , function ( ) {
683+ const url = `${ base } empty/deflate` ;
684+ return fetch ( url ) . then ( res => {
685+ expect ( res . headers . get ( 'content-type' ) ) . to . equal ( 'text/plain' ) ;
686+ return res . text ( ) . then ( result => {
687+ expect ( result ) . to . be . a ( 'string' ) ;
688+ expect ( result ) . to . be . empty ;
689+ } ) ;
690+ } ) ;
691+ } ) ;
692+
682693 it ( 'should decompress brotli response' , function ( ) {
683694 if ( typeof zlib . createBrotliDecompress !== 'function' ) this . skip ( ) ;
684695 const url = `${ base } brotli` ;
You can’t perform that action at this time.
0 commit comments