Skip to content

[Response] Mock Local Responses ​

This section configures static local HTTP responses for specified URLs, returning preset content directly (plain text, 1×1 transparent GIF, Base64 binary, local file, or external resource) before establishing external connections.

Matching HTTP requests establish no upstream connections and return the configured response directly.

HTTPS requests must first be decrypted via MITM before URLs can be matched.

Syntax Declaration ​

Each line defines an independent interception rule using key-value mapping:

ini
[Response]
pattern = response_body

Component breakdown:

  • pattern: Regular expression matching the full HTTP request URL initiated by the client. Enclose in double quotes if it contains =, ,, leading/trailing whitespace, inline comment triggers (whitespace followed by # or ;), or starts with #, ;, or [.
  • =: Key-value delimiter.
  • response_body: Response body definition supporting five body forms (must be a single scalar value; an empty unquoted pattern = is rejected).

Response Body Forms & Default Behaviors ​

response_body supports five forms:

FormSyntaxBehaviorDefault Content-Type
Transparent GIFtiny-gif (bare keyword)Returns a 1×1 transparent GIF (GIF89a); quoted "tiny-gif" is treated as plain textapplication/octet-stream
Base64 binarybase64:<encoded>Decodes standard Base64 bytes (trims surrounding whitespace around <encoded>)application/octet-stream
Local filefile:<path>Reads the response body from the specified local file path (must be non-empty)None
External resourceresource:<location>Loads the response body from a local path or HTTP/HTTPS resource URLNone
Plain textAny other scalar (including "")Returns UTF-8 plain text; write "" for an empty response bodytext/plain; charset=utf-8

Text & Prefix Disambiguation ​

  • If literal plain text equals tiny-gif or starts with base64:, file:, or resource:, wrap it in double quotes (e.g., "tiny-gif", "file:note") so it is parsed as plain text rather than a typed body prefix.
  • Enclose plain text (or base64:/file:/resource: values) in double quotes "..." whenever it contains commas (,), leading/trailing whitespace, # or ; preceded by whitespace outside quotes (inline comment trigger), or starts with (, {, ), ], }, or [. Inside double quotes, escape embedded quotes as \" and backslashes as \\.
  • An empty plain-text response must be written explicitly as ""; a bare empty assignment pattern = fails validation.

Fixed Status Code & Headers ​

  • Status Code: Always returns 200 OK.
  • Headers & Capture Groups: [Response] does not support custom status codes, custom response headers, or referencing regex capture groups from pattern in the response body. To customize status codes, headers, or generate dynamic bodies, use a type=http-request script in Script.

Execution Pipeline & Rules ​

  1. Execution Phase: Local response mocking executes after URL Rewrite and Header Rewrite, but before establishing external connections.
  2. Sequential Matching & First-Match: Rules evaluate from top to bottom. Once a request matches a rule, the mock response is returned immediately and subsequent processing stops; unmatched requests proceed normally.

Configuration Examples ​

Basic Configuration ​

ini
[Response]
# 1. Plain text health check and empty body
^https?://api\.example\.com/healthz$ = ok
^https?://api\.example\.com/empty$ = ""

# 2. Plain text JSON (quoted because it contains commas)
^https?://api\.example\.com/v1/user/profile$ = "{\"code\": 0, \"data\": {\"id\": 1001, \"status\": \"active\"}}"

# 3. Literal text disambiguated from bare keyword
^https?://example\.com/literal$ = "tiny-gif"

# 4. 1×1 transparent GIF placeholder
^https?://analytics\.example\.com/pixel\.gif$ = tiny-gif

# 5. Base64 binary response
^https?://static\.example\.com/favicon\.ico$ = base64:AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

# 6. Local file and external resource responses
^https?://mock\.example\.com/config\.json$ = file:./mocks/config.json
^https?://mock\.example\.com/remote\.json$ = resource:https://example.com/mock.json