| 1 | package integrationscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddytest/integration`/ |
| 2 | |
| 3 | import ( |
| 4 | "testingscip-go gomod github.com/golang/go/src go1.25.1 testing/" |
| 5 | |
| 6 | "github.com/caddyserver/caddy/v2/caddytestscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddytest`/" |
| 7 | ) |
| 8 | |
| 9 | func TestInterceptscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddytest/integration`/TestIntercept().(t *testingscip-go gomod github.com/golang/go/src go1.25.1 testing/.Tscip-go gomod github.com/golang/go/src go1.25.1 testing/T#) { |
| 10 | tester := caddytestscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddytest`/.NewTesterscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddytest`/NewTester().(t) |
| 11 | tester.InitServerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddytest`/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.AssertGetResponsescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddytest`/Tester#AssertGetResponse().("http://localhost:9080/intercept", 503, "I'm a combined coffee/tea pot that is temporarily out of coffee") |
| 35 | if r.Headerscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Response#Header..Getscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Header#Get().("intercepted") != "ok" { |
| 36 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Fatalf().(`header "intercepted" value is not "ok": %s`, r.Headerscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Response#Header..Getscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Header#Get().("intercepted")) |
| 37 | } |
| 38 | |
| 39 | tester.AssertGetResponsescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddytest`/Tester#AssertGetResponse().("http://localhost:9080/no-intercept", 200, "I'm not a teapot") |
| 40 | } |