Skip to content

Commit 0287009

Browse files
authored
intercept: fix http.intercept.header.* placeholder (#6429)
1 parent f8861ca commit 0287009

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

caddytest/integration/intercept_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,23 @@ func TestIntercept(t *testing.T) {
1818
1919
localhost:9080 {
2020
respond /intercept "I'm a teapot" 408
21+
header /intercept To-Intercept ok
2122
respond /no-intercept "I'm not a teapot"
2223
2324
intercept {
2425
@teapot status 408
2526
handle_response @teapot {
27+
header /intercept intercepted {resp.header.To-Intercept}
2628
respond /intercept "I'm a combined coffee/tea pot that is temporarily out of coffee" 503
2729
}
2830
}
2931
}
3032
`, "caddyfile")
3133

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+
3339
tester.AssertGetResponse("http://localhost:9080/no-intercept", 200, "I'm not a teapot")
3440
}

modules/caddyhttp/intercept/intercept.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ type Intercept struct {
5050
//
5151
// Three new placeholders are available in this handler chain:
5252
// - `{http.intercept.status_code}` The status code from the response
53-
// - `{http.intercept.status_text}` The status text from the response
5453
// - `{http.intercept.header.*}` The headers from the response
5554
HandleResponse []caddyhttp.ResponseHandler `json:"handle_response,omitempty"`
5655

@@ -161,7 +160,7 @@ func (ir Intercept) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddy
161160

162161
// set up the replacer so that parts of the original response can be
163162
// used for routing decisions
164-
for field, value := range r.Header {
163+
for field, value := range rec.Header() {
165164
repl.Set("http.intercept.header."+field, strings.Join(value, ","))
166165
}
167166
repl.Set("http.intercept.status_code", rec.Status())

0 commit comments

Comments
 (0)