I am using nodejs and expressjs. I wonder if there is something like request.headers.protocol in the clientRequest object. I would like to build the baseUrl for
If you are using request module and for example want to know what protocol does some www use, you can use: response.request.uri.protocol
request(YOUR_TARGET, function(error, response, body){
if (error){
console.log(error);
}
else {
console.log(response.request.uri.protocol); // will show HTTP or HTTPS
}
});
If you need user protocol then use request.headers.referer.split(':')[0]; just like @Harsh gave you.