Commit 092df0f1 authored by Janka Uryga's avatar Janka Uryga

support experimental.validateRSCRequestHeaders for runtime prefetches

parent 63e373bf
......@@ -2,15 +2,37 @@ import { LinkAccordion } from '../components/link-accordion'
export default function Page() {
return (
<ul>
<li>
<LinkAccordion href="/target-page">Target page</LinkAccordion>
</li>
<li>
<LinkAccordion href="/redirect-to-target-page">
Redirects to target page
</LinkAccordion>
</li>
</ul>
<div>
<h2>auto prefetches</h2>
<ul id="prefetch-auto">
<li>
<LinkAccordion href="/target-page">Target page</LinkAccordion>
</li>
<li>
<LinkAccordion href="/redirect-to-target-page">
Redirects to target page
</LinkAccordion>
</li>
</ul>
{process.env.__NEXT_CACHE_COMPONENTS && (
// runtime prefetches are only available if cacheComponents is enabled.
<>
<h2>runtime prefetches</h2>
<ul id="prefetch-runtime">
<li>
<LinkAccordion href="/target-page" prefetch={true}>
Target page
</LinkAccordion>
</li>
<li>
<LinkAccordion href="/redirect-to-target-page" prefetch={true}>
Redirects to target page
</LinkAccordion>
</li>
</ul>
</>
)}
</div>
)
}
......@@ -135,11 +135,15 @@ async function createFakeCDN(destPort) {
}
resolveCDNEntry(entry)
})
return
} else {
// If the response isn't cacheable, pipe it through to the client.
res.writeHead(
proxyRes.statusCode || 200,
proxyRes.statusMessage,
proxyRes.headers
)
proxyRes.pipe(res)
}
// If the response isn't cacheable, pipe it through to the client.
proxyRes.pipe(res)
return
})
return cdnServer
......
......@@ -159,7 +159,7 @@ export function createRouterAct(
// `act` controls the timing of when responses reach the client,
// but it should not affect the timing of when requests reach the
// server; we pass the request to the server the immediately.
result: new Promise(async (resolve) => {
result: (async () => {
const originalResponse = await page.request.fetch(request, {
maxRedirects: 0,
})
......@@ -172,13 +172,13 @@ export function createRouterAct(
const headers = originalResponse.headers()
delete headers['transfer-encoding']
resolve({
return {
text: await originalResponse.text(),
body: await originalResponse.body(),
headers,
status: originalResponse.status(),
})
}),
}
})(),
didProcess: false,
})
if (onDidIssueFirstRequest !== null) {
......@@ -417,14 +417,14 @@ ${fulfilled.body}
batch.pendingRequests.add({
url: req.url(),
route: null,
result: new Promise(async (resolve) => {
resolve({
result: (async () => {
return {
text: await res.text(),
body: await res.body(),
headers: res.headers(),
status: res.status(),
})
}),
}
})(),
didProcess: false,
})
page.off('response', handleResponse)
......
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