File tree Expand file tree Collapse file tree 3 files changed +14
-1
lines changed
Expand file tree Collapse file tree 3 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -79,6 +79,11 @@ export default class Body {
7979
8080 this [ DISTURBED ] = true ;
8181
82+ // body is null
83+ if ( ! this . body ) {
84+ return Body . Promise . resolve ( new Buffer ( 0 ) ) ;
85+ }
86+
8287 // body is string
8388 if ( typeof this . body === 'string' ) {
8489 return Body . Promise . resolve ( convertBody ( [ new Buffer ( this . body ) ] , this . headers ) ) ;
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ import Body, { clone } from './body';
1717 * @return Void
1818 */
1919export default class Response extends Body {
20- constructor ( body , opts = { } ) {
20+ constructor ( body = null , opts = { } ) {
2121 super ( body , opts ) ;
2222
2323 this . url = opts . url ;
Original file line number Diff line number Diff line change @@ -1427,6 +1427,14 @@ describe('node-fetch', () => {
14271427 } ) ;
14281428 } ) ;
14291429
1430+ it ( 'should default to null as body' , function ( ) {
1431+ const res = new Response ( ) ;
1432+ expect ( res . body ) . to . equal ( null ) ;
1433+ return res . text ( ) . then ( result => {
1434+ expect ( result ) . to . equal ( '' ) ;
1435+ } ) ;
1436+ } ) ;
1437+
14301438 it ( 'should default to 200 as status code' , function ( ) {
14311439 const res = new Response ( null ) ;
14321440 expect ( res . status ) . to . equal ( 200 ) ;
You can’t perform that action at this time.
0 commit comments