aboutsummaryrefslogtreecommitdiffhomepage
path: root/caddytest/integration
diff options
context:
space:
mode:
authorEmily <[email protected]>2024-03-27 22:36:53 +0100
committerGitHub <[email protected]>2024-03-27 21:36:53 +0000
commitddb1d2c2b11b860f1e91b43d830d283d1e1363b2 (patch)
tree0f930eccdfa4b61584fce00dd6c44056e8180b3c /caddytest/integration
parent7f227b9d392cee647f05724384e1a2d6d3518faa (diff)
downloadcaddy-ddb1d2c2b11b860f1e91b43d830d283d1e1363b2.tar.gz
caddy-ddb1d2c2b11b860f1e91b43d830d283d1e1363b2.zip
caddyhttp: add http.request.local{,.host,.port} placeholder (#6182)
* caddyhttp: add `http.request.local{,.host,.port}` placeholder This is the counterpart of `http.request.remote{,.host,.port}`. `http.request.remote` operates on the remote client's address, while `http.request.local` operates on the address the connection arrived on. Take the following example: - Caddy serving on `203.0.113.1:80` - Client on `203.0.113.2` `http.request.remote.host` would return `203.0.113.2` (client IP) `http.request.local.host` would return `203.0.113.1` (server IP) `http.request.local.port` would return `80` (server port) I find this helpful for debugging setups with multiple servers and/or multiple network paths (multiple IPs, AnyIP, Anycast). Co-authored-by: networkException <[email protected]> * caddyhttp: add unit test for `http.request.local{,.host,.port}` * caddyhttp: add integration test for `http.request.local.port` * caddyhttp: fix `http.request.local.host` placeholder handling with unix sockets The implementation matches the one of `http.request.remote.host` now and returns the unix socket path (just like `http.request.local` already did) instead of an empty string. --------- Co-authored-by: networkException <[email protected]>
Diffstat (limited to 'caddytest/integration')
-rw-r--r--caddytest/integration/caddyfile_test.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/caddytest/integration/caddyfile_test.go b/caddytest/integration/caddyfile_test.go
index 628363a52..11ffc08ae 100644
--- a/caddytest/integration/caddyfile_test.go
+++ b/caddytest/integration/caddyfile_test.go
@@ -517,6 +517,25 @@ func TestUriOps(t *testing.T) {
tester.AssertGetResponse("http://localhost:9080/endpoint?foo=bar0&baz=buz&taz=nottest&changethis=val", 200, "changed=val&foo=bar0&foo=bar&key%3Dvalue=example&taz=test")
}
+// Tests the `http.request.local.port` placeholder.
+// We don't test the very similar `http.request.local.host` placeholder,
+// because depending on the host the test is running on, localhost might
+// refer to 127.0.0.1 or ::1.
+// TODO: Test each http version separately (especially http/3)
+func TestHttpRequestLocalPortPlaceholder(t *testing.T) {
+ tester := caddytest.NewTester(t)
+
+ tester.InitServer(`
+ {
+ admin localhost:2999
+ http_port 9080
+ }
+ :9080
+ respond "{http.request.local.port}"`, "caddyfile")
+
+ tester.AssertGetResponse("http://localhost:9080/", 200, "9080")
+}
+
func TestSetThenAddQueryParams(t *testing.T) {
tester := caddytest.NewTester(t)