2024-05-13 20:38:18 +03:00
|
|
|
package integration
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/caddyserver/caddy/v2/caddytest"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestIntercept(t *testing.T) {
|
|
|
|
tester := caddytest.NewTester(t)
|
|
|
|
tester.InitServer(`{
|
|
|
|
skip_install_trust
|
|
|
|
admin localhost:2999
|
|
|
|
http_port 9080
|
|
|
|
https_port 9443
|
|
|
|
grace_period 1ns
|
|
|
|
}
|
|
|
|
|
|
|
|
localhost:9080 {
|
|
|
|
respond /intercept "I'm a teapot" 408
|
2024-07-03 17:43:13 +03:00
|
|
|
header /intercept To-Intercept ok
|
2024-05-13 20:38:18 +03:00
|
|
|
respond /no-intercept "I'm not a teapot"
|
|
|
|
|
|
|
|
intercept {
|
|
|
|
@teapot status 408
|
|
|
|
handle_response @teapot {
|
2024-07-03 17:43:13 +03:00
|
|
|
header /intercept intercepted {resp.header.To-Intercept}
|
2024-05-13 20:38:18 +03:00
|
|
|
respond /intercept "I'm a combined coffee/tea pot that is temporarily out of coffee" 503
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`, "caddyfile")
|
|
|
|
|
2024-07-03 17:43:13 +03:00
|
|
|
r, _ := tester.AssertGetResponse("http://localhost:9080/intercept", 503, "I'm a combined coffee/tea pot that is temporarily out of coffee")
|
|
|
|
if r.Header.Get("intercepted") != "ok" {
|
|
|
|
t.Fatalf(`header "intercepted" value is not "ok": %s`, r.Header.Get("intercepted"))
|
|
|
|
}
|
|
|
|
|
2024-05-13 20:38:18 +03:00
|
|
|
tester.AssertGetResponse("http://localhost:9080/no-intercept", 200, "I'm not a teapot")
|
|
|
|
}
|