Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added `req.host`

  • Loading branch information...
commit 2b90cd7d51a49a52f0b36ff206c13c734690af78 1 parent d5fde6a
@tj tj authored
Showing with 29 additions and 0 deletions.
  1. +11 −0 lib/request.js
  2. +18 −0 test/req.host.js
View
11 lib/request.js
@@ -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
18 test/req.host.js
@@ -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');
+ })
+ })
+})
Please sign in to comment.
Something went wrong with that request. Please try again.