Built-in Values
Built-in Values
Section titled “Built-in Values”HTTP Requests
Section titled “HTTP Requests”HTTP requests are parsed and matched with a base template. The base template defines the following variables:
Variable | Note |
---|---|
method | The http request method, e.g., GET , POST , PUT |
origin | The request origin, including the schema and domain |
pathname | The request path, up to the ?search part |
search | The request search params, as an object largely compatible with URLSearchParams |
headers | The request headers, as an object largely compatible with Headers |
body | The request body, usually as a string . |
In the templates, ANY https://....
declares a request with no request method (which matches any),
and ANY //
can be used to define a request with no origin to match anything. These forms are useful
for writing mixin requests.
In the pathname, {{variable}}
will have a default regex of /[^/]+/
, i.e., one or more non-slash characters,
while the hint ...
as in {{...variable}}
matches /.*/
(anything).
Similarly, in the origin, {{variable}}
matches /[^.]+/
(one or more non-dots), and {{...variable}}
matches /.*/
(anything).
HTTP Responses
Section titled “HTTP Responses”HTTP responses are parsed and matched with a base template. The base template defines the following variables:
Variable | Note |
---|---|
status | The response status |
headers | The response headers, as an object largely compatible with Headers |
body | The response body, usually as a string . |
Http Meta-Headers
Section titled “Http Meta-Headers”There are two meta-headers, body
and resolve
POST https://example.com/...[body]: plain[resolve]: localhost
The body
meta header
Section titled “The body meta header”body
overrides the normal guess for how to parse the request or response body. Options are
[body] | behavior |
---|---|
plain | plain text, supports {{interpolation}} |
raw | raw text |
json | JSON or scripted templates |
form | url-encoded form data, supports {{interpolation}} |
The resolve
meta header
Section titled “The resolve meta header”The [resolve]
meta header specifies the DNS name or IP address to connect to.
This overrides DNS only, the host header and SNI will still be based on the origin of the request.
This mimics curl
’s --resolve
option.