File tree 3 files changed +15
-3
lines changed
3 files changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -46,7 +46,7 @@ class Request {
46
46
this . signal = request . signal ;
47
47
this . headers = new Headers ( options . headers ?? request . headers ) ;
48
48
49
- if ( ! options . body && request . _body . _bodyInit ) {
49
+ if ( options . body === undefined && request . _body . _bodyInit ) {
50
50
this . _body = new Body ( request . _body . _bodyInit ) ;
51
51
request . _body . bodyUsed = true ;
52
52
}
@@ -85,7 +85,14 @@ class Request {
85
85
}
86
86
87
87
clone ( ) {
88
- return new Request ( this , { body : this . _body . _bodyInit } ) ;
88
+ if ( this . bodyUsed ) {
89
+ throw new TypeError ( "Already read" ) ;
90
+ }
91
+
92
+ const newRequest = new Request ( this , { body : null } ) ;
93
+ newRequest . _body = this . _body . clone ( ) ;
94
+
95
+ return newRequest ;
89
96
}
90
97
91
98
blob ( ) {
Original file line number Diff line number Diff line change @@ -21,13 +21,18 @@ class Response {
21
21
}
22
22
23
23
clone ( ) {
24
+ if ( this . bodyUsed ) {
25
+ throw new TypeError ( "Already read" ) ;
26
+ }
27
+
24
28
const newResponse = new Response ( null , {
25
29
status : this . status ,
26
30
statusText : this . statusText ,
27
31
headers : new Headers ( this . headers ) ,
28
32
url : this . url ,
29
33
} ) ;
30
34
newResponse . _body = this . _body . clone ( ) ;
35
+
31
36
return newResponse ;
32
37
}
33
38
Original file line number Diff line number Diff line change @@ -553,7 +553,7 @@ test("request", (t) => {
553
553
t . isNot ( clone . headers , req . headers ) ;
554
554
t . notOk ( req . bodyUsed ) ;
555
555
556
- const bodies = await Promise . all ( [ clone . text ( ) , req . clone ( ) . text ( ) ] ) ;
556
+ const bodies = await Promise . all ( [ clone . text ( ) , req . text ( ) ] ) ;
557
557
558
558
t . eq ( bodies , [ "I work out" , "I work out" ] ) ;
559
559
} ) ;
You can’t perform that action at this time.
0 commit comments