Add req.host=

master
jeromew 2014-01-07 19:01:11 +00:00
parent 612bba8d83
commit 93351bf845
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')
})
})