@@ -11,8 +11,8 @@ const regContentType = /^(application\/json\b|text\/(?!event-stream\b))/i
1111const globalResponse = global . Response
1212const responsePrototype : Record < string , any > = {
1313 getResponseCache ( ) {
14- this . __cache = undefined
15- return ( this . responseCache ||= new globalResponse ( this . body , this . init ) )
14+ delete this . __cache
15+ return ( this . responseCache ||= new globalResponse ( this . __body , this . __init ) )
1616 } ,
1717 get body ( ) {
1818 return this . getResponseCache ( ) . body
@@ -67,19 +67,18 @@ const responsePrototype: Record<string, any> = {
6767 } ,
6868}
6969
70- function newResponse ( body : BodyInit | null , init ?: ResponseInit ) : Response {
71- const res = {
72- body,
73- init,
70+ function newResponse ( this : Response , body : BodyInit | null , init ?: ResponseInit ) {
71+ Object . assign ( this , {
7472 status : init ?. status || 200 ,
75- __cache :
76- typeof body === 'string'
77- ? [ body , ( init ?. headers || { } ) as Record < string , string > ]
78- : undefined ,
79- } as unknown as Response
80- Object . setPrototypeOf ( res , responsePrototype )
81- return res
73+ __body : body ,
74+ __init : init ,
75+ __cache : [ body , ( init ?. headers || { } ) as Record < string , string > ] ,
76+ } )
77+ if ( typeof body !== 'string' ) {
78+ delete ( this as any ) . __cache
79+ }
8280}
81+ newResponse . prototype = responsePrototype
8382Object . defineProperty ( global , 'Response' , {
8483 value : newResponse ,
8584} )
0 commit comments