diff --git a/docs/api/context.md b/docs/api/context.md index dfc6f38..0c9582f 100644 --- a/docs/api/context.md +++ b/docs/api/context.md @@ -124,7 +124,7 @@ throw err; - `ctx.querystring` - `ctx.querystring=` - `ctx.host` - - `ctx.host=` + - `ctx.hostname` - `ctx.fresh` - `ctx.stale` - `ctx.socket` diff --git a/docs/api/request.md b/docs/api/request.md index 065d29b..a4508ca 100644 --- a/docs/api/request.md +++ b/docs/api/request.md @@ -57,12 +57,12 @@ ### req.host - Get host void of port number when present. Supports `X-Forwarded-Host` + Get host(hostname:port) when present. Supports `X-Forwarded-Host` when `app.proxy` is __true__, otherwise `Host` is used. -### req.host= - - Set the `Host` header field to a new value. +### req.hostname + Get hostname when present. Supports `X-Forwarded-Host` + when `app.proxy` is __true__, otherwise `Host` is used. ### req.type diff --git a/lib/context.js b/lib/context.js index 23b131e..1e2f0b7 100644 --- a/lib/context.js +++ b/lib/context.js @@ -162,10 +162,10 @@ delegate(proto, 'request') .access('method') .access('query') .access('path') - .access('host') .access('url') .getter('subdomains') .getter('protocol') + .getter('host') .getter('hostname') .getter('header') .getter('secure') diff --git a/lib/request.js b/lib/request.js index 48c7b6a..4491c19 100644 --- a/lib/request.js +++ b/lib/request.js @@ -188,17 +188,6 @@ module.exports = { return host.split(/\s*,\s*/)[0]; }, - /** - * Set the host. - * - * @param {String} str - * @api public - */ - - set host(val) { - this.req.headers.host = val; - }, - /** * Parse the "Host" header field hostname * and support X-Forwarded-Host when a diff --git a/test/request/host.js b/test/request/host.js index 7b3a0e9..2bbeb0c 100644 --- a/test/request/host.js +++ b/test/request/host.js @@ -14,7 +14,7 @@ describe('req.host', function(){ var req = request(); req.header['x-forwarded-host'] = 'bar.com'; req.header['host'] = 'foo.com'; - req.host.should.equal('foo.com') + req.host.should.equal('foo.com'); }) }) @@ -24,17 +24,8 @@ describe('req.host', function(){ req.app.proxy = true; req.header['x-forwarded-host'] = 'bar.com, baz.com'; req.header['host'] = 'foo.com'; - req.host.should.equal('bar.com') + req.host.should.equal('bar.com'); }) }) }) }) - -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') - }) -})