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:
- Request arrives and hostname is resolved
- Forwarding rules evaluated (route to different config if matched)
- Request rules evaluated (accept or reject request)
- Policies enforced (WAF, rate limiting, IP filtering, etc.)
- Authentication validated
- Request modifiers applied (with their rules evaluated per modifier)
- Action executed (proxy, redirect, static, etc.)
- Response modifiers applied (with their rules evaluated per modifier)
- 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/