Skip to content

Commit

Permalink
ipv6 support
Browse files Browse the repository at this point in the history
  • Loading branch information
nkzawa committed Dec 2, 2015
1 parent fc6451c commit 18be967
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
1 change: 0 additions & 1 deletion lib/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* Module dependencies.
*/

var url = require('./url');
var eio = require('engine.io-client');
var Socket = require('./socket');
var Emitter = require('component-emitter');
Expand Down
7 changes: 5 additions & 2 deletions lib/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,13 @@ function url(uri, loc){

obj.path = obj.path || '/';

var ipv6 = obj.host.indexOf(':') !== -1;
var host = ipv6 ? '[' + obj.host + ']' : obj.host;

// define unique id
obj.id = obj.protocol + '://' + obj.host + ':' + obj.port;
obj.id = obj.protocol + '://' + host + ':' + obj.port;
// define href
obj.href = obj.protocol + '://' + obj.host + (loc && loc.port == obj.port ? '' : (':' + obj.port));
obj.href = obj.protocol + '://' + host + (loc && loc.port == obj.port ? '' : (':' + obj.port));

return obj;
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"socket.io-parser": "2.2.5",
"has-binary": "0.1.7",
"indexof": "0.0.1",
"parseuri": "0.0.2",
"parseuri": "0.0.4",
"to-array": "0.1.3",
"backo2": "1.0.2"
},
Expand Down
20 changes: 20 additions & 0 deletions test/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,24 @@ describe('url', function(){
expect(url('http://google.com/').path).to.be('/');
});

it('works with ipv6', function(){
var parsed = url('http://[::1]');
expect(parsed.protocol).to.be('http');
expect(parsed.host).to.be('::1');
expect(parsed.port).to.be('80');
expect(parsed.id).to.be('http://[::1]:80');
});

it('works with ipv6 location', function(){
loc.protocol = 'http:';
loc.hostname = '[::1]';
loc.port = '';
loc.host = loc.hostname + ':' + loc.port;

var parsed = url(undefined, loc);
expect(parsed.protocol).to.be('http');
expect(parsed.host).to.be('::1');
expect(parsed.port).to.be('80');
expect(parsed.id).to.be('http://[::1]:80');
});
});

0 comments on commit 18be967

Please sign in to comment.