-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Keep clientAddress on cloned requests (#12613)
* Keep clientAddress on cloned requests User observed that calling actions resulted in an error about not having clientRequest available. This is because the user had a middleware that cloned the request, which loses all of the symbols. The fix is to pass the clientAddress directly into the RenderContext. This deprecates the `clientAddressSymbol`, but we need to keep it for now because some adapters set the clientAddress that way. Note that similar fixes should be done for other symbol usage on the Request object (locals is one). * changeset * fix build stuff * Update packages/astro/src/core/render-context.ts * Update changeset
- Loading branch information
Showing
8 changed files
with
55 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
'astro': patch | ||
--- | ||
|
||
Fix use of cloned requests in middleware with clientAddress | ||
|
||
When using `context.clientAddress` or `Astro.clientAddress` Astro looks up the address in a hidden property. Cloning a request can cause this hidden property to be lost. | ||
|
||
The fix is to pass the address as an internal property instead, decoupling it from the request. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
packages/astro/test/fixtures/client-address/src/middleware.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { defineMiddleware } from 'astro:middleware'; | ||
|
||
export const onRequest = defineMiddleware(async (ctx, next) => { | ||
// Clone a request, losing all symbols | ||
const clonedRequest = ctx.request.clone(); | ||
const safeInternalRequest = new Request(clonedRequest, { | ||
method: clonedRequest.method, | ||
headers: clonedRequest.headers, | ||
}); | ||
|
||
return next(safeInternalRequest); | ||
}); |