question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error accessing request.headers middleware

See original GitHub issue

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System: Platform: win32 Arch: x64 Version: Windows 10 Pro Binaries: Node: 16.13.2 npm: N/A Yarn: N/A pnpm: N/A Relevant packages: next: 12.2.5 eslint-config-next: 12.2.5 react: 18.2.0 react-dom: 18.2.0

What browser are you using? (if relevant)

Chrome

How are you deploying your application? (if relevant)

No response

Describe the Bug

I tried to access the request.headers in the Next.js Middleware but the data is not showing up.

If I access something else, the data can appear

if i display headers it gets an error

Server Error
TypeError: Cannot delete property 'Symbol(set-cookie)' of #<HeadersList2>
  1. Img 1 = Code in Middleware
  2. Img 2 = Fill in the data in the request variable
  3. Img 3 = Error when I display request.headers

Img 1 Img 2 Img 3

Expected Behavior

i can access request.headers.referer

Link to reproduction

To Reproduce

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:10
  • Comments:5

github_iconTop GitHub Comments

1reaction
aliaksandr-savitskicommented, Aug 23, 2022

I had the same problem and seems like accessing directly request.headers object throws that type of error, which is counter intuitive at all, and hard to debug for FE person, maybe a specific error handling for that case would be a good idea?

The solution is to ether access needed header by request.headers.get('header-name-here') . If you need to list them, you may use request.headers.values(callback). Thank should solve the issue

0reactions
github-actions[bot]commented, Sep 23, 2022

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error accessing request.headers in Next.js middleware
You can't access the headers object directly inside the middleware. If you want to access a specific header you should use the get...
Read more >
Using custom HTTP Headers · Twirp
Read HTTP Headers from requests · Write some middleware (a func(http.Handler) http.Handler) that reads the header's value and stores it in the request...
Read more >
Cross-Origin Resource Sharing (CORS) - MDN Web Docs
The Access-Control-Request-Headers header notifies the server that when the actual request is sent, it will do so with X-PINGOTHER and Content- ...
Read more >
Request and response objects - Django documentation
HttpRequest.headers is a simpler way to access all HTTP-prefixed headers, plus CONTENT_LENGTH and CONTENT_TYPE . HttpRequest. headers ¶. A case insensitive, ...
Read more >
Headers - Traefik Labs documentation
In Traefik Proxy, the HTTP headers middleware manages the headers of requests ... Regular expressions and replacements can be tested using online tools...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found