You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 a setHeader function in the request object could be a solution to this issue.
constexpress=require('express');constapp=express();app.use((req,res,next)=>{req.headers['X-filipe']='filipe';next();});app.get('/',(req,res)=>{res.json({header: req.get('x-filipe')});});app.listen(3000,()=>{console.log('Server is listening on port 3000');});
Expected output:
{"header": "filipe"}
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:
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 String.prototype.toLowerCase method.
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://github.com/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: