fetch
fetch copied to clipboard
fix: clone methods correctly handle teeing body stream
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:
- Response/Request clone method creates a new instance with a null body
- Source body is cloned
- Body clone method tees stream, sets its stream to one output, and returns a body with second output
- Response/Request clone sets body on cloned instance
- Response/Request clone returns new instance
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