Request Context

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:

iduint64Unique ID of the request
tlsboolWhether the request is a TLS request
remote_ipstringSource IP of the client
remote_addrstringSource IP address of the client, including port
local_ipstringGateway local IP address
local_addrstringGateway local IP address, including port
elapsedint64Time that the request has been executed (ms)
request.*objectRequest description
response.*objectResponse description

request #

The request object has the following attributes:

to_stringstringComplete HTTP request in text form
hoststringAccessed destination host name/domain name
methodstringRequest type
uristringComplete URL of request
pathstringRequest path
query_argsmapURL request parameter
usernamestringName of the user who initiates the request
passwordstringPassword of the user
headermapHeader parameter
bodystringRequest body
body_jsonobjectJSON request body object
body_lengthintRequest 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'
  "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
      - dump:
            - _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:

to_stringstringComplete HTTP response in text form
statusintRequest status code
headermapHeader parameter
content_typestringResponse body type
bodystringResponse body
body_lengthintResponse body length