See the [requests concepts](../concepts/concepts.md#requests) for details.
The context object (`ctx`) contains all the requests related informations. They are accessible through `ctx.request`, from [controllers](controllers.md) and [policies](policies.md).
## API Reference
For more information, please refer to the [Koa request documentation](http://koajs.com/#request).
### request.header
Request header object.
### request.header=
Set request header object.
### request.headers
Request header object. Alias as `request.header`.
### request.headers=
Set request header object. Alias as `request.header=`.
### request.method
Request method.
### request.method=
Set request method, useful for implementing middleware
such as `methodOverride()`.
### request.length
Return request Content-Length as a number when present, or `undefined`.
### request.url
Get request URL.
### request.url=
Set request URL, useful for url rewrites.
### request.originalUrl
Get request original URL.
### request.origin
Get origin of URL, include `protocol` and `host`.
```js
ctx.request.origin
// => http://example.com
```
### request.href
Get full request URL, include `protocol`, `host` and `url`.
```js
ctx.request.href;
// => http://example.com/foo/bar?q=1
```
### request.path
Get request pathname.
### request.path=
Set request pathname and retain query-string when present.
### request.querystring
Get raw query string void of `?`.
### request.querystring=
Set raw query string.
### request.search
Get raw query string with the `?`.
### request.search=
Set raw query string.
### request.host
Get host (hostname:port) when present. Supports `X-Forwarded-Host`
when `app.proxy` is __true__, otherwise `Host` is used.
### request.hostname
Get hostname when present. Supports `X-Forwarded-Host`
when `app.proxy` is __true__, otherwise `Host` is used.
Set query-string to the given object. Note that this
setter does _not_ support nested objects.
```js
ctx.query = { next: '/login' };
```
### request.fresh
Check if a request cache is "fresh", aka the contents have not changed. This
method is for cache negotiation between `If-None-Match` / `ETag`, and `If-Modified-Since` and `Last-Modified`. It should be referenced after setting one or more of these response headers.
Koa's `request` object includes helpful content negotiation utilities powered by [accepts](http://github.com/expressjs/accepts) and [negotiator](https://github.com/federomero/negotiator). These utilities are:
-`request.accepts(types)`
-`request.acceptsEncodings(types)`
-`request.acceptsCharsets(charsets)`
-`request.acceptsLanguages(langs)`
If no types are supplied, __all__ acceptable types are returned.
If multiple types are supplied, the best match will be returned. If no matches are found, a `false` is returned, and you should send a `406 "Not Acceptable"` response to the client.
In the case of missing accept headers where any type is acceptable, the first type will be returned. Thus, the order of types you supply is important.
### request.accepts(types)
Check if the given `type(s)` is acceptable, returning the best match when true, otherwise `false`. The `type` value may be one or more mime type string
such as "application/json", the extension name
such as "json", or an array `["json", "html", "text/plain"]`.
```js
// Accept: text/html
ctx.accepts('html');
// => "html"
// Accept: text/*, application/json
ctx.accepts('html');
// => "html"
ctx.accepts('text/html');
// => "text/html"
ctx.accepts('json', 'text');
// => "json"
ctx.accepts('application/json');
// => "application/json"
// Accept: text/*, application/json
ctx.accepts('image/png');
ctx.accepts('png');
// => false
// Accept: text/*;q=.5, application/json
ctx.accepts(['html', 'json']);
ctx.accepts('html', 'json');
// => "json"
// No Accept header
ctx.accepts('html', 'json');
// => "html"
ctx.accepts('json', 'html');
// => "json"
```
You may call `ctx.accepts()` as many times as you like,
Check if `encodings` are acceptable, returning the best match when true, otherwise `false`. Note that you should include `identity` as one of the encodings!
When no arguments are given all accepted encodings
are returned as an array:
```js
// Accept-Encoding: gzip, deflate
ctx.acceptsEncodings();
// => ["gzip", "deflate", "identity"]
```
Note that the `identity` encoding (which means no encoding) could be unacceptable if the client explicitly sends `identity;q=0`. Although this is an edge case, you should still handle the case where this method returns `false`.