Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NextResponse.rewrite does not override origin server headers #70515

Open
Gebov opened this issue Sep 26, 2024 · 2 comments
Open

NextResponse.rewrite does not override origin server headers #70515

Gebov opened this issue Sep 26, 2024 · 2 comments
Labels
bug Issue was opened via the bug report template. Middleware Related to Next.js Middleware.

Comments

@Gebov
Copy link
Contributor

Gebov commented Sep 26, 2024

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

@Gebov Gebov added the bug Issue was opened via the bug report template. label Sep 26, 2024
@github-actions github-actions bot added the Middleware Related to Next.js Middleware. label Sep 26, 2024
@abhi12299
Copy link
Contributor

isn't this the desired behaviour? priority should be given to the website being redirected to, so that things dont break there. Also, there's no docs regarding the desired behaviour, so you may argue otherwise

@Gebov
Copy link
Contributor Author

Gebov commented Sep 28, 2024

@abhi12299 maybe there is no single solution. In that case, I would expect this to be configurable with an override flag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue was opened via the bug report template. Middleware Related to Next.js Middleware.
Projects
None yet
Development

No branches or pull requests

2 participants