make sure req.host and req.hostname return strict string
Should return empty string when no host present.
This commit is contained in:
parent
8b14b91bae
commit
dd3a0fcdfa
3 changed files with 6 additions and 6 deletions
|
@ -212,7 +212,7 @@ module.exports = {
|
||||||
var proxy = this.app.proxy;
|
var proxy = this.app.proxy;
|
||||||
var host = proxy && this.get('X-Forwarded-Host');
|
var host = proxy && this.get('X-Forwarded-Host');
|
||||||
host = host || this.get('Host');
|
host = host || this.get('Host');
|
||||||
if (!host) return;
|
if (!host) return '';
|
||||||
return host.split(/\s*,\s*/)[0];
|
return host.split(/\s*,\s*/)[0];
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -227,7 +227,7 @@ module.exports = {
|
||||||
|
|
||||||
get hostname() {
|
get hostname() {
|
||||||
var host = this.host;
|
var host = this.host;
|
||||||
if (!host) return;
|
if (!host) return '';
|
||||||
return host.split(':')[0];
|
return host.split(':')[0];
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -10,9 +10,9 @@ describe('req.host', function(){
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('with no host present', function(){
|
describe('with no host present', function(){
|
||||||
it('should return null', function(){
|
it('should return ""', function(){
|
||||||
var req = request();
|
var req = request();
|
||||||
assert(null == req.host);
|
assert.equal(req.host, '');
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -10,9 +10,9 @@ describe('req.hostname', function(){
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('with no host present', function(){
|
describe('with no host present', function(){
|
||||||
it('should return null', function(){
|
it('should return ""', function(){
|
||||||
var req = request();
|
var req = request();
|
||||||
assert(null == req.hostname);
|
assert.equal(req.hostname, '');
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue