Skip to content

Commit d7a4c70

Browse files
committed
only include the port number in the Host header when non-default port
Fixes #22.
1 parent ed300a4 commit d7a4c70

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

index.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,23 @@ HttpsProxyAgent.prototype.callback = function connect(req, opts, fn) {
206206
headers['Proxy-Authorization'] =
207207
'Basic ' + new Buffer(proxy.auth).toString('base64');
208208
}
209-
headers['Host'] = hostname;
209+
210+
// the Host header should only include the port
211+
// number when it is a non-standard port
212+
var host = opts.host;
213+
if (!isDefaultPort(opts.port, opts.secureEndpoint)) {
214+
host += ':' + opts.port;
215+
}
216+
headers['Host'] = host;
217+
210218
headers['Connection'] = 'close';
211219
Object.keys(headers).forEach(function(name) {
212220
msg += name + ': ' + headers[name] + '\r\n';
213221
});
214222

215223
socket.write(msg + '\r\n');
216224
};
225+
226+
function isDefaultPort(port, secure) {
227+
return Boolean((!secure && port === 80) || (secure && port === 443));
228+
}

0 commit comments

Comments
 (0)