Skip to content

Get exact reuest header in node http

Is there a way to see/inspect the complete request header send by the native node http module? I’m doing sth. like that:

const req = Http.request(http_request_options, res => {...

and I’ like to see if there are any cookies send with this request.



I think Node’s documentation will tell you of any headers it will add. Reviewing it, it looks like by default it will add the Host header, but I didn’t see any others unless you add auth in the options. (And a quick test using the methods below confirmed that.)

Also, request returns a ClientRequest object, which has methods you can use to inspect it, such as getRawHeaderNames (new in v15.13) and getHeader, which you could use to see what headers are present.

Externally, you could always set up a quick HTTP server (perhaps also using Node) to see what headers you receive…

User contributions licensed under: CC BY-SA
1 People found this is helpful