Skip to content

Commit

Permalink
only include the port number in the Host header when non-default port
Browse files Browse the repository at this point in the history
Fixes #22.
  • Loading branch information
TooTallNate committed Jul 11, 2017
1 parent ed300a4 commit d7a4c70
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,23 @@ HttpsProxyAgent.prototype.callback = function connect(req, opts, fn) {
headers['Proxy-Authorization'] =
'Basic ' + new Buffer(proxy.auth).toString('base64');
}
headers['Host'] = hostname;

// the Host header should only include the port
// number when it is a non-standard port
var host = opts.host;
if (!isDefaultPort(opts.port, opts.secureEndpoint)) {
host += ':' + opts.port;
}
headers['Host'] = host;

headers['Connection'] = 'close';
Object.keys(headers).forEach(function(name) {
msg += name + ': ' + headers[name] + '\r\n';
});

socket.write(msg + '\r\n');
};

function isDefaultPort(port, secure) {
return Boolean((!secure && port === 80) || (secure && port === 443));
}

0 comments on commit d7a4c70

Please sign in to comment.