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).
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'.
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.
If you use Express 4.x, you can use the req.get(headerName)
method as described in Express 4.x API Reference
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