Permalink
Browse files

Added `req.host`

  • Loading branch information...
1 parent d5fde6a commit 2b90cd7d51a49a52f0b36ff206c13c734690af78 TJ Holowaychuk committed Jun 6, 2012
Showing with 29 additions and 0 deletions.
  1. +11 −0 lib/request.js
  2. +18 −0 test/req.host.js
View
@@ -369,6 +369,17 @@ req.__defineGetter__('path', function(){
});
/**
+ * 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
* still match.
View
@@ -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.