@marcel91200 / caddy Mirror · read-only / commits / 0287009e
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 12, 10:45 UTC

intercept: fix http.intercept.header.* placeholder (#6429)

Kévin Dunglas committed Jul 3, 2024 at 16:43 UTC 0287009ee5fbe171e7a84f7d5b965992bb5488a7
2 files changed +8 -3
caddytest/integration/intercept_test.go
+7 -1
@@ -18,17 +18,23 @@ func TestIntercept(t *testing.T) {
18
19 localhost:9080 {
20 respond /intercept "I'm a teapot" 408
21 + header /intercept To-Intercept ok
22 respond /no-intercept "I'm not a teapot"
23
24 intercept {
25 @teapot status 408
26 handle_response @teapot {
27 + header /intercept intercepted {resp.header.To-Intercept}
28 respond /intercept "I'm a combined coffee/tea pot that is temporarily out of coffee" 503
29 }
30 }
31 }
32 `, "caddyfile")
33
32 - tester.AssertGetResponse("http://localhost:9080/intercept", 503, "I'm a combined coffee/tea pot that is temporarily out of coffee")
34 + r, _ := tester.AssertGetResponse("http://localhost:9080/intercept", 503, "I'm a combined coffee/tea pot that is temporarily out of coffee")
35 + if r.Header.Get("intercepted") != "ok" {
36 + t.Fatalf(`header "intercepted" value is not "ok": %s`, r.Header.Get("intercepted"))
37 + }
38 +
39 tester.AssertGetResponse("http://localhost:9080/no-intercept", 200, "I'm not a teapot")
40 }
modules/caddyhttp/intercept/intercept.go
+1 -2
@@ -50,7 +50,6 @@ type Intercept struct {
50 //
51 // Three new placeholders are available in this handler chain:
52 // - `{http.intercept.status_code}` The status code from the response
53 - // - `{http.intercept.status_text}` The status text from the response
53 // - `{http.intercept.header.*}` The headers from the response
54 HandleResponse []caddyhttp.ResponseHandler `json:"handle_response,omitempty"`
55
@@ -161,7 +160,7 @@ func (ir Intercept) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddy
160
161 // set up the replacer so that parts of the original response can be
162 // used for routing decisions
164 - for field, value := range r.Header {
163 + for field, value := range rec.Header() {
164 repl.Set("http.intercept.header."+field, strings.Join(value, ","))
165 }
166 repl.Set("http.intercept.status_code", rec.Status())