make sure req.host and req.hostname return strict string

Should return empty string when no host present.
This commit is contained in:
fengmk2 2015-03-30 17:37:47 +08:00
parent 8b14b91bae
commit dd3a0fcdfa
3 changed files with 6 additions and 6 deletions

View file

@ -212,7 +212,7 @@ module.exports = {
var proxy = this.app.proxy;
var host = proxy && this.get('X-Forwarded-Host');
host = host || this.get('Host');
if (!host) return;
if (!host) return '';
return host.split(/\s*,\s*/)[0];
},
@ -227,7 +227,7 @@ module.exports = {
get hostname() {
var host = this.host;
if (!host) return;
if (!host) return '';
return host.split(':')[0];
},

View file

@ -10,9 +10,9 @@ describe('req.host', function(){
})
describe('with no host present', function(){
it('should return null', function(){
it('should return ""', function(){
var req = request();
assert(null == req.host);
assert.equal(req.host, '');
})
})

View file

@ -10,9 +10,9 @@ describe('req.hostname', function(){
})
describe('with no host present', function(){
it('should return null', function(){
it('should return ""', function(){
var req = request();
assert(null == req.hostname);
assert.equal(req.hostname, '');
})
})