Add req.host=
This commit is contained in:
parent
612bba8d83
commit
93351bf845
3 changed files with 27 additions and 1 deletions
|
@ -60,6 +60,12 @@
|
||||||
Get host void of port number when present. Supports `X-Forwarded-Host`
|
Get host void of port number when present. Supports `X-Forwarded-Host`
|
||||||
when `app.proxy` is __true__, otherwise `Host` is used.
|
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
|
### req.type
|
||||||
|
|
||||||
Get request `Content-Type` void of parameters such as "charset".
|
Get request `Content-Type` void of parameters such as "charset".
|
||||||
|
|
|
@ -189,6 +189,17 @@ module.exports = {
|
||||||
return host.split(/\s*,\s*/)[0].split(':')[0];
|
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
|
* Check if the request is fresh, aka
|
||||||
* Last-Modified and/or the ETag
|
* Last-Modified and/or the ETag
|
||||||
|
|
|
@ -29,3 +29,12 @@ 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')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
Loading…
Reference in a new issue