vercel / next.js

The React Framework
https://nextjs.org
MIT License
127.01k stars 26.99k forks source link

Development server exposes different request headers like content-encoding #49081

Open nickbabcock opened 1 year ago

nickbabcock commented 1 year ago

Verify canary release

Provide environment information

Operating System:
      Platform: linux
      Arch: x64
      Version: #39~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Fri Mar 17 21:16:15 UTC 2
    Binaries:
      Node: 18.12.1
      npm: 8.19.2
      Yarn: 1.22.19
      pnpm: 7.17.1
    Relevant packages:
      next: 13.3.5-canary.2
      eslint-config-next: 13.3.4
      react: 18.2.0
      react-dom: 18.2.0

Which area(s) of Next.js are affected? (leave empty if unsure)

No response

Link to the code that reproduces this issue

https://stackblitz.com/edit/vercel-next-js-vhqros

To Reproduce

Start dev server:

npm run dev

Send request with a Content-Encoding header to the endpoint:

echo '{"mydummy": "json"}' | gzip | curl --data-binary @- -H "Content-Encoding: gzip" http://localhost:3000/api/hello

Describe the Bug

The Next.js 13.3.x dev server returns

{}

Whereas the production server (and Next.js 13.2.x dev server) returns:

{"content-encoding":"gzip"}

Potentially related discussion

Expected Behavior

I would expect Next.js 13.3.x dev server to have the same behavior as the production server in regards to handling headers, like how Next.js 13.2.x did.

import type { NextApiRequest, NextApiResponse } from 'next';

export default function handler(req: NextApiRequest, res: NextApiResponse) {
  res.status(200).json({ 'content-encoding': req.headers['content-encoding'] });
}

Which browser are you using? (if relevant)

N/A

How are you deploying your application? (if relevant)

N/A

smaeda-ks commented 1 year ago

looks like it's coming from here: https://github.com/vercel/next.js/blob/6527d29c8a1b5f7f497107bb39a46025e4459318/packages/next/src/server/next-server.ts#L1513