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:
commit
8d74cb9f5c
3 changed files with 6 additions and 6 deletions
|
@ -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];
|
||||
},
|
||||
|
||||
|
|
|
@ -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, '');
|
||||
})
|
||||
})
|
||||
|
||||
|
|
|
@ -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, '');
|
||||
})
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in a new issue