diff --git a/lib/request.js b/lib/request.js index e66bf9f..84f8cfc 100644 --- a/lib/request.js +++ b/lib/request.js @@ -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]; }, diff --git a/test/request/host.js b/test/request/host.js index 18d63e5..303cd86 100644 --- a/test/request/host.js +++ b/test/request/host.js @@ -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, ''); }) }) diff --git a/test/request/hostname.js b/test/request/hostname.js index 43ec62c..5014666 100644 --- a/test/request/hostname.js +++ b/test/request/hostname.js @@ -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, ''); }) })