Request Context #
What Is Context #
Context is the entry for INFINI Gateway to access relevant information in the current running environment, such as the request source and configuration. You can use the _ctx
keyword to access relevant fields, for example, _ctx.request.uri
, which indicates the requested URL.
Embedded Request Context #
The embedded _ctx
context objects of an HTTP request mainly include the following:
Name | Type | Description |
---|---|---|
id | uint64 | Unique ID of the request |
tls | bool | Whether the request is a TLS request |
remote_ip | string | Source IP of the client |
remote_addr | string | Source IP address of the client, including port |
local_ip | string | Gateway local IP address |
local_addr | string | Gateway local IP address, including port |
elapsed | int64 | Time that the request has been executed (ms) |
request.* | object | Request description |
response.* | object | Response description |
request #
The request
object has the following attributes:
Name | Type | Description |
---|---|---|
to_string | string | Complete HTTP request in text form |
host | string | Accessed destination host name/domain name |
method | string | Request type |
uri | string | Complete URL of request |
path | string | Request path |
query_args | map | URL request parameter |
username | string | Name of the user who initiates the request |
password | string | Password of the user |
header | map | Header parameter |
body | string | Request body |
body_json | object | JSON request body object |
body_length | int | Request body length |
If the request body data submitted by the client is in JSON format, you can use body_json
to access the data. See the following example.
curl -u tesla:password -XGET "http://localhost:8000/medcl/_search?pretty" -H 'Content-Type: application/json' -d'
{
"query":{
"bool":{
"must":[{"match":{"name":"A"}},{"match":{"age":18}}]
}
},
"size":900,
"aggs": {
"total_num": {
"terms": {
"field": "name1",
"size": 1000000
}
}
}
}'
In JSON data, .
is used to identify the path. If the data is an array, you can use [Subscript]
to access a specified element, for example, you can use a dump
filter for debugging as follows:
- name: cache_first
filter:
- dump:
context:
- _ctx.request.body_json.size
- _ctx.request.body_json.aggs.total_num.terms.field
- _ctx.request.body_json.query.bool.must.[1].match.age
The output is as follows:
_ctx.request.body_json.size : 900
_ctx.request.body_json.aggs.total_num.terms.field : name1
_ctx.request.body_json.query.bool.must.[1].match.age : 18
response #
The response
object has the following attributes:
Name | Type | Description |
---|---|---|
to_string | string | Complete HTTP response in text form |
status | int | Request status code |
header | map | Header parameter |
content_type | string | Response body type |
body | string | Response body |
body_length | int | Response body length |