fix the node-fetch cloned response hanging bug as best I can #580
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
While this is technically a breaking change - responses returned by inspected calls won't always be readable in the way they were before - I feel it's necessary to roll back the hanging bug for users of v9. Prioritising the users of this new feature (only released about a month ago) over established users who may come across this troubling bug #575 feels like poor prioritisation.
The solution I've gone with is to clone responses on demand in the inspection stage. If this fails (because the response has already been read), it falls back to overwriting the
json
,text
etc methods of the original response with functions that return the promises generated by those original function calls, which are captured by the proxy wrapped around the original response.A better solution making more use of the proxy feels possible, along the lines of lazily cloning only at the point that the original body is used. That feels more robust, but also hard work to implement properly, so want to get this fix out first.