Unverified Commit 91471878 authored by Dima Voytenko's avatar Dima Voytenko Committed by GitHub

Testmode: provide test info for rewrite requests (#59033)

The rewrite request appear to bypass the `BaseServer` or are executed in
the sandbox. However, these requests have the correct test info in the
headers that can be used instead of the `AsyncLocalStorage`.
parent d0c5673d
......@@ -84,11 +84,26 @@ function buildResponse(proxyResponse: ProxyFetchResponse): Response {
})
}
function extractTestInfoFromRequest(req: Request): TestReqInfo | undefined {
const proxyPortHeader = req.headers.get('next-test-proxy-port')
if (!proxyPortHeader) {
return undefined
}
const url = req.url
const proxyPort = Number(proxyPortHeader)
const testData = req.headers.get('next-test-data') ?? ''
return {
url,
proxyPort,
testData,
}
}
async function handleFetch(
originalFetch: Fetch,
request: Request
): Promise<Response> {
const testInfo = testStorage.getStore()
const testInfo = testStorage.getStore() ?? extractTestInfoFromRequest(request)
if (!testInfo) {
throw new Error('No test info')
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment