added the ability to set a host's host to false, causing the urls it creates to be relative
This commit is contained in:
@ -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 () {
|
||||
|
||||
@ -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 () {
|
||||
|
||||
Reference in New Issue
Block a user