src/docs/markdown/caddyfile/response-matchers.md
Response matchers can be used to filter (or classify) responses by specific criteria.
These typically only appear as config inside of certain other directives, to make decisions on the response as it's being written out to the client.
If a directive accepts response matchers, the usage is represented as either [<response_matcher>] or [<inline_response_matcher>] in the syntax documentation.
@name.status 200.@name {
status <code...>
header <field> [<value>]
}
If only one aspect of the response is relevant to the directive, you can put the name and the criteria on the same line:
@name status <code...>
... {
status <code...>
header <field> [<value>]
}
... status <code...>
... header <field> [<value>]
status <code...>
By HTTP status code.
2xx and 3xx, which match against all status codes in the range of 200-299 and 300-399, respectively.@success status 2xx
header <field> [<value>]
By response header fields.
<field> is the name of the HTTP header field to check.
!, the field must not exist to match (omit value arg).<value> is the value the field must have to match.
*, it performs a fast suffix match (appears at the end).*, it performs a fast prefix match (appears at the start).*, it performs a fast substring match (appears anywhere).Different header fields within the same set are AND-ed. Multiple values per field are OR'ed.
Note that header fields may be repeated and have different values. Backend applications MUST consider that header field values are arrays, not singular values, and Caddy does not interpret meaning in such quandaries.
Match responses with the Foo header containing the value bar:
@upgrade header Foo *bar*
Match responses with the Foo header having the value bar OR baz:
@foo {
header Foo bar
header Foo baz
}
Match responses that do not have the Foo header field at all:
@not_foo header !Foo