Request

Request

new Request()

继承 koa 的 Request

Source:
See:

Members

acceptJSON :Boolean

detect if response should be json

  1. url path ends with .json
  2. response type is set to json
  3. detect by request accept header
Since:
  • 1.0.0
Source:

Request header

Source:

headers :Object

Request headers

Source:

host :String

Parse the "Host" header field host and support X-Forwarded-Host when a proxy is enabled.

Source:
Example
ip + port
```js
this.request.host
=> '127.0.0.1:7001'
```
or domain
```js
this.request.host
=> 'demo.eggjs.org'
```

ip :String

Request remote IPv4 address

Source:
Example
```js
this.request.ip
=> '127.0.0.1'
=> '111.10.2.1'
```

ips :Array

Get all pass through ip addresses from the request. Enable only on app.config.proxy = true

Source:
Example
```js
this.request.ips
=> ['100.23.1.2', '201.10.10.2']
```

method :String

Request HTTP Method, 比如: GET, POST, PATCH, PUT, DELETE

Source:

originalUrl :String

完整的请求 URL 地址

Source:

path :String

完整的请求 URL 地址,的路径部分(不包含域名)

Source:

protocol :String

Source:
Example
```js
this.request.protocol
=> 'https'
```

queries :Array

get params pass by querystring, all value are Array type. Request#query

Source:
Example
```js
GET http://127.0.0.1:7001?a=b&a=c&o[foo]=bar&b[]=1&b[]=2&e=val
this.queries
=>
{
  "a": ["b", "c"],
  "o[foo]": ["bar"],
  "b[]": ["1", "2"],
  "e": ["val"]
}
```

query :Object

get params pass by querystring, all value are String type.

Source:
Example
```js
GET http://127.0.0.1:7001?name=Foo&age=20&age=21
this.query
=> { 'name': 'Foo', 'age': 20 }

GET http://127.0.0.1:7001?a=b&a=c&o[foo]=bar&b[]=1&b[]=2&e=val
this.query
=>
{
  "a": "b",
  "o[foo]": "bar",
  "b[]": "1",
  "e": "val"
}
```

querystring :String

请求的 GET 参数

Source:
Example
GET http://127.0.0.1:7001?name=Foo&age=20
```js
this.request.querystring
=> 'name=Foo&age=20'
```

url :String

完整的请求 URL 地址

Source:

Methods

query(obj) → {void}

Set query-string as an object.

Parameters:
Name Type Description
obj Object

set querystring and query object for request.

Source: