-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: clone methods correctly handle teeing body stream #17
base: master
Are you sure you want to change the base?
fix: clone methods correctly handle teeing body stream #17
Conversation
Was hoping the tests would work in CI since I can't get them to run locally but looks like they're running into similar environment problems |
ad40a47
to
436406d
Compare
@@ -5,7 +5,8 @@ | |||
"requires": true, | |||
"packages": { | |||
"": { | |||
"version": "1.0.2", | |||
"name": "react-native-fetch-api", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
idk why this is changing when i npm install
@@ -228,6 +233,16 @@ class Body { | |||
}, | |||
}); | |||
} | |||
|
|||
clone() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -85,7 +85,14 @@ class Request { | |||
} | |||
|
|||
clone() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -21,12 +21,19 @@ class Response { | |||
} | |||
|
|||
clone() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -85,7 +85,14 @@ class Request { | |||
} | |||
|
|||
clone() { | |||
return new Request(this, { body: this._body._bodyInit }); | |||
if (this.bodyUsed) { | |||
throw new TypeError("Already read"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -21,12 +21,19 @@ class Response { | |||
} | |||
|
|||
clone() { | |||
return new Response(this._body._bodyInit, { | |||
if (this.bodyUsed) { | |||
throw new TypeError("Already read"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -46,7 +46,7 @@ class Request { | |||
this.signal = request.signal; | |||
this.headers = new Headers(options.headers ?? request.headers); | |||
|
|||
if (!options.body && request._body._bodyInit) { | |||
if (options.body === undefined && request._body._bodyInit) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to avoid explicit null body triggering this case I think
8a06df0
to
0d9cad2
Compare
@acostalima are you still maintaining? Code here is good to go but the test infra is broken locally and in CI. I got it working locally by editing the generated rn test app but unsure of what the real fix is. seems like a problem with react-native-test-runner rather than config in this project though? happy to do whatever needed to get this merged in 👍 |
Encountered error
This stream has already been locked for exclusive reading by another reader
when cloning a response that gets read as a stream. Problem was we did not handle teeing the body stream when cloning happens. The fix is:Also added a few updates to correct the behavior of this library wrt the spec. Namely body class handles explicitly null bodyInit and request/response clone methods check if the body has been used before executing.
Test cases added / modified to verify the new cloning behavior