File tree Expand file tree Collapse file tree 2 files changed +20
-1
lines changed
Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -462,6 +462,9 @@ export function Response(bodyInit, options) {
462462
463463 this . type = 'default'
464464 this . status = options . status === undefined ? 200 : options . status
465+ if ( this . status < 200 || this . status > 599 ) {
466+ throw new RangeError ( "Failed to construct 'Response': The status provided (0) is outside the range [200, 599]." )
467+ }
465468 this . ok = this . status >= 200 && this . status < 300
466469 this . statusText = options . statusText === undefined ? '' : '' + options . statusText
467470 this . headers = new Headers ( options . headers )
@@ -481,7 +484,8 @@ Response.prototype.clone = function() {
481484}
482485
483486Response . error = function ( ) {
484- var response = new Response ( null , { status : 0 , statusText : '' } )
487+ var response = new Response ( null , { status : 200 , statusText : '' } )
488+ response . status = 0
485489 response . type = 'error'
486490 return response
487491}
Original file line number Diff line number Diff line change @@ -623,6 +623,21 @@ exercise.forEach(function(exerciseMode) {
623623 Response ( '{"foo":"bar"}' , { headers : { 'content-type' : 'application/json' } } )
624624 } )
625625 } )
626+ test ( 'status outside inclusive range 200-599 ' , function ( ) {
627+ assert . throws ( function ( ) {
628+ new Response ( '' , { status : 199 } )
629+ } )
630+ for ( var i = 0 ; i < 200 ; i ++ ) {
631+ assert . throws ( function ( ) {
632+ new Response ( '' , { status : i } )
633+ } )
634+ }
635+ for ( i = 999 ; i > 599 ; i -- ) {
636+ assert . throws ( function ( ) {
637+ new Response ( '' , { status : i } )
638+ } )
639+ }
640+ } )
626641 test ( 'creates Headers object from raw headers' , function ( ) {
627642 var r = new Response ( '{"foo":"bar"}' , { headers : { 'content-type' : 'application/json' } } )
628643 assert . equal ( r . headers instanceof Headers , true )
You can’t perform that action at this time.
0 commit comments