Unverified Commit 2bc8e740 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Update res.revalidate to pass through headers (#44981)

parent 09830502
......@@ -353,6 +353,15 @@ function setPreviewData<T>(
return res
}
const filteredRevalidateHeaders = new Set([
'content-type',
'content-encoding',
'accept',
'accept-language',
'accept-encoding',
'connection',
])
async function revalidate(
urlPath: string,
opts: {
......@@ -366,7 +375,7 @@ async function revalidate(
`Invalid urlPath provided to revalidate(), must be a path e.g. /blog/post-1, received ${urlPath}`
)
}
const revalidateHeaders = {
const revalidateHeaders: HeadersInit = {
[PRERENDER_REVALIDATE_HEADER]: context.previewModeId,
...(opts.unstable_onlyGenerated
? {
......@@ -375,14 +384,17 @@ async function revalidate(
: {}),
}
for (const key of Object.keys(req.headers)) {
if (!filteredRevalidateHeaders.has(key) && !key.startsWith('x-vercel')) {
revalidateHeaders[key] = req.headers[key] as string
}
}
try {
if (context.trustHostHeader) {
const res = await fetch(`https://${req.headers.host}${urlPath}`, {
method: 'HEAD',
headers: {
...revalidateHeaders,
cookie: req.headers.cookie || '',
},
headers: revalidateHeaders,
})
// we use the cache header to determine successful revalidate as
// a non-200 status code can be returned from a successful revalidate
......
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