Skip to content

Commit

Permalink
fix(address-parsing): support basic hostnames in address parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
mbroadst committed Mar 4, 2016
1 parent 9d42b3e commit 757f0d2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/policies/default_policy.js
Expand Up @@ -107,9 +107,11 @@ module.exports = {
parseAddress: function(address) {
var parsedAddress = url.parse(address);
var result = {
host: parsedAddress.hostname,
path: parsedAddress.path || '/',
protocol: parsedAddress.protocol.slice(0, -1).toLowerCase() || 'amqp',
host: parsedAddress.hostname || parsedAddress.href,
path: (parsedAddress.path && parsedAddress.path !== address) ?
parsedAddress.path : '/',
protocol: parsedAddress.protocol ?
parsedAddress.protocol.slice(0, -1).toLowerCase() : 'amqp',
href: parsedAddress.href
};

Expand All @@ -122,7 +124,7 @@ module.exports = {
}
}

result.rootUri = parsedAddress.protocol + '//';
result.rootUri = result.protocol + '://';
if (!!parsedAddress.auth) {
result.rootUri += parsedAddress.auth + '@';

Expand Down
18 changes: 18 additions & 0 deletions test/unit/address.test.js
Expand Up @@ -8,6 +8,24 @@ var DefaultPolicy = require('../../lib/policies/default_policy'),
describe('Address Parsing', function() {
describe('default', function() {
[
{
description: 'a plain host (1)',
address: 'localhost',
expected: {
protocol: 'amqp', host: 'localhost', port: 5672, path: '/',
rootUri: 'amqp://localhost:5672',
href: 'localhost'
}
},
{
description: 'a plain host (2)',
address: '192.168.1.9',
expected: {
protocol: 'amqp', host: '192.168.1.9', port: 5672, path: '/',
rootUri: 'amqp://192.168.1.9:5672',
href: '192.168.1.9'
}
},
{
description: 'amqp no port no route',
address: 'amqp://127.0.0.1',
Expand Down

0 comments on commit 757f0d2

Please sign in to comment.