javascript – Retrieve raw HTTP headers in node.js http module – Stack Overflow

I’m trying to get the raw HTTP headers of a request in the node.js HTTP module. I want to extract the request line:

GET / HTTP/1.1

However, there doesn’t seem to be a way to do it.

I’m instead using a format: ${req.method} ${req.url} HTTP/${req.httpVersion} to do it.

I looked through the Node http module docs for information on the headers, but I couldn’t find a way to extract the raw headers from the request.

Is there a way to do it in vanilla Node?

The reason I want to get the request line is to test what happens if I make a request with invalid headers.

Read more here: Source link