Closed jfsiii closed 2 years ago
This is needed because Remix Auth reads the body, and if you want to read it yourself later it will fail without request.clone()
Thanks for the explanation. This makes sense a day later. I think I interpreted this an alternative/preferred way to make a copy, but it could have just been that my app never read the .clone()
body.
Closing the PR
Although, looking at https://developers.cloudflare.com/workers/examples/alter-headers
async function handleRequest(request) {
const response = await fetch(request);
// Clone the response so that it's no longer immutable
const newResponse = new Response(response.body, response);
// Add a custom header with a value
newResponse.headers.append('x-workers-hello', 'Hello from Cloudflare Workers');
// Delete headers
newResponse.headers.delete('x-header-to-delete');
newResponse.headers.delete('x-header2-to-delete');
// Adjust the value for an existing header
newResponse.headers.set('x-header-to-change', 'NewValue');
return newResponse;
}
doesn't it look like these are interchangeable?
// Clone the response so that it's no longer immutable
- const newResponse = new Response(response.body, response);
+ const newResponse = response.clone()
Aren't these both ways duplicating a request? If so, it seems like Cloudflare has a clear preference for one.
Can you say more about the distinction you see between the two and why .clone
is the preference in remix-auth
?
This change does break other environments. I'm trying to unit test an action that runs this code and new Request
seems to mess up the body whereas request.clone()
works fine.
I received this warning while running in Cloudflare Workers:
This is the only
.clone()
I could find in my worker, and updating this removed the warning. My app still appears to be working correctly