Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to extract request http headers from a request using NodeJS connect

Tags:

node.js

I'd like to get the "Host" header of a request made using Node JS's connect library bundle. My code looks like:

var app = connect()   .use(connect.logger('dev'))   .use(connect.static('public'))   .use(function(req, res){      var host = req.???    })  .listen(3000); 

The documentation for connect is here but I don't see anything detailing the API of the req object in the above code. http://www.senchalabs.org/connect/

Edit: Note a successful answer must point to the documentation (I need this to verify which version provided the API I'm looking for).

like image 639
Alex Spurling Avatar asked Oct 30 '12 21:10

Alex Spurling


People also ask

How do I capture a request header?

Google Chrome has the ability to view HTTP request headers built-in. From the menu, select 'Tools / Developer Tools' and then press the 'Network' button. When you now go to the required page the HTTP requests are displayed in the lower pane. Right click in this pane will provide the option to 'Save all as a HAR file'.

What is HTTP header in node js?

The header tells the server details about the request such as what type of data the client, user, or request wants in the response. Type can be html , text , JSON , cookies or others.


Video Answer


1 Answers

If you use Express 4.x, you can use the req.get(headerName) method as described in Express 4.x API Reference

like image 183
Sami Avatar answered Oct 13 '22 00:10

Sami