Skip to content

Commit 3efa096

Browse files
committed
Removes automatic port appending to "Host" header.
Previously, a `port` (443) was appended automatically to the "Host" header if the given `endpoint` URL is a secure URL (starts with "https://"). With this Pull Request a port is only appended if it is also present in the `endpoint` URL.
1 parent c6c1fba commit 3efa096

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

lib/http.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ exports.request = function(rurl, data, callback, exheaders, exoptions) {
1414
var curl = url.parse(rurl);
1515
var secure = curl.protocol === 'https:';
1616
var host = curl.hostname;
17-
var port = parseInt(curl.port || (secure ? 443 : false));
17+
var port = parseInt(curl.port, 10);
1818
var path = [curl.pathname || '/', curl.search || '', curl.hash || ''].join('');
1919
var method = data ? "POST" : "GET";
2020
var headers = {
@@ -23,7 +23,7 @@ exports.request = function(rurl, data, callback, exheaders, exoptions) {
2323
"Accept-Encoding": "none",
2424
"Accept-Charset": "utf-8",
2525
"Connection": "close",
26-
"Host" : host + (port ? ":"+port : "")
26+
"Host": host + (isNaN(port) ? "" : ":" + port)
2727
};
2828
var attr;
2929

test/client-test.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,30 @@ describe('SOAP Client', function() {
101101
}, 'http://127.0.0.1');
102102
});
103103

104+
it('should not append `:443` to the Host header if endpoints runs on `https`', function (done) {
105+
soap.createClient(__dirname+'/wsdl/default_namespace.wsdl', function(err, client) {
106+
assert.ok(client);
107+
assert.ok(!err);
108+
109+
client.MyOperation({}, function() {
110+
assert.equal(client.lastRequestHeaders.Host.indexOf(':443'), -1);
111+
done();
112+
}, null, {"test-header": 'test'});
113+
}, 'https://127.0.0.1');
114+
});
115+
116+
it('should append a port to the Host header if explicitly defined', function (done) {
117+
soap.createClient(__dirname+'/wsdl/default_namespace.wsdl', function(err, client) {
118+
assert.ok(client);
119+
assert.ok(!err);
120+
121+
client.MyOperation({}, function() {
122+
assert.ok(client.lastRequestHeaders.Host.indexOf(':443') > -1);
123+
done();
124+
}, null, {"test-header": 'test'});
125+
}, 'https://127.0.0.1:443');
126+
});
127+
104128
it('should have the correct extra header in the request', function(done) {
105129
soap.createClient(__dirname+'/wsdl/default_namespace.wsdl', function(err, client) {
106130
assert.ok(client);

0 commit comments

Comments
 (0)