diff options
author | Matthew Holt <mholt@users.noreply.github.com> | 2021-05-19 10:47:06 -0600 |
---|---|---|
committer | Matthew Holt <mholt@users.noreply.github.com> | 2021-05-19 10:47:06 -0600 |
commit | c052162203654d9fcb6f3a40b1c9b376b8e618d1 (patch) | |
tree | ed168c63505b98d378d2513b2a235742701d1db9 | |
parent | 7f26a6b3e507cef98c2d4a74384bacf53bc58f57 (diff) | |
parent | b82db994f39c6991d673a7ae9836f5454b1f9668 (diff) |
Merge branch '2.4'
-rw-r--r-- | .github/workflows/ci.yml | 2 | ||||
-rw-r--r-- | .github/workflows/cross-build.yml | 2 | ||||
-rw-r--r-- | .github/workflows/lint.yml | 2 | ||||
-rwxr-xr-x | caddyconfig/caddyfile/parse.go | 5 | ||||
-rwxr-xr-x | caddyconfig/caddyfile/parse_test.go | 4 | ||||
-rw-r--r-- | modules/caddyhttp/reverseproxy/reverseproxy.go | 15 |
6 files changed, 27 insertions, 3 deletions
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 22e7d7e..9a46b80 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,9 +6,11 @@ on: push: branches: - master + - 2.* pull_request: branches: - master + - 2.* jobs: test: diff --git a/.github/workflows/cross-build.yml b/.github/workflows/cross-build.yml index 4da0a25..dc6b8e3 100644 --- a/.github/workflows/cross-build.yml +++ b/.github/workflows/cross-build.yml @@ -4,9 +4,11 @@ on: push: branches: - master + - 2.* pull_request: branches: - master + - 2.* jobs: cross-build-test: diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index ef69150..4b4ed03 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -4,9 +4,11 @@ on: push: branches: - master + - 2.* pull_request: branches: - master + - 2.* jobs: # From https://github.com/golangci/golangci-lint-action diff --git a/caddyconfig/caddyfile/parse.go b/caddyconfig/caddyfile/parse.go index 96491bb..d870765 100755 --- a/caddyconfig/caddyfile/parse.go +++ b/caddyconfig/caddyfile/parse.go @@ -214,6 +214,11 @@ func (p *parser) addresses() error { break } + // Users commonly forget to place a space between the address and the '{' + if strings.HasSuffix(tkn, "{") { + return p.Errf("Site addresses cannot end with a curly brace: '%s' - put a space between the token and the brace", tkn) + } + if tkn != "" { // empty token possible if user typed "" // Trailing comma indicates another address will follow, which // may possibly be on the next line diff --git a/caddyconfig/caddyfile/parse_test.go b/caddyconfig/caddyfile/parse_test.go index 3c7db79..12c7139 100755 --- a/caddyconfig/caddyfile/parse_test.go +++ b/caddyconfig/caddyfile/parse_test.go @@ -160,6 +160,10 @@ func TestParseOneAndImport(t *testing.T) { "localhost", }, []int{}}, + {`localhost{ + dir1 + }`, true, []string{}, []int{}}, + {`localhost dir1 { nested { diff --git a/modules/caddyhttp/reverseproxy/reverseproxy.go b/modules/caddyhttp/reverseproxy/reverseproxy.go index ddb3ca9..671f42a 100644 --- a/modules/caddyhttp/reverseproxy/reverseproxy.go +++ b/modules/caddyhttp/reverseproxy/reverseproxy.go @@ -120,9 +120,10 @@ type Handler struct { // handler chain will not affect the health status of the // backend. // - // Two new placeholders are available in this handler chain: - // - `{http.reverse_proxy.status_code}` The status code - // - `{http.reverse_proxy.status_text}` The status text + // Three new placeholders are available in this handler chain: + // - `{http.reverse_proxy.status_code}` The status code from the response + // - `{http.reverse_proxy.status_text}` The status text from the response + // - `{http.reverse_proxy.header.*}` The headers from the response HandleResponse []caddyhttp.ResponseHandler `json:"handle_response,omitempty"` Transport http.RoundTripper `json:"-"` @@ -631,9 +632,17 @@ func (h *Handler) reverseProxy(rw http.ResponseWriter, req *http.Request, repl * if len(rh.Routes) == 0 { continue } + res.Body.Close() + + // set up the replacer so that parts of the original response can be + // used for routing decisions + for field, value := range res.Header { + repl.Set("http.reverse_proxy.header."+field, strings.Join(value, ",")) + } repl.Set("http.reverse_proxy.status_code", res.StatusCode) repl.Set("http.reverse_proxy.status_text", res.Status) + h.logger.Debug("handling response", zap.Int("handler", i)) if routeErr := rh.Routes.Compile(next).ServeHTTP(rw, req); routeErr != nil { // wrap error in roundtripSucceeded so caller knows that |