I have this in my Node script (simplified for this question):
var http = require("http"),
url = require("url"),
options = url.parse("http://example.com/"),
moreOptions = url.parse("http://example.net/"),
callback,
request,
moreDifferentRequest;
callback = function( res ) {
console.log(res.socket._httpMessage._headers.host);
}
request = http.request( options, callback );
request.end();
moreDifferentRequest = http.request( moreDifferentOptions, callback );
moreDifferentRequest.end();
I grab the host name from res.socket._httpMessage._headers.hostbecause it does not exist in res.headers.
But underscores give me a break. They tell me: "Hey, this should be considered as private property for internal use only socket, so do not read it because it can completely change in a later version, and we are not going to tell you.
If I am right to think that I am doing it wrong, what is the correct way to get the hostname inside the callback? Or am I just completely misinterpreting the underscores, and what am I doing is fine?
Trott source
share