Unverified Commit ee284b8b authored by Janka Uryga's avatar Janka Uryga Committed by GitHub

refactor: lowercase app router header values (#82169)

we define most of the app router headers with capital letters, like
this:
```ts
export const NEXT_ROUTER_PREFETCH_HEADER = 'Next-Router-Prefetch' as const
```
which means we have to keep lowercasing the header everywhere when
checking for its presence, because node and other intermediate layers
normalize all headers to lowercase:
```ts
if (req.headers[NEXT_ROUTER_PREFETCH_HEADER.toLowerCase()]) { ... }
```
this seems pretty pointless -- we can just define the headers in
lowercase form, and skip all those `toLowerCase()` calls.

(all the above sentences have been normalized to lowercase to match the
spirit of this pr)
parent dd2e89a9
export const RSC_HEADER = 'RSC' as const export const RSC_HEADER = 'rsc' as const
export const ACTION_HEADER = 'Next-Action' as const export const ACTION_HEADER = 'next-action' as const
// TODO: Instead of sending the full router state, we only need to send the // TODO: Instead of sending the full router state, we only need to send the
// segment path. Saves bytes. Then we could also use this field for segment // segment path. Saves bytes. Then we could also use this field for segment
// prefetches, which also need to specify a particular segment. // prefetches, which also need to specify a particular segment.
export const NEXT_ROUTER_STATE_TREE_HEADER = 'Next-Router-State-Tree' as const export const NEXT_ROUTER_STATE_TREE_HEADER = 'next-router-state-tree' as const
export const NEXT_ROUTER_PREFETCH_HEADER = 'Next-Router-Prefetch' as const export const NEXT_ROUTER_PREFETCH_HEADER = 'next-router-prefetch' as const
// This contains the path to the segment being prefetched. // This contains the path to the segment being prefetched.
// TODO: If we change Next-Router-State-Tree to be a segment path, we can use // TODO: If we change next-router-state-tree to be a segment path, we can use
// that instead. Then Next-Router-Prefetch and Next-Router-Segment-Prefetch can // that instead. Then next-router-prefetch and next-router-segment-prefetch can
// be merged into a single enum. // be merged into a single enum.
export const NEXT_ROUTER_SEGMENT_PREFETCH_HEADER = export const NEXT_ROUTER_SEGMENT_PREFETCH_HEADER =
'Next-Router-Segment-Prefetch' as const 'next-router-segment-prefetch' as const
export const NEXT_HMR_REFRESH_HEADER = 'Next-HMR-Refresh' as const export const NEXT_HMR_REFRESH_HEADER = 'next-hmr-refresh' as const
export const NEXT_HMR_REFRESH_HASH_COOKIE = '__next_hmr_refresh_hash__' as const export const NEXT_HMR_REFRESH_HASH_COOKIE = '__next_hmr_refresh_hash__' as const
export const NEXT_URL = 'Next-Url' as const export const NEXT_URL = 'next-url' as const
export const RSC_CONTENT_TYPE_HEADER = 'text/x-component' as const export const RSC_CONTENT_TYPE_HEADER = 'text/x-component' as const
export const FLIGHT_HEADERS = [ export const FLIGHT_HEADERS = [
......
...@@ -282,28 +282,23 @@ function parseRequestHeaders( ...@@ -282,28 +282,23 @@ function parseRequestHeaders(
// dev warmup requests are treated as prefetch RSC requests // dev warmup requests are treated as prefetch RSC requests
const isPrefetchRequest = const isPrefetchRequest =
isDevWarmupRequest || isDevWarmupRequest || headers[NEXT_ROUTER_PREFETCH_HEADER] !== undefined
headers[NEXT_ROUTER_PREFETCH_HEADER.toLowerCase()] !== undefined
const isHmrRefresh = const isHmrRefresh = headers[NEXT_HMR_REFRESH_HEADER] !== undefined
headers[NEXT_HMR_REFRESH_HEADER.toLowerCase()] !== undefined
// dev warmup requests are treated as prefetch RSC requests // dev warmup requests are treated as prefetch RSC requests
const isRSCRequest = const isRSCRequest = isDevWarmupRequest || headers[RSC_HEADER] !== undefined
isDevWarmupRequest || headers[RSC_HEADER.toLowerCase()] !== undefined
const shouldProvideFlightRouterState = const shouldProvideFlightRouterState =
isRSCRequest && (!isPrefetchRequest || !options.isRoutePPREnabled) isRSCRequest && (!isPrefetchRequest || !options.isRoutePPREnabled)
const flightRouterState = shouldProvideFlightRouterState const flightRouterState = shouldProvideFlightRouterState
? parseAndValidateFlightRouterState( ? parseAndValidateFlightRouterState(headers[NEXT_ROUTER_STATE_TREE_HEADER])
headers[NEXT_ROUTER_STATE_TREE_HEADER.toLowerCase()]
)
: undefined : undefined
// Checks if this is a prefetch of the Route Tree by the Segment Cache // Checks if this is a prefetch of the Route Tree by the Segment Cache
const isRouteTreePrefetchRequest = const isRouteTreePrefetchRequest =
headers[NEXT_ROUTER_SEGMENT_PREFETCH_HEADER.toLowerCase()] === '/_tree' headers[NEXT_ROUTER_SEGMENT_PREFETCH_HEADER] === '/_tree'
const csp = const csp =
headers['content-security-policy'] || headers['content-security-policy'] ||
...@@ -399,7 +394,7 @@ function NonIndex({ ...@@ -399,7 +394,7 @@ function NonIndex({
/** /**
* This is used by server actions & client-side navigations to generate RSC data from a client-side request. * This is used by server actions & client-side navigations to generate RSC data from a client-side request.
* This function is only called on "dynamic" requests (ie, there wasn't already a static response). * This function is only called on "dynamic" requests (ie, there wasn't already a static response).
* It uses request headers (namely `Next-Router-State-Tree`) to determine where to start rendering. * It uses request headers (namely `next-router-state-tree`) to determine where to start rendering.
*/ */
async function generateDynamicRSCPayload( async function generateDynamicRSCPayload(
ctx: AppRenderContext, ctx: AppRenderContext,
......
...@@ -9,6 +9,6 @@ import { FLIGHT_HEADERS } from '../../client/components/app-router-headers' ...@@ -9,6 +9,6 @@ import { FLIGHT_HEADERS } from '../../client/components/app-router-headers'
*/ */
export function stripFlightHeaders(headers: IncomingHttpHeaders) { export function stripFlightHeaders(headers: IncomingHttpHeaders) {
for (const header of FLIGHT_HEADERS) { for (const header of FLIGHT_HEADERS) {
delete headers[header.toLowerCase()] delete headers[header]
} }
} }
...@@ -28,7 +28,7 @@ import type { ImplicitTags } from '../lib/implicit-tags' ...@@ -28,7 +28,7 @@ import type { ImplicitTags } from '../lib/implicit-tags'
function getHeaders(headers: Headers | IncomingHttpHeaders): ReadonlyHeaders { function getHeaders(headers: Headers | IncomingHttpHeaders): ReadonlyHeaders {
const cleaned = HeadersAdapter.from(headers) const cleaned = HeadersAdapter.from(headers)
for (const header of FLIGHT_HEADERS) { for (const header of FLIGHT_HEADERS) {
cleaned.delete(header.toLowerCase()) cleaned.delete(header)
} }
return HeadersAdapter.seal(cleaned) return HeadersAdapter.seal(cleaned)
......
...@@ -614,10 +614,9 @@ export default abstract class Server< ...@@ -614,10 +614,9 @@ export default abstract class Server<
parsedUrl.pathname = originalPathname parsedUrl.pathname = originalPathname
// Mark the request as a router prefetch request. // Mark the request as a router prefetch request.
req.headers[RSC_HEADER.toLowerCase()] = '1' req.headers[RSC_HEADER] = '1'
req.headers[NEXT_ROUTER_PREFETCH_HEADER.toLowerCase()] = '1' req.headers[NEXT_ROUTER_PREFETCH_HEADER] = '1'
req.headers[NEXT_ROUTER_SEGMENT_PREFETCH_HEADER.toLowerCase()] = req.headers[NEXT_ROUTER_SEGMENT_PREFETCH_HEADER] = segmentPath
segmentPath
addRequestMeta(req, 'isRSCRequest', true) addRequestMeta(req, 'isRSCRequest', true)
addRequestMeta(req, 'isPrefetchRSCRequest', true) addRequestMeta(req, 'isPrefetchRSCRequest', true)
...@@ -629,8 +628,8 @@ export default abstract class Server< ...@@ -629,8 +628,8 @@ export default abstract class Server<
) )
// Mark the request as a router prefetch request. // Mark the request as a router prefetch request.
req.headers[RSC_HEADER.toLowerCase()] = '1' req.headers[RSC_HEADER] = '1'
req.headers[NEXT_ROUTER_PREFETCH_HEADER.toLowerCase()] = '1' req.headers[NEXT_ROUTER_PREFETCH_HEADER] = '1'
addRequestMeta(req, 'isRSCRequest', true) addRequestMeta(req, 'isRSCRequest', true)
addRequestMeta(req, 'isPrefetchRSCRequest', true) addRequestMeta(req, 'isPrefetchRSCRequest', true)
} else if (this.normalizers.rsc?.match(parsedUrl.pathname)) { } else if (this.normalizers.rsc?.match(parsedUrl.pathname)) {
...@@ -640,7 +639,7 @@ export default abstract class Server< ...@@ -640,7 +639,7 @@ export default abstract class Server<
) )
// Mark the request as a RSC request. // Mark the request as a RSC request.
req.headers[RSC_HEADER.toLowerCase()] = '1' req.headers[RSC_HEADER] = '1'
addRequestMeta(req, 'isRSCRequest', true) addRequestMeta(req, 'isRSCRequest', true)
} else if (req.headers['x-now-route-matches']) { } else if (req.headers['x-now-route-matches']) {
// If we didn't match, return with the flight headers stripped. If in // If we didn't match, return with the flight headers stripped. If in
...@@ -651,14 +650,14 @@ export default abstract class Server< ...@@ -651,14 +650,14 @@ export default abstract class Server<
stripFlightHeaders(req.headers) stripFlightHeaders(req.headers)
return false return false
} else if (req.headers[RSC_HEADER.toLowerCase()] === '1') { } else if (req.headers[RSC_HEADER] === '1') {
addRequestMeta(req, 'isRSCRequest', true) addRequestMeta(req, 'isRSCRequest', true)
if (req.headers[NEXT_ROUTER_PREFETCH_HEADER.toLowerCase()] === '1') { if (req.headers[NEXT_ROUTER_PREFETCH_HEADER] === '1') {
addRequestMeta(req, 'isPrefetchRSCRequest', true) addRequestMeta(req, 'isPrefetchRSCRequest', true)
const segmentPrefetchRSCRequest = const segmentPrefetchRSCRequest =
req.headers[NEXT_ROUTER_SEGMENT_PREFETCH_HEADER.toLowerCase()] req.headers[NEXT_ROUTER_SEGMENT_PREFETCH_HEADER]
if (typeof segmentPrefetchRSCRequest === 'string') { if (typeof segmentPrefetchRSCRequest === 'string') {
addRequestMeta( addRequestMeta(
req, req,
...@@ -1333,7 +1332,7 @@ export default abstract class Server< ...@@ -1333,7 +1332,7 @@ export default abstract class Server<
params params
) )
req.headers[NEXT_ROUTER_SEGMENT_PREFETCH_HEADER.toLowerCase()] = req.headers[NEXT_ROUTER_SEGMENT_PREFETCH_HEADER] =
segmentPrefetchRSCRequest segmentPrefetchRSCRequest
addRequestMeta( addRequestMeta(
req, req,
...@@ -2017,18 +2016,18 @@ export default abstract class Server< ...@@ -2017,18 +2016,18 @@ export default abstract class Server<
const headers = req.headers const headers = req.headers
const isPrefetchRSCRequest = const isPrefetchRSCRequest =
headers[NEXT_ROUTER_PREFETCH_HEADER.toLowerCase()] || headers[NEXT_ROUTER_PREFETCH_HEADER] ||
getRequestMeta(req, 'isPrefetchRSCRequest') getRequestMeta(req, 'isPrefetchRSCRequest')
const segmentPrefetchRSCRequest = const segmentPrefetchRSCRequest =
headers[NEXT_ROUTER_SEGMENT_PREFETCH_HEADER.toLowerCase()] || headers[NEXT_ROUTER_SEGMENT_PREFETCH_HEADER] ||
getRequestMeta(req, 'segmentPrefetchRSCRequest') getRequestMeta(req, 'segmentPrefetchRSCRequest')
const expectedHash = computeCacheBustingSearchParam( const expectedHash = computeCacheBustingSearchParam(
isPrefetchRSCRequest ? '1' : '0', isPrefetchRSCRequest ? '1' : '0',
segmentPrefetchRSCRequest, segmentPrefetchRSCRequest,
headers[NEXT_ROUTER_STATE_TREE_HEADER.toLowerCase()], headers[NEXT_ROUTER_STATE_TREE_HEADER],
headers[NEXT_URL.toLowerCase()] headers[NEXT_URL]
) )
const actualHash = const actualHash =
getRequestMeta(req, 'cacheBustingSearchParam') ?? getRequestMeta(req, 'cacheBustingSearchParam') ??
......
...@@ -743,8 +743,7 @@ export function getResolveRoutes( ...@@ -743,8 +743,7 @@ export function getResolveRoutes(
// is currently on, which wouldn't be extractable from the matched route params. // is currently on, which wouldn't be extractable from the matched route params.
// This attempts to extract the dynamic params from the provided router state. // This attempts to extract the dynamic params from the provided router state.
if (isInterceptionRouteRewrite(route as Rewrite)) { if (isInterceptionRouteRewrite(route as Rewrite)) {
const stateHeader = const stateHeader = req.headers[NEXT_ROUTER_STATE_TREE_HEADER]
req.headers[NEXT_ROUTER_STATE_TREE_HEADER.toLowerCase()]
if (stateHeader) { if (stateHeader) {
rewriteParams = { rewriteParams = {
...@@ -776,7 +775,7 @@ export function getResolveRoutes( ...@@ -776,7 +775,7 @@ export function getResolveRoutes(
} }
// Set the rewrite headers only if this is a RSC request. // Set the rewrite headers only if this is a RSC request.
if (req.headers[RSC_HEADER.toLowerCase()] === '1') { if (req.headers[RSC_HEADER] === '1') {
// We set the rewritten path and query headers on the response now // We set the rewritten path and query headers on the response now
// that we know that the it's not an external rewrite. // that we know that the it's not an external rewrite.
if (parsedUrl.pathname !== parsedDestination.pathname) { if (parsedUrl.pathname !== parsedDestination.pathname) {
......
...@@ -16,10 +16,10 @@ export function getServerActionRequestMetadata( ...@@ -16,10 +16,10 @@ export function getServerActionRequestMetadata(
let contentType: string | null let contentType: string | null
if (req.headers instanceof Headers) { if (req.headers instanceof Headers) {
actionId = req.headers.get(ACTION_HEADER.toLowerCase()) ?? null actionId = req.headers.get(ACTION_HEADER) ?? null
contentType = req.headers.get('content-type') contentType = req.headers.get('content-type')
} else { } else {
actionId = (req.headers[ACTION_HEADER.toLowerCase()] as string) ?? null actionId = (req.headers[ACTION_HEADER] as string) ?? null
contentType = req.headers['content-type'] ?? null contentType = req.headers['content-type'] ?? null
} }
......
...@@ -268,8 +268,7 @@ export function getServerUtils({ ...@@ -268,8 +268,7 @@ export function getServerUtils({
// is currently on, which wouldn't be extractable from the matched route params. // is currently on, which wouldn't be extractable from the matched route params.
// This attempts to extract the dynamic params from the provided router state. // This attempts to extract the dynamic params from the provided router state.
if (isInterceptionRouteRewrite(rewrite as Rewrite)) { if (isInterceptionRouteRewrite(rewrite as Rewrite)) {
const stateHeader = const stateHeader = req.headers[NEXT_ROUTER_STATE_TREE_HEADER]
req.headers[NEXT_ROUTER_STATE_TREE_HEADER.toLowerCase()]
if (stateHeader) { if (stateHeader) {
params = { params = {
......
...@@ -154,11 +154,10 @@ export async function adapter( ...@@ -154,11 +154,10 @@ export async function adapter(
// Headers should only be stripped for middleware // Headers should only be stripped for middleware
if (!isEdgeRendering) { if (!isEdgeRendering) {
for (const header of FLIGHT_HEADERS) { for (const header of FLIGHT_HEADERS) {
const key = header.toLowerCase() const value = requestHeaders.get(header)
const value = requestHeaders.get(key)
if (value !== null) { if (value !== null) {
flightHeaders.set(key, value) flightHeaders.set(header, value)
requestHeaders.delete(key) requestHeaders.delete(header)
} }
} }
} }
......
...@@ -78,9 +78,9 @@ describe('app dir - basepath', () => { ...@@ -78,9 +78,9 @@ describe('app dir - basepath', () => {
page.on('request', (request) => { page.on('request', (request) => {
return request.allHeaders().then((headers) => { return request.allHeaders().then((headers) => {
if ( if (
headers['RSC'.toLowerCase()] === '1' && headers['rsc'] === '1' &&
// Prefetches also include `RSC` // Prefetches also include `rsc`
headers['Next-Router-Prefetch'.toLowerCase()] !== '1' headers['next-router-prefetch'] !== '1'
) { ) {
rscRequests.push(request.url()) rscRequests.push(request.url())
} }
......
...@@ -262,10 +262,10 @@ describe('app dir - prefetching', () => { ...@@ -262,10 +262,10 @@ describe('app dir - prefetching', () => {
) )
const response = await next.fetch(`/prefetch-auto/justputit?_rsc=dcqtr`, { const response = await next.fetch(`/prefetch-auto/justputit?_rsc=dcqtr`, {
headers: { headers: {
RSC: '1', rsc: '1',
'Next-Router-Prefetch': '1', 'next-router-prefetch': '1',
'Next-Router-State-Tree': stateTree, 'next-router-state-tree': stateTree,
'Next-Url': '/prefetch-auto/justputit', 'next-url': '/prefetch-auto/justputit',
}, },
}) })
...@@ -297,18 +297,18 @@ describe('app dir - prefetching', () => { ...@@ -297,18 +297,18 @@ describe('app dir - prefetching', () => {
) )
const headers = { const headers = {
RSC: '1', rsc: '1',
'Next-Router-Prefetch': '1', 'next-router-prefetch': '1',
'Next-Router-State-Tree': stateTree, 'next-router-state-tree': stateTree,
'Next-Url': '/prefetch-auto/vercel', 'next-url': '/prefetch-auto/vercel',
} }
const url = new URL('/prefetch-auto/justputit', 'http://localhost') const url = new URL('/prefetch-auto/justputit', 'http://localhost')
const cacheBustingParam = computeCacheBustingSearchParam( const cacheBustingParam = computeCacheBustingSearchParam(
headers['Next-Router-Prefetch'] ? '1' : '0', headers['next-router-prefetch'] ? '1' : '0',
undefined, undefined,
headers['Next-Router-State-Tree'], headers['next-router-state-tree'],
headers['Next-Url'] headers['next-url']
) )
if (cacheBustingParam) { if (cacheBustingParam) {
url.searchParams.set('_rsc', cacheBustingParam) url.searchParams.set('_rsc', cacheBustingParam)
......
...@@ -16,13 +16,13 @@ describe('app dir - validation', () => { ...@@ -16,13 +16,13 @@ describe('app dir - validation', () => {
const stateTree2 = JSON.stringify(['', {}]) const stateTree2 = JSON.stringify(['', {}])
const headers1 = { const headers1 = {
RSC: '1', rsc: '1',
'Next-Router-State-Tree': stateTree1, 'next-router-state-tree': stateTree1,
} }
const headers2 = { const headers2 = {
RSC: '1', rsc: '1',
'Next-Router-State-Tree': stateTree2, 'next-router-state-tree': stateTree2,
} }
const url1 = new URL('/', 'http://localhost') const url1 = new URL('/', 'http://localhost')
......
...@@ -334,7 +334,7 @@ describe('app dir - basic', () => { ...@@ -334,7 +334,7 @@ describe('app dir - basic', () => {
const res = await next.fetch('/dashboard') const res = await next.fetch('/dashboard')
expect(res.headers.get('x-edge-runtime')).toBe('1') expect(res.headers.get('x-edge-runtime')).toBe('1')
expect(res.headers.get('vary')).toBe( expect(res.headers.get('vary')).toBe(
'RSC, Next-Router-State-Tree, Next-Router-Prefetch, Next-Router-Segment-Prefetch' 'rsc, next-router-state-tree, next-router-prefetch, next-router-segment-prefetch'
) )
}) })
...@@ -346,8 +346,8 @@ describe('app dir - basic', () => { ...@@ -346,8 +346,8 @@ describe('app dir - basic', () => {
}) })
expect(res.headers.get('vary')).toBe( expect(res.headers.get('vary')).toBe(
isNextDeploy isNextDeploy
? 'RSC, Next-Router-State-Tree, Next-Router-Prefetch, Next-Router-Segment-Prefetch' ? 'rsc, next-router-state-tree, next-router-prefetch, next-router-segment-prefetch'
: 'RSC, Next-Router-State-Tree, Next-Router-Prefetch, Next-Router-Segment-Prefetch, Accept-Encoding' : 'rsc, next-router-state-tree, next-router-prefetch, next-router-segment-prefetch, Accept-Encoding'
) )
}) })
......
...@@ -41,8 +41,8 @@ export async function middleware(request) { ...@@ -41,8 +41,8 @@ export async function middleware(request) {
? 'rewrite' ? 'rewrite'
: 'redirect' : 'redirect'
const internal = ['RSC', 'Next-Router-State-Tree'] const internal = ['rsc', 'next-router-state-tree']
if (internal.some((name) => request.headers.has(name.toLowerCase()))) { if (internal.some((name) => request.headers.has(name))) {
return NextResponse[method](new URL('/internal/failure', request.url)) return NextResponse[method](new URL('/internal/failure', request.url))
} }
......
...@@ -52,10 +52,10 @@ const addCacheBustingSearchParam = ( ...@@ -52,10 +52,10 @@ const addCacheBustingSearchParam = (
headers: Record<string, string | string[] | undefined> headers: Record<string, string | string[] | undefined>
) => { ) => {
const cacheKey = computeCacheBustingSearchParam( const cacheKey = computeCacheBustingSearchParam(
headers['Next-Router-Prefetch'] ? '1' : '0', headers['next-router-prefetch'] ? '1' : '0',
headers['Next-Router-Segment-Prefetch'], headers['next-router-segment-prefetch'],
headers['Next-Router-State-Tree'], headers['next-router-state-tree'],
headers['Next-URL'] headers['next-url']
) )
if (cacheKey === null) { if (cacheKey === null) {
...@@ -535,8 +535,8 @@ describe('ppr-full', () => { ...@@ -535,8 +535,8 @@ describe('ppr-full', () => {
it('should have correct headers', async () => { it('should have correct headers', async () => {
await retry(async () => { await retry(async () => {
const headers = { const headers = {
RSC: '1', rsc: '1',
'Next-Router-Prefetch': '1', 'next-router-prefetch': '1',
} }
const urlWithCacheBusting = addCacheBustingSearchParam( const urlWithCacheBusting = addCacheBustingSearchParam(
pathname, pathname,
...@@ -573,8 +573,8 @@ describe('ppr-full', () => { ...@@ -573,8 +573,8 @@ describe('ppr-full', () => {
it('should not contain dynamic content', async () => { it('should not contain dynamic content', async () => {
const unexpected = `${Date.now()}:${Math.random()}` const unexpected = `${Date.now()}:${Math.random()}`
const headers = { const headers = {
RSC: '1', rsc: '1',
'Next-Router-Prefetch': '1', 'next-router-prefetch': '1',
'X-Test-Input': unexpected, 'X-Test-Input': unexpected,
} }
const urlWithCacheBusting = addCacheBustingSearchParam( const urlWithCacheBusting = addCacheBustingSearchParam(
...@@ -596,7 +596,7 @@ describe('ppr-full', () => { ...@@ -596,7 +596,7 @@ describe('ppr-full', () => {
describe('Dynamic RSC Response', () => { describe('Dynamic RSC Response', () => {
describe.each(pages)('for $pathname', ({ pathname, dynamic }) => { describe.each(pages)('for $pathname', ({ pathname, dynamic }) => {
it('should have correct headers', async () => { it('should have correct headers', async () => {
const headers = { RSC: '1' } const headers = { rsc: '1' }
const urlWithCacheBusting = addCacheBustingSearchParam( const urlWithCacheBusting = addCacheBustingSearchParam(
pathname, pathname,
headers headers
...@@ -621,7 +621,7 @@ describe('ppr-full', () => { ...@@ -621,7 +621,7 @@ describe('ppr-full', () => {
it('should contain dynamic content', async () => { it('should contain dynamic content', async () => {
const expected = `${Date.now()}:${Math.random()}` const expected = `${Date.now()}:${Math.random()}`
const headers = { const headers = {
RSC: '1', rsc: '1',
'X-Test-Input': expected, 'X-Test-Input': expected,
} }
const urlWithCacheBusting = addCacheBustingSearchParam( const urlWithCacheBusting = addCacheBustingSearchParam(
...@@ -641,7 +641,7 @@ describe('ppr-full', () => { ...@@ -641,7 +641,7 @@ describe('ppr-full', () => {
it('should not contain dynamic content', async () => { it('should not contain dynamic content', async () => {
const unexpected = `${Date.now()}:${Math.random()}` const unexpected = `${Date.now()}:${Math.random()}`
const headers = { const headers = {
RSC: '1', rsc: '1',
'X-Test-Input': unexpected, 'X-Test-Input': unexpected,
} }
const urlWithCacheBusting = addCacheBustingSearchParam( const urlWithCacheBusting = addCacheBustingSearchParam(
......
...@@ -25,7 +25,7 @@ const cases: { ...@@ -25,7 +25,7 @@ const cases: {
name: 'static RSC', name: 'static RSC',
pathname: '/', pathname: '/',
headers: { headers: {
RSC: '1', rsc: '1',
}, },
expected: { expected: {
'x-nextjs-rewritten-path': null, 'x-nextjs-rewritten-path': null,
...@@ -36,8 +36,8 @@ const cases: { ...@@ -36,8 +36,8 @@ const cases: {
name: 'static Prefetch RSC', name: 'static Prefetch RSC',
pathname: '/', pathname: '/',
headers: { headers: {
RSC: '1', rsc: '1',
'Next-Router-Prefetch': '1', 'next-router-prefetch': '1',
}, },
expected: { expected: {
'x-nextjs-rewritten-path': null, 'x-nextjs-rewritten-path': null,
...@@ -56,7 +56,7 @@ const cases: { ...@@ -56,7 +56,7 @@ const cases: {
name: 'prerendered RSC', name: 'prerendered RSC',
pathname: '/hello/world', pathname: '/hello/world',
headers: { headers: {
RSC: '1', rsc: '1',
}, },
expected: { expected: {
'x-nextjs-rewritten-path': null, 'x-nextjs-rewritten-path': null,
...@@ -67,8 +67,8 @@ const cases: { ...@@ -67,8 +67,8 @@ const cases: {
name: 'prerendered Prefetch RSC', name: 'prerendered Prefetch RSC',
pathname: '/hello/world', pathname: '/hello/world',
headers: { headers: {
RSC: '1', rsc: '1',
'Next-Router-Prefetch': '1', 'next-router-prefetch': '1',
}, },
expected: { expected: {
'x-nextjs-rewritten-path': null, 'x-nextjs-rewritten-path': null,
...@@ -87,7 +87,7 @@ const cases: { ...@@ -87,7 +87,7 @@ const cases: {
name: 'middleware rewrite RSC', name: 'middleware rewrite RSC',
pathname: '/hello/wyatt', pathname: '/hello/wyatt',
headers: { headers: {
RSC: '1', rsc: '1',
}, },
expected: { expected: {
'x-nextjs-rewritten-path': '/hello/admin', 'x-nextjs-rewritten-path': '/hello/admin',
...@@ -98,8 +98,8 @@ const cases: { ...@@ -98,8 +98,8 @@ const cases: {
name: 'middleware rewrite Prefetch RSC', name: 'middleware rewrite Prefetch RSC',
pathname: '/hello/wyatt', pathname: '/hello/wyatt',
headers: { headers: {
RSC: '1', rsc: '1',
'Next-Router-Prefetch': '1', 'next-router-prefetch': '1',
}, },
// only: true, // only: true,
expected: { expected: {
...@@ -119,7 +119,7 @@ const cases: { ...@@ -119,7 +119,7 @@ const cases: {
name: 'middleware rewrite dynamic RSC', name: 'middleware rewrite dynamic RSC',
pathname: '/hello/bob', pathname: '/hello/bob',
headers: { headers: {
RSC: '1', rsc: '1',
}, },
expected: { expected: {
'x-nextjs-rewritten-path': '/hello/bobby', 'x-nextjs-rewritten-path': '/hello/bobby',
...@@ -130,8 +130,8 @@ const cases: { ...@@ -130,8 +130,8 @@ const cases: {
name: 'middleware rewrite dynamic Prefetch RSC', name: 'middleware rewrite dynamic Prefetch RSC',
pathname: '/hello/bob', pathname: '/hello/bob',
headers: { headers: {
RSC: '1', rsc: '1',
'Next-Router-Prefetch': '1', 'next-router-prefetch': '1',
}, },
expected: { expected: {
'x-nextjs-rewritten-path': '/hello/bobby', 'x-nextjs-rewritten-path': '/hello/bobby',
...@@ -150,7 +150,7 @@ const cases: { ...@@ -150,7 +150,7 @@ const cases: {
name: 'dynamic RSC', name: 'dynamic RSC',
pathname: '/hello/mary', pathname: '/hello/mary',
headers: { headers: {
RSC: '1', rsc: '1',
}, },
expected: { expected: {
'x-nextjs-rewritten-path': null, 'x-nextjs-rewritten-path': null,
...@@ -161,8 +161,8 @@ const cases: { ...@@ -161,8 +161,8 @@ const cases: {
name: 'dynamic Prefetch RSC', name: 'dynamic Prefetch RSC',
pathname: '/hello/mary', pathname: '/hello/mary',
headers: { headers: {
RSC: '1', rsc: '1',
'Next-Router-Prefetch': '1', 'next-router-prefetch': '1',
}, },
expected: { expected: {
'x-nextjs-rewritten-path': null, 'x-nextjs-rewritten-path': null,
...@@ -181,7 +181,7 @@ const cases: { ...@@ -181,7 +181,7 @@ const cases: {
name: 'dynamic RSC with query', name: 'dynamic RSC with query',
pathname: '/hello/mary?key=value', pathname: '/hello/mary?key=value',
headers: { headers: {
RSC: '1', rsc: '1',
}, },
expected: { expected: {
'x-nextjs-rewritten-path': null, 'x-nextjs-rewritten-path': null,
...@@ -192,8 +192,8 @@ const cases: { ...@@ -192,8 +192,8 @@ const cases: {
name: 'dynamic Prefetch RSC with query', name: 'dynamic Prefetch RSC with query',
pathname: '/hello/mary?key=value', pathname: '/hello/mary?key=value',
headers: { headers: {
RSC: '1', rsc: '1',
'Next-Router-Prefetch': '1', 'next-router-prefetch': '1',
}, },
expected: { expected: {
'x-nextjs-rewritten-path': null, 'x-nextjs-rewritten-path': null,
...@@ -212,7 +212,7 @@ const cases: { ...@@ -212,7 +212,7 @@ const cases: {
name: 'next.config.js rewrites RSC', name: 'next.config.js rewrites RSC',
pathname: '/hello/sam', pathname: '/hello/sam',
headers: { headers: {
RSC: '1', rsc: '1',
}, },
expected: { expected: {
'x-nextjs-rewritten-path': '/hello/samantha', 'x-nextjs-rewritten-path': '/hello/samantha',
...@@ -223,8 +223,8 @@ const cases: { ...@@ -223,8 +223,8 @@ const cases: {
name: 'next.config.js rewrites Prefetch RSC', name: 'next.config.js rewrites Prefetch RSC',
pathname: '/hello/sam', pathname: '/hello/sam',
headers: { headers: {
RSC: '1', rsc: '1',
'Next-Router-Prefetch': '1', 'next-router-prefetch': '1',
}, },
expected: { expected: {
'x-nextjs-rewritten-path': '/hello/samantha', 'x-nextjs-rewritten-path': '/hello/samantha',
...@@ -243,7 +243,7 @@ const cases: { ...@@ -243,7 +243,7 @@ const cases: {
name: 'next.config.js rewrites static RSC', name: 'next.config.js rewrites static RSC',
pathname: '/hello/other', pathname: '/hello/other',
headers: { headers: {
RSC: '1', rsc: '1',
}, },
expected: { expected: {
'x-nextjs-rewritten-path': '/other', 'x-nextjs-rewritten-path': '/other',
...@@ -254,8 +254,8 @@ const cases: { ...@@ -254,8 +254,8 @@ const cases: {
name: 'next.config.js rewrites static Prefetch RSC', name: 'next.config.js rewrites static Prefetch RSC',
pathname: '/hello/other', pathname: '/hello/other',
headers: { headers: {
RSC: '1', rsc: '1',
'Next-Router-Prefetch': '1', 'next-router-prefetch': '1',
}, },
expected: { expected: {
'x-nextjs-rewritten-path': '/other', 'x-nextjs-rewritten-path': '/other',
...@@ -282,7 +282,7 @@ const cases: { ...@@ -282,7 +282,7 @@ const cases: {
name: 'middleware rewrite query RSC', name: 'middleware rewrite query RSC',
pathname: '/hello/john', pathname: '/hello/john',
headers: { headers: {
RSC: '1', rsc: '1',
}, },
expected: { expected: {
'x-nextjs-rewritten-path': null, 'x-nextjs-rewritten-path': null,
...@@ -293,8 +293,8 @@ const cases: { ...@@ -293,8 +293,8 @@ const cases: {
name: 'middleware rewrite query Prefetch RSC', name: 'middleware rewrite query Prefetch RSC',
pathname: '/hello/john', pathname: '/hello/john',
headers: { headers: {
RSC: '1', rsc: '1',
'Next-Router-Prefetch': '1', 'next-router-prefetch': '1',
}, },
expected: { expected: {
'x-nextjs-rewritten-path': null, 'x-nextjs-rewritten-path': null,
...@@ -316,7 +316,7 @@ const cases: { ...@@ -316,7 +316,7 @@ const cases: {
// name: 'middleware rewrite external RSC', // name: 'middleware rewrite external RSC',
// pathname: '/hello/vercel', // pathname: '/hello/vercel',
// headers: { // headers: {
// RSC: '1', // rsc: '1',
// }, // },
// expected: { // expected: {
// // Vercel matches `/` to `/home` // // Vercel matches `/` to `/home`
...@@ -328,8 +328,8 @@ const cases: { ...@@ -328,8 +328,8 @@ const cases: {
// name: 'middleware rewrite external Prefetch RSC', // name: 'middleware rewrite external Prefetch RSC',
// pathname: '/hello/vercel', // pathname: '/hello/vercel',
// headers: { // headers: {
// RSC: '1', // rsc: '1',
// 'Next-Router-Prefetch': '1', // 'next-router-prefetch': '1',
// }, // },
// expected: { // expected: {
// // Vercel matches `/` to `/home` // // Vercel matches `/` to `/home`
...@@ -349,7 +349,7 @@ const cases: { ...@@ -349,7 +349,7 @@ const cases: {
name: 'next.config.js rewrites with query RSC', name: 'next.config.js rewrites with query RSC',
pathname: '/hello/fred', pathname: '/hello/fred',
headers: { headers: {
RSC: '1', rsc: '1',
}, },
expected: { expected: {
'x-nextjs-rewritten-path': '/other', 'x-nextjs-rewritten-path': '/other',
...@@ -360,8 +360,8 @@ const cases: { ...@@ -360,8 +360,8 @@ const cases: {
name: 'next.config.js rewrites with query Prefetch RSC', name: 'next.config.js rewrites with query Prefetch RSC',
pathname: '/hello/fred', pathname: '/hello/fred',
headers: { headers: {
RSC: '1', rsc: '1',
'Next-Router-Prefetch': '1', 'next-router-prefetch': '1',
}, },
expected: { expected: {
'x-nextjs-rewritten-path': '/other', 'x-nextjs-rewritten-path': '/other',
...@@ -380,7 +380,7 @@ const cases: { ...@@ -380,7 +380,7 @@ const cases: {
name: 'next.config.js rewrites with path-matched query RSC', name: 'next.config.js rewrites with path-matched query RSC',
pathname: '/rewrites-to-query/andrew', pathname: '/rewrites-to-query/andrew',
headers: { headers: {
RSC: '1', rsc: '1',
}, },
expected: { expected: {
'x-nextjs-rewritten-path': '/other', 'x-nextjs-rewritten-path': '/other',
...@@ -391,8 +391,8 @@ const cases: { ...@@ -391,8 +391,8 @@ const cases: {
name: 'next.config.js rewrites with path-matched query Prefetch RSC', name: 'next.config.js rewrites with path-matched query Prefetch RSC',
pathname: '/rewrites-to-query/andrew', pathname: '/rewrites-to-query/andrew',
headers: { headers: {
RSC: '1', rsc: '1',
'Next-Router-Prefetch': '1', 'next-router-prefetch': '1',
}, },
expected: { expected: {
'x-nextjs-rewritten-path': '/other', 'x-nextjs-rewritten-path': '/other',
...@@ -416,11 +416,11 @@ describe('rewrite-headers', () => { ...@@ -416,11 +416,11 @@ describe('rewrite-headers', () => {
const url = new URL(pathname, 'http://localhost') const url = new URL(pathname, 'http://localhost')
// Add cache busting param for RSC requests // Add cache busting param for RSC requests
if (headers.RSC === '1') { if (headers.rsc === '1') {
const cacheBustingParam = computeCacheBustingSearchParam( const cacheBustingParam = computeCacheBustingSearchParam(
headers['Next-Router-Prefetch'] ? '1' : '0', headers['next-router-prefetch'] ? '1' : '0',
undefined, undefined,
headers['Next-Router-State-Tree'], headers['next-router-state-tree'],
undefined undefined
) )
if (cacheBustingParam) { if (cacheBustingParam) {
......
...@@ -169,9 +169,9 @@ describe('app dir - rsc basics', () => { ...@@ -169,9 +169,9 @@ describe('app dir - rsc basics', () => {
requestsCount++ requestsCount++
const headers = request.headers() const headers = request.headers()
if ( if (
headers['RSC'.toLowerCase()] === '1' && headers['rsc'] === '1' &&
// Prefetches also include `RSC` // Prefetches also include `rsc`
headers['Next-Router-Prefetch'.toLowerCase()] !== '1' headers['next-router-prefetch'] !== '1'
) { ) {
flightRequests.push(request.url()) flightRequests.push(request.url())
} }
......
...@@ -26,7 +26,7 @@ describe('rsc-redirect', () => { ...@@ -26,7 +26,7 @@ describe('rsc-redirect', () => {
{ {
redirect: 'manual', redirect: 'manual',
headers: { headers: {
RSC: '1', rsc: '1',
}, },
} }
) )
......
...@@ -83,9 +83,9 @@ describe('segment cache (CDN cache busting)', () => { ...@@ -83,9 +83,9 @@ describe('segment cache (CDN cache busting)', () => {
async () => { async () => {
const res = await fetch('/target-page', { const res = await fetch('/target-page', {
headers: { headers: {
RSC: '1', rsc: '1',
'Next-Router-Prefetch': '1', 'next-router-prefetch': '1',
'Next-Router-Segment-Prefetch': '/_tree', 'next-router-segment-prefetch': '/_tree',
}, },
}) })
return { return {
......
...@@ -25,9 +25,9 @@ describe('conflicting routes', () => { ...@@ -25,9 +25,9 @@ describe('conflicting routes', () => {
fetchUrl.search = searchParams.toString() fetchUrl.search = searchParams.toString()
return await next.fetch(fetchUrl.pathname + fetchUrl.search, { return await next.fetch(fetchUrl.pathname + fetchUrl.search, {
headers: { headers: {
RSC: '1', rsc: '1',
'Next-Router-Prefetch': '1', 'next-router-prefetch': '1',
'Next-Router-Segment-Prefetch': segmentPath, 'next-router-segment-prefetch': segmentPath,
}, },
}) })
} }
......
...@@ -37,8 +37,8 @@ describe('segment cache (incremental opt in)', () => { ...@@ -37,8 +37,8 @@ describe('segment cache (incremental opt in)', () => {
const url = request.url() const url = request.url()
const prefetchInfo = { const prefetchInfo = {
href: new URL(url).pathname, href: new URL(url).pathname,
segment: headers['Next-Router-Segment-Prefetch'.toLowerCase()], segment: headers['next-router-segment-prefetch'],
base: headers['Next-Router-State-Tree'.toLowerCase()] ?? null, base: headers['next-router-state-tree'] ?? null,
} }
const key = JSON.stringify(prefetchInfo) const key = JSON.stringify(prefetchInfo)
if (prefetches.has(key)) { if (prefetches.has(key)) {
......
...@@ -28,8 +28,8 @@ _describe('app dir - form prefetching', () => { ...@@ -28,8 +28,8 @@ _describe('app dir - form prefetching', () => {
requestFilter: async (request) => { requestFilter: async (request) => {
// only capture RSC requests that *aren't* prefetches // only capture RSC requests that *aren't* prefetches
const headers = await request.allHeaders() const headers = await request.allHeaders()
const isRSC = headers[RSC_HEADER.toLowerCase()] === '1' const isRSC = headers[RSC_HEADER] === '1'
const isPrefetch = !!headers[NEXT_ROUTER_PREFETCH_HEADER.toLowerCase()] const isPrefetch = !!headers[NEXT_ROUTER_PREFETCH_HEADER]
return isRSC && !isPrefetch return isRSC && !isPrefetch
}, },
log: true, log: true,
...@@ -74,7 +74,7 @@ _describe('app dir - form prefetching', () => { ...@@ -74,7 +74,7 @@ _describe('app dir - form prefetching', () => {
requestFilter: async (request) => { requestFilter: async (request) => {
// capture all RSC requests, prefetch or not // capture all RSC requests, prefetch or not
const headers = await request.allHeaders() const headers = await request.allHeaders()
const isRSC = headers[RSC_HEADER.toLowerCase()] === '1' const isRSC = headers[RSC_HEADER] === '1'
return isRSC return isRSC
}, },
log: true, log: true,
......
...@@ -108,7 +108,7 @@ describe('Switchable runtime', () => { ...@@ -108,7 +108,7 @@ describe('Switchable runtime', () => {
beforePageLoad(page) { beforePageLoad(page) {
page.on('request', (request) => { page.on('request', (request) => {
return request.allHeaders().then((headers) => { return request.allHeaders().then((headers) => {
if (headers['RSC'.toLowerCase()] === '1') { if (headers['rsc'] === '1') {
flightRequest = request.url() flightRequest = request.url()
} }
}) })
...@@ -640,7 +640,7 @@ describe('Switchable runtime', () => { ...@@ -640,7 +640,7 @@ describe('Switchable runtime', () => {
beforePageLoad(page) { beforePageLoad(page) {
page.on('request', (request) => { page.on('request', (request) => {
request.allHeaders().then((headers) => { request.allHeaders().then((headers) => {
if (headers['RSC'.toLowerCase()] === '1') { if (headers['rsc'] === '1') {
flightRequest = request.url() flightRequest = request.url()
} }
}) })
......
...@@ -21,9 +21,9 @@ describe('Vary Header Tests', () => { ...@@ -21,9 +21,9 @@ describe('Vary Header Tests', () => {
expect(res.headers.get('cache-control')).toBe('s-maxage=3600') expect(res.headers.get('cache-control')).toBe('s-maxage=3600')
// Next.js internal headers are appended // Next.js internal headers are appended
expect(varyHeader).toContain('RSC') expect(varyHeader).toContain('rsc')
expect(varyHeader).toContain('Next-Router-State-Tree') expect(varyHeader).toContain('next-router-state-tree')
expect(varyHeader).toContain('Next-Router-Prefetch') expect(varyHeader).toContain('next-router-prefetch')
}) })
it('should preserve middleware vary header in combination with route handlers', async () => { it('should preserve middleware vary header in combination with route handlers', async () => {
...@@ -39,8 +39,8 @@ describe('Vary Header Tests', () => { ...@@ -39,8 +39,8 @@ describe('Vary Header Tests', () => {
expect(varyHeader).toContain('User-Agent') expect(varyHeader).toContain('User-Agent')
// Next.js internal headers are still present // Next.js internal headers are still present
expect(varyHeader).toContain('RSC') expect(varyHeader).toContain('rsc')
expect(varyHeader).toContain('Next-Router-State-Tree') expect(varyHeader).toContain('next-router-state-tree')
expect(varyHeader).toContain('Next-Router-Prefetch') expect(varyHeader).toContain('next-router-prefetch')
}) })
}) })
...@@ -2559,14 +2559,14 @@ const runTests = (isDev = false) => { ...@@ -2559,14 +2559,14 @@ const runTests = (isDev = false) => {
}, },
], ],
rsc: { rsc: {
header: 'RSC', header: 'rsc',
contentTypeHeader: 'text/x-component', contentTypeHeader: 'text/x-component',
didPostponeHeader: 'x-nextjs-postponed', didPostponeHeader: 'x-nextjs-postponed',
varyHeader: varyHeader:
'RSC, Next-Router-State-Tree, Next-Router-Prefetch, Next-Router-Segment-Prefetch', 'rsc, next-router-state-tree, next-router-prefetch, next-router-segment-prefetch',
prefetchHeader: 'Next-Router-Prefetch', prefetchHeader: 'next-router-prefetch',
prefetchSegmentDirSuffix: '.segments', prefetchSegmentDirSuffix: '.segments',
prefetchSegmentHeader: 'Next-Router-Segment-Prefetch', prefetchSegmentHeader: 'next-router-segment-prefetch',
prefetchSegmentSuffix: '.segment.rsc', prefetchSegmentSuffix: '.segment.rsc',
prefetchSuffix: '.prefetch.rsc', prefetchSuffix: '.prefetch.rsc',
suffix: '.rsc', suffix: '.rsc',
......
...@@ -1518,14 +1518,14 @@ function runTests({ dev }) { ...@@ -1518,14 +1518,14 @@ function runTests({ dev }) {
queryHeader: 'x-nextjs-rewritten-query', queryHeader: 'x-nextjs-rewritten-query',
}, },
rsc: { rsc: {
header: 'RSC', header: 'rsc',
contentTypeHeader: 'text/x-component', contentTypeHeader: 'text/x-component',
didPostponeHeader: 'x-nextjs-postponed', didPostponeHeader: 'x-nextjs-postponed',
varyHeader: varyHeader:
'RSC, Next-Router-State-Tree, Next-Router-Prefetch, Next-Router-Segment-Prefetch', 'rsc, next-router-state-tree, next-router-prefetch, next-router-segment-prefetch',
prefetchHeader: 'Next-Router-Prefetch', prefetchHeader: 'next-router-prefetch',
prefetchSegmentDirSuffix: '.segments', prefetchSegmentDirSuffix: '.segments',
prefetchSegmentHeader: 'Next-Router-Segment-Prefetch', prefetchSegmentHeader: 'next-router-segment-prefetch',
prefetchSegmentSuffix: '.segment.rsc', prefetchSegmentSuffix: '.segment.rsc',
prefetchSuffix: '.prefetch.rsc', prefetchSuffix: '.prefetch.rsc',
suffix: '.rsc', suffix: '.rsc',
......
...@@ -92,7 +92,7 @@ describe('minimal-mode-response-cache', () => { ...@@ -92,7 +92,7 @@ describe('minimal-mode-response-cache', () => {
it('app router revalidate should work with previous response cache dynamic', async () => { it('app router revalidate should work with previous response cache dynamic', async () => {
const headers = { const headers = {
vary: 'RSC, Next-Router-State-Tree, Next-Router-Prefetch', vary: 'rsc, next-router-state-tree, next-router-prefetch',
'x-now-route-matches': '1=compare&rsc=1', 'x-now-route-matches': '1=compare&rsc=1',
'x-matched-path': '/app-blog/compare.rsc', 'x-matched-path': '/app-blog/compare.rsc',
'x-vercel-id': '1', 'x-vercel-id': '1',
...@@ -122,7 +122,7 @@ describe('minimal-mode-response-cache', () => { ...@@ -122,7 +122,7 @@ describe('minimal-mode-response-cache', () => {
it('app router revalidate should work with previous response cache', async () => { it('app router revalidate should work with previous response cache', async () => {
const headers = { const headers = {
vary: 'RSC, Next-Router-State-Tree, Next-Router-Prefetch', vary: 'rsc, next-router-state-tree, next-router-prefetch',
'x-now-route-matches': '1=app-another&rsc=1', 'x-now-route-matches': '1=app-another&rsc=1',
'x-matched-path': '/app-another.rsc', 'x-matched-path': '/app-another.rsc',
'x-vercel-id': '1', 'x-vercel-id': '1',
......
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