vercel / vercel/next.js

Middleware: Response headers gets set on Request aswell

Open
#77,652 6 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Headers 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/sommeeeer/opennext-middleware-request-headers-issue

To Reproduce
  1. pnpm build && pnpm start
  2. curl http://localhost:3000/test
  3. Visit http://localhost:3000/issue-page and http://localhost:3000/issue-action
Current vs. Expected behavior

When you set response headers in middleware.ts I expect it not to be on both the request headers and response headers in any route. Can confirm this is an issue on 15.x.x, and on latest 14.

Provide environment information
Operating System:
  Platform: linux
  Arch: x64
  Version: #47~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Oct  2 16:16:55 UTC 2
  Available memory (MB): 14800
  Available CPU cores: 16
Binaries:
  Node: 20.18.0
  npm: 11.1.0
  Yarn: N/A
  pnpm: 9.15.4
Relevant Packages:
  next: 15.2.4 // Latest available version is detected (15.2.4).
  eslint-config-next: 15.2.4
  react: 19.1.0
  react-dom: 19.1.0
  typescript: 5.8.2
Next.js Config:
  output: N/A
Which area(s) are affected? (Select all that apply)

Middleware, Headers

Which stage(s) are affected? (Select all that apply)

next start (local), next dev (local)

Additional context

I tested with standalone build too. Same problem there.

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 run pnpm build && pnpm start, then request /test and visit /issue-page and /issue-action. Inspect middleware.ts and the middleware request/response handling involved in those routes; done means response headers set by middleware no longer appear in request headers across the reported local stages.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nextjs, react
Domain
backend, web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.