Skip to content

Commit

Permalink
Replace request.clone() with new Request(...) (#167)
Browse files Browse the repository at this point in the history
* Replace `request.clone()` with `new Request(...)`

I received this warning while running in Cloudflare Workers:

```
Your worker called response.clone(), but did not read the body of both clones. This is wasteful, as it forces the system to buffer the entire response body in memory, rather than streaming it through. This may cause your worker to be unexpectedly terminated for going over the memory limit. If you only meant to copy the response headers and metadata (e.g. in order to be able to modify them), use `new Response(response.body, response)` instead
```

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

* Update src/authenticator.ts

Co-authored-by: Sergio Xalambrí <[email protected]>

Co-authored-by: Sergio Xalambrí <[email protected]>
  • Loading branch information
jfsiii and sergiodxa authored May 17, 2022
1 parent 222058c commit 50a58e0
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/authenticator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export class Authenticator<User = unknown> {
): Promise<User> {
const strategyObj = this.strategies.get(strategy);
if (!strategyObj) throw new Error(`Strategy ${strategy} not found.`);
return strategyObj.authenticate(request.clone(), this.sessionStorage, {
return strategyObj.authenticate(new Request(request.url, request), this.sessionStorage, {
throwOnError: this.throwOnError,
...options,
sessionKey: this.sessionKey,
Expand Down

0 comments on commit 50a58e0

Please sign in to comment.