added the ability to set a host's host to false, causing the urls it creates to be relative

This commit is contained in:
Spencer Alger
2014-01-16 14:19:11 -07:00
parent eda56aa5d0
commit ab033e9698
2 changed files with 15 additions and 1 deletions

View File

@ -135,7 +135,11 @@ Host.prototype.makeUrl = function (params) {
auth = this.auth + '@';
}
return this.protocol + '://' + auth + this.host + port + path + (query ? '?' + query : '');
if (this.host) {
return this.protocol + '://' + auth + this.host + port + path + (query ? '?' + query : '');
} else {
return path + (query ? '?' + query : '');
}
};
Host.prototype.toString = function () {

View File

@ -149,6 +149,16 @@ describe('Host class', function () {
host = new Host({ host: 'italy', path: '/pie', auth: 'user:pass'});
expect(host.makeUrl()).to.be('http://user:pass@italy:9200/pie');
});
it('outputs valid relative urls when the host is empty', function () {
var host = new Host({
host: false,
path: '/path',
query: { this: 'that' }
});
expect(host + '').to.be('/path?this=that');
});
});
describe('#toString', function () {