-
Notifications
You must be signed in to change notification settings - Fork 15.9k
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
Express 4 and 5 req.get
doesnt return header if not set in lowercase
#5288
Comments
Yes, you need to set https://nodejs.org/dist/latest-v21.x/docs/api/http.html#messageheaders
|
When middleware start working, all headers alredy parsed and transformed if neede. All middleware changes goes on top of this updates. So be sure to controll it yourself or with |
In the documentation, it's stated that
req.get
is intended to be case-insensitive. However, it appears that when you set a custom header in a middleware, this case-insensitivity breaks if the header is not in lowercase. Should this behavior be corrected, or should the guidance be to always set headers in lowercase? Perhaps, adding asetHeader
function in the request object could be a solution to this issue.The problem seems to originate from this part of the code: https:/expressjs/express/blob/master/lib/request.js#L82, where the headers are not being converted to lowercase, while the input is.
Example code
Expected output:
This adjustment ensures that the headers are consistently in lowercase, aligning with the case-insensitive nature of
req.get
.The text was updated successfully, but these errors were encountered: