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 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];
}, },

View File

@ -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, '');
}) })
}) })

View File

@ -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, '');
}) })
}) })