Merge pull request #176 from jeromew/set_host

Add req.host=
This commit is contained in:
TJ Holowaychuk 2014-01-07 17:21:03 -08:00
commit 2de4a5561a
3 changed files with 27 additions and 1 deletions

View file

@ -60,6 +60,12 @@
Get host void of port number when present. Supports `X-Forwarded-Host`
when `app.proxy` is __true__, otherwise `Host` is used.
### req.host=
Set host to a new value. It sets the `Host` header under the hood and will
behave correctly with req.subdomains.
This can be useful for a `hostOverride()` middleware
### req.type
Get request `Content-Type` void of parameters such as "charset".

View file

@ -189,6 +189,17 @@ module.exports = {
return host.split(/\s*,\s*/)[0].split(':')[0];
},
/**
* Set the host.
*
* @param {String} str
* @api public
*/
set host(val) {
this.req.headers.host = val;
},
/**
* Check if the request is fresh, aka
* Last-Modified and/or the ETag

View file

@ -28,4 +28,13 @@ describe('req.host', function(){
})
})
})
})
})
describe('req.host=', function(){
it('should replace the host', function(){
var req = request();
req.header['host'] = 'foo.com';
req.host = 'bar.com';
req.host.should.equal('bar.com')
})
})