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