context_regex_replace
> Documentation > Docs > INFINI Gateway > References > Online Filter > context_regex_replace

context_regex_replace #

Description #

The context_regex_replace filter is used to replace and modify relevant information in the request context by using regular expressions.

Configuration Example #

A simple example is as follows:

flow:
  - name: test
    filter:
      - context_regex_replace:
          context: "_ctx.request.path"
          pattern: "^/"
          to: "/cluster:"
          when:
            contains:
              _ctx.request.path: /_search
      - dump:
          request: true

This example replaces curl localhost:8000/abc/_search in requests with curl localhost:8000/cluster:abc/_search.

Parameter Description #

NameTypeDescription
contextstringRequest context and corresponding key
patternstringRegular expression used for matching and replacement
tostringTarget string used for replacement

A list of context variables that can be modified is provided below:

NameTypeDescription
_ctx.request.uristringComplete URL of a request
_ctx.request.pathstringRequest path
_ctx.request.hoststringRequest host
_ctx.request.bodystringRequest body
_ctx.request.body_json.[JSON_PATH]stringPath to the JSON request object
_ctx.request.query_args.[KEY]stringURL query request parameter
_ctx.request.header.[KEY]stringRequest header information
_ctx.response.header.[KEY]stringResponse header information
_ctx.response.bodystringReturned response body
_ctx.response.body_json.[JSON_PATH]stringPath to the JSON response object