allow specifying the hostname as the host, eg. host: 'localhost'
This commit is contained in:
@ -47,9 +47,10 @@ function Host(config, globalConfig) {
|
|||||||
if (typeof config === 'string') {
|
if (typeof config === 'string') {
|
||||||
var firstColon = config.indexOf(':');
|
var firstColon = config.indexOf(':');
|
||||||
var firstSlash = config.indexOf('/');
|
var firstSlash = config.indexOf('/');
|
||||||
var portWithPath = firstColon < firstSlash;
|
var noSlash = firstSlash === -1;
|
||||||
var portNoPath = firstColon > -1 && firstSlash === -1;
|
var portNoPath = firstColon > -1 && noSlash;
|
||||||
if ((portWithPath || portNoPath) && !startsWithProtocolRE.test(config)) {
|
var portWithPath = !portNoPath && firstColon < firstSlash;
|
||||||
|
if ((noSlash || portNoPath || portWithPath) && !startsWithProtocolRE.test(config)) {
|
||||||
config = defaultProto + '//' + config;
|
config = defaultProto + '//' + config;
|
||||||
}
|
}
|
||||||
config = _.pick(url.parse(config, false, true), urlParseFields);
|
config = _.pick(url.parse(config, false, true), urlParseFields);
|
||||||
|
|||||||
@ -71,8 +71,9 @@ describe('Host class', function () {
|
|||||||
it('parses simple urls properly', function () {
|
it('parses simple urls properly', function () {
|
||||||
var host;
|
var host;
|
||||||
|
|
||||||
host = new Host('elasticsearch');
|
host = new Host('localhost');
|
||||||
expect(host.path).to.be('/elasticsearch');
|
expect(host.host).to.be('localhost');
|
||||||
|
expect(host.path).to.be('');
|
||||||
|
|
||||||
host = new Host('/elasticsearch');
|
host = new Host('/elasticsearch');
|
||||||
expect(host.path).to.be('/elasticsearch');
|
expect(host.path).to.be('/elasticsearch');
|
||||||
|
|||||||
Reference in New Issue
Block a user