fetch icon indicating copy to clipboard operation
fetch copied to clipboard

fix: clone methods correctly handle teeing body stream

Open slightlytyler opened this issue 1 year ago • 2 comments

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:

  1. Response/Request clone method creates a new instance with a null body
  2. Source body is cloned
  3. Body clone method tees stream, sets its stream to one output, and returns a body with second output
  4. Response/Request clone sets body on cloned instance
  5. 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

slightlytyler avatar Jun 05 '23 23:06 slightlytyler