Rules and Modifiers

Understanding matching rules, request/response modifiers, and execution order

Overview

Rules and modifiers work together to conditionally modify requests and responses. Rules determine when to apply a configuration (matching on path, method, headers, status codes, IP, etc.), while modifiers define what changes to make (add/remove headers, rewrite paths, modify bodies).

Rules support AND/OR logic: multiple conditions within a single rule are ANDed together, while multiple rules in an array use OR logic (any match passes).

Capabilities

  • Rules can be used in 5 places: request modifiers, response modifiers, transforms, forward rules, and load balancer targets
  • AND logic within a rule, OR logic across rules in an array
  • Match on path, method, headers, IP/CIDR, status codes, content types, CEL expressions, and Lua scripts
  • Request modifiers: set/add/remove headers, rewrite path, modify query, change body
  • Response modifiers: set/add/remove headers, modify status code, change body

Execution Order

The request processing pipeline follows this sequence:

  1. Request arrives and hostname is resolved
  2. Forwarding rules evaluated (route to different config if matched)
  3. Request rules evaluated (accept or reject request)
  4. Policies enforced (WAF, rate limiting, IP filtering, etc.)
  5. Authentication validated
  6. Request modifiers applied (with their rules evaluated per modifier)
  7. Action executed (proxy, redirect, static, etc.)
  8. Response modifiers applied (with their rules evaluated per modifier)
  9. Transforms applied (with their rules evaluated per transform)

Example

Add a header only for POST requests to API paths:

proxy:
  http_bind_port: 8080

origins:
  "api.example.com":
    action:
      type: proxy
      url: https://test.sbproxy.dev
    request_modifiers:
      - rules:
          - path:
              contains: /api
            methods:
              - POST
        headers:
          set:
            X-API-Version: "2.0"

Test it:

curl -H "Host: api.example.com" http://localhost:8080/