rsnext/packages/next/server/internal-utils.ts
Tim Neutkens 2358e9c296
Rename RSC and Router headers (#42482)
Removes the `_` prefix from the RSC and Router headers as nginx strips
`_` prefixed headers by default.

Fixes #42164

<!--
Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change that you're making:
-->

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the
feature request has been accepted for implementation before opening a
PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
2022-11-07 16:35:32 -08:00

33 lines
715 B
TypeScript

import type { NextParsedUrlQuery } from './request-meta'
const INTERNAL_QUERY_NAMES = [
'__nextFallback',
'__nextLocale',
'__nextDefaultLocale',
'__nextIsNotFound',
] as const
const EXTENDED_INTERNAL_QUERY_NAMES = ['__nextDataReq'] as const
export function stripInternalQueries(query: NextParsedUrlQuery) {
for (const name of INTERNAL_QUERY_NAMES) {
delete query[name]
}
}
export function stripInternalSearchParams(
searchParams: URLSearchParams,
extended?: boolean
) {
for (const name of INTERNAL_QUERY_NAMES) {
searchParams.delete(name)
}
if (extended) {
for (const name of EXTENDED_INTERNAL_QUERY_NAMES) {
searchParams.delete(name)
}
}
return searchParams
}