mirror of
https://github.com/caddyserver/caddy.git
synced 2025-10-19 15:53:17 +00:00
* reverseproxy: Add `handle_response` blocks to `reverse_proxy` (#3710) * reverseproxy: complete handle_response test * reverseproxy: Change handle_response matchers to use named matchers reverseproxy: Add support for changing status code * fastcgi: Remove obsolete TODO We already have d.Err("transport already specified") in the reverse_proxy parsing code which covers this case * reverseproxy: Fix support for "4xx" type status codes * Apply suggestions from code review Co-authored-by: Matt Holt <mholt@users.noreply.github.com> * caddyhttp: Reorganize response matchers * reverseproxy: Reintroduce caddyfile.Unmarshaler * reverseproxy: Add comment mentioning Finalize should be called Co-authored-by: Maxime Soulé <btik-git@scoubidou.com> Co-authored-by: Matt Holt <mholt@users.noreply.github.com>
This commit is contained in:
parent
e6f6d3a476
commit
e4a22de9d1
10 changed files with 635 additions and 253 deletions
|
@ -971,40 +971,6 @@ func (mre *MatchRegexp) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// ResponseMatcher is a type which can determine if an
|
||||
// HTTP response matches some criteria.
|
||||
type ResponseMatcher struct {
|
||||
// If set, one of these status codes would be required.
|
||||
// A one-digit status can be used to represent all codes
|
||||
// in that class (e.g. 3 for all 3xx codes).
|
||||
StatusCode []int `json:"status_code,omitempty"`
|
||||
|
||||
// If set, each header specified must be one of the
|
||||
// specified values, with the same logic used by the
|
||||
// request header matcher.
|
||||
Headers http.Header `json:"headers,omitempty"`
|
||||
}
|
||||
|
||||
// Match returns true if the given statusCode and hdr match rm.
|
||||
func (rm ResponseMatcher) Match(statusCode int, hdr http.Header) bool {
|
||||
if !rm.matchStatusCode(statusCode) {
|
||||
return false
|
||||
}
|
||||
return matchHeaders(hdr, rm.Headers, "", nil)
|
||||
}
|
||||
|
||||
func (rm ResponseMatcher) matchStatusCode(statusCode int) bool {
|
||||
if rm.StatusCode == nil {
|
||||
return true
|
||||
}
|
||||
for _, code := range rm.StatusCode {
|
||||
if StatusCodeMatches(statusCode, code) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
var wordRE = regexp.MustCompile(`\w+`)
|
||||
|
||||
const regexpPlaceholderPrefix = "http.regexp"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue