响应匹配器
响应匹配器用于根据响应的属性(如状态码、头部等)对响应进行条件处理。
语法
响应匹配器通常用于 handle_response
块内,用于筛选需要处理的响应。例如:
handle_response {
@json header Content-Type application/json
respond @json 200
}
上例中,只有响应头 Content-Type
为 application/json
的响应会被 respond
指令处理。
标准响应匹配器
status
status <codes...>
按响应状态码匹配。支持多个状态码。
示例:
@notfound status 404
header
header <field> [<value> ...]
按响应头字段匹配。可指定字段名和可选的值。
示例:
@json header Content-Type application/json