Merge pull request #427 from koajs/make-sure-host-return-string

make sure req.host and req.hostname return strict string
This commit is contained in:
TJ Holowaychuk 2015-04-03 10:31:37 -06:00
commit 8d74cb9f5c
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, '');
})
})