I'm trying to append additional header to an incoming request, it can't seem to work.
server.get('/', function md1(req, res, next) {
req.setHeader('px-test-header', 1234); // Error - "req.setHeader is not a function"
req.headers['px-test-header'] = 1234; // nothing happens
}, function (req, res, next) {
console.log(req.get('px-test-header')); // always undefined
}, handler);
What am I doing wrong? Is it even possible?
Note - I do not want to modify the request object with additional parameter instead.
setHeader is a function for response type of objects not requests as from the documentation
But if you still want to set the headers in request then you could do something like
app.get('/', function(req,res){
req.headers.abc ='xyz';
console.log(req);
});
req are stored in req.headers so you could add your custom headers here for application middle wares to use later.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With