vercel / vercel/next.js

NextResponse.rewrite does not override origin server headers

Open
#70,515 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug Middleware
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
  1. Start the app
  2. Request /rewrite
  3. Inspect the response headers
  4. Verify that the Cache-Control header is not overriden
  5. 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.