(t *testing.T)
| 7 | ) |
| 8 | |
| 9 | func TestIntercept(t *testing.T) { |
| 10 | tester := caddytest.NewTester(t) |
| 11 | tester.InitServer(`{ |
| 12 | skip_install_trust |
| 13 | admin localhost:2999 |
| 14 | http_port 9080 |
| 15 | https_port 9443 |
| 16 | grace_period 1ns |
| 17 | } |
| 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 | |
| 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 | } |
nothing calls this directly
no test coverage detected