Rule Syntax
Whistle modifies requests and responses through simple rule configurations. The basic syntax structure is as follows:
txt
pattern operation [includeFilter://pattern1 ... excludeFilter://patternN ...]Rule Composition
Each rule consists of three core components:
Match Pattern (
pattern): An expression to match request URLs, supporting various formats:- Domain matching:
www.test.com(matches all requests to this domain, including ports) - Path matching:
www.test.com/path - Regular expression:
/^https?://test\.com//i - Wildcards:
*.test.com,**.test.com/path
Whistle supports three URL types:
- Tunnel Proxy:
tunnel://domain[:port] - WebSocket:
ws[s]://domain[:port]/path/to - Regular HTTP/HTTPS:
http[s]://domain[:port]/path/to
- Domain matching:
Operation (
operation), formatted as:protocol://valueprotocol: Operation type, such as:reqHeaders: Modify request headersresHeaders: Modify response headers
value: Operation content, supporting multiple data sources:- Inline value:
reqHeaders://x-proxy-by=whistle(directly adds a request header) - Local file:
file://path/to/file - Remote resource:
https://example.com/data.json - Preset variable:
{key}(read from embedded values in Rules or Values)
- Inline value:
The
protocol://in operation can be omitted in the following two scenarios:iporip:port: Equivalent tohost://iporhost://ip:portD:\path\to,/path/to, or{key}: Equivalent tofile://D:\path\to,file:///path/to, orfile://{key}
Filter Conditions (Optional) (
includeFilter/excludeFilter)- Logical relationship: Multiple conditions use "OR" matching; matching any one condition makes it effective
- Matching scope:
- Request: URL, method (GET/POST, etc.), header fields, content, client IP
- Response: Status code, header fields, content, server IP