Mock Response
Chute can return mock data for matched HTTP/HTTPS requests without reaching the real server. This is useful for testing, development, or blocking unwanted content with a custom response.
Mock rules are defined in the [Map Local] section (also supports [Mock] as a legacy section name).
Mutiple rules could be applied for one single request. The first mock with a matching URL pattern is used.
Inline Mock Format
For simple mock responses with inline content:
[Map Local]
^http://example\.com/api/status status=200 body={"ok":true}
^http://example\.com/blocked status=403
^http://ad\.com/.* status=200 body="<html></html>" content-type="text/html"
The inline mock rule consists of: URL regular expression, and one or more key=value response parameters.
Inline Parameters
status: Required.
status=200
The HTTP status code to return.
body: Optional.
body={"result":"mocked"}
The response body to return. If not specified, an empty body is returned.
content-type: Optional.
content-type=application/json
The Content-Type header for the mock response. Use together with body to serve proper responses.
headers: Optional.
headers=X-Custom:Value1;X-Another:Value2
Additional response headers, separated by ;.
Map Local Format
For serving mock responses from local files or with base64-encoded content:
[Map Local]
^https://example\.com/api data="/path/to/mock-response.json"
^https://example\.com/page data="/path/to/page.html" header="SGVhZGVyOiBWYWx1ZQ=="
^https://example\.com/pixel base64="R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"
Map Local Parameters
| Parameter | Description |
|---|---|
data="/path/to/file" |
File path to serve as response body. The file is read at request time. |
base64="<encoded>" |
Base64-encoded response body content. |
header="<base64>" |
Base64-encoded custom response headers (Key: Value\n format). |
At least one of
data=orbase64=must be specified.
Template Variables
When using data= or base64=, the response body supports template variable substitution:
| Variable | Replaced With |
|---|---|
{{url}} |
Full request URL path |
{{host}} |
Request hostname |
{{path}} |
Relative URL path |
{{method}} |
HTTP method |
{{ua}} |
User-Agent header value |
Example mock response file (response.json):
{
"requested_url": "{{ "{{url}}" }}",
"host": "{{ "{{host}}" }}",
"method": "{{ "{{method}}" }}"
}
Note: For HTTPS requests, MitM decryption must be enabled for the matching hostname. Mock rules for HTTPS traffic without MitM will be ignored.