NextResponse.rewrite does not override origin server headers
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 142k
- Forks
- 32.5k
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 351
Description
Link to the code that reproduces this issue
https://github.com/Gebov/nextjs-rewrite-headers
To Reproduce
- Start the app
- Request /rewrite
- Inspect the response headers
- Verify that the Cache-Control header is not overriden
- Verify that the custom header is overriden
Current vs. Expected behavior
Currently the app is configured to proxy requests to nextjs.org with the URL /rewrite.
I expect all the headers specified in the NextResponse.headers to be overriden. In particular the Cache-Control header.
Currently it is not overriden. Custom headers work.
Provide environment information
Operating System:
Platform: win32
Arch: x64
Version: Windows 11 Enterprise
Available memory (MB): 32488
Available CPU cores: 16
Binaries:
Node: 20.15.0
npm: N/A
Yarn: N/A
pnpm: N/A
Relevant Packages:
next: 14.2.13 // Latest available version is detected (14.2.13).
eslint-config-next: N/A
react: 18.3.1
react-dom: 18.3.1
typescript: N/A
Next.js Config:
output: N/A
Which area(s) are affected? (Select all that apply)
Middleware
Which stage(s) are affected? (Select all that apply)
next dev (local), next start (local)
Additional context
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked reproduction repository and follow its /rewrite request in next dev and next start. Inspect the middleware response headers, especially NextResponse.headers and the proxied origin response. Done means the specified Cache-Control header and custom headers both override the origin headers.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, next.js
- Domain
- backend, web-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100