File tree Expand file tree Collapse file tree 2 files changed +24
-6
lines changed Expand file tree Collapse file tree 2 files changed +24
-6
lines changed Original file line number Diff line number Diff line change @@ -82,16 +82,18 @@ export function deserializeBodyReader(
8282 return buildBodyReader ( encodedBody , headers , decoder ) ;
8383}
8484
85- function failIfDecodingRequired ( error : string | undefined , buffer : Buffer , headers : Headers ) {
85+ function failIfDecodingRequired ( errorMessage : string | undefined , buffer : Buffer , headers : Headers ) {
8686 if ( ! headers [ 'content-encoding' ] || headers [ 'content-encoding' ] === 'identity' ) {
8787 return buffer ;
8888 }
8989
90- if ( error ) {
91- throw new Error ( `Decoding error: ${ error } ` ) ;
92- } else {
93- throw new Error ( "Can't read encoded message body as client-side decoding has been disabled" ) ;
94- }
90+ const error = errorMessage
91+ ? new Error ( `Decoding error (${ headers [ 'content-encoding' ] } ): ${ errorMessage } ` )
92+ : new Error ( "Can't read encoded message body without server-side decoding" ) ;
93+
94+ console . warn ( error . message ) ;
95+
96+ throw error ;
9597}
9698
9799/**
Original file line number Diff line number Diff line change @@ -478,6 +478,22 @@ nodeOnly(() => {
478478 expect ( bodyText ) . to . equal ( 'Hello world' ) ;
479479 } ) ;
480480
481+ it ( "should not be able to read non-decodeable bodies" , async ( ) => {
482+ const responseDeferred = getDeferred < CompletedResponse > ( ) ;
483+ await remoteServer . on ( 'response' , ( res ) => responseDeferred . resolve ( res ) ) ;
484+
485+ await remoteServer . forAnyRequest ( ) . thenReply ( 200 , 'INVALID DATA' , {
486+ 'Content-Encoding' : 'gzip'
487+ } ) ;
488+
489+ await fetch ( remoteServer . url ) ;
490+
491+ const response = await responseDeferred ;
492+ expect ( response . statusCode ) . to . equal ( 200 ) ;
493+ const bodyText = await response . body . getText ( ) ;
494+ expect ( bodyText ) . to . equal ( undefined ) ;
495+ } ) ;
496+
481497 it ( "should allow resetting the mock server configured responses" , async ( ) => {
482498 await remoteServer . forGet ( "/mocked-endpoint" ) . thenReply ( 200 , "mocked data" ) ;
483499
You can’t perform that action at this time.
0 commit comments