Skip to content

Commit

Permalink
fix req.host when no Host is present, return undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed May 9, 2013
1 parent 28ca1b5 commit 06ead58
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/request.js
Expand Up @@ -473,6 +473,7 @@ req.__defineGetter__('host', function(){
var trustProxy = this.app.get('trust proxy');
var host = trustProxy && this.get('X-Forwarded-Host');
host = host || this.get('Host');
if (!host) return;
return host.split(':')[0];
});

Expand Down
13 changes: 13 additions & 0 deletions test/req.host.js
Expand Up @@ -17,5 +17,18 @@ describe('req', function(){
.set('Host', 'example.com')
.expect('example.com', done);
})

it('should return undefined otherwise', function(done){
var app = express();

app.use(function(req, res){
req.headers.host = null;
res.end(String(req.host));
});

request(app)
.post('/')
.expect('undefined', done);
})
})
})

0 comments on commit 06ead58

Please sign in to comment.