Skip to content

Commit

Permalink
Added req.host
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Jun 6, 2012
1 parent d5fde6a commit 2b90cd7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,17 @@ req.__defineGetter__('path', function(){
return parse(this).pathname;
});

/**
* Parse the "Host" header field hostname.
*
* @return {String}
* @api public
*/

req.__defineGetter__('host', function(){
return this.get('Host').split(':')[0];
});

/**
* Check if the request is fresh, aka
* Last-Modified and/or the ETag
Expand Down
18 changes: 18 additions & 0 deletions test/req.host.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

var express = require('../');

function req(ret) {
return {
get: function(){ return ret }
, __proto__: express.request
};
}

describe('req', function(){
describe('.host', function(){
it('should return hostname', function(){
req('example.com:3000').host.should.equal('example.com');
req('example.com').host.should.equal('example.com');
})
})
})

0 comments on commit 2b90cd7

Please sign in to comment.