Skip to content

Commit

Permalink
Merge pull request #366 from Automattic/fix-default-port
Browse files Browse the repository at this point in the history
fix default port detection when host is specified
  • Loading branch information
rauchg committed Jan 12, 2015
2 parents d0e8643 + bfc48ec commit e3fe9a2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@ function Socket(uri, opts){
if (opts.host) {
var pieces = opts.host.split(':');
opts.hostname = pieces.shift();
if (pieces.length) opts.port = pieces.pop();
if (pieces.length) {
opts.port = pieces.pop();
} else if (!opts.port) {
// if no port is specified manually, use the protocol default
opts.port = self.secure ? '443' : '80';
}
}

this.agent = opts.agent || false;
Expand Down
20 changes: 20 additions & 0 deletions test/engine.io-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,24 @@ describe('engine.io-client', function () {
expect(eio.protocol).to.be.a('number');
});

it('should properly parse http uri without port', function() {
var server = eio('http://localhost');
expect(server.port).to.be('80');
});

it('should properly parse https uri without port', function() {
var server = eio('https://localhost');
expect(server.port).to.be('443');
});

it('should properly parse wss uri without port', function() {
var server = eio('wss://localhost');
expect(server.port).to.be('443');
});

it('should properly parse wss uri with port', function() {
var server = eio('wss://localhost:2020');
expect(server.port).to.be('2020');
});

});

0 comments on commit e3fe9a2

Please sign in to comment.