summaryrefslogtreecommitdiff
path: root/caddytest/integration/reverseproxy_test.go
diff options
context:
space:
mode:
authorelnoro <karimov.work@gmail.com>2021-07-07 08:43:45 +0500
committerGitHub <noreply@github.com>2021-07-06 23:43:45 -0400
commitd882211080cbb97f5e1cfdd87be6874eb1a9430a (patch)
treeaea979d2f35356dedd76d18f37d8e93f1cbea187 /caddytest/integration/reverseproxy_test.go
parent42e140b1b2f5fc3f602151947dc981334b338020 (diff)
reverseproxy: Keep path to unix socket as dial address (#4232)
Diffstat (limited to 'caddytest/integration/reverseproxy_test.go')
-rw-r--r--caddytest/integration/reverseproxy_test.go54
1 files changed, 54 insertions, 0 deletions
diff --git a/caddytest/integration/reverseproxy_test.go b/caddytest/integration/reverseproxy_test.go
index e838d86..e6aff87 100644
--- a/caddytest/integration/reverseproxy_test.go
+++ b/caddytest/integration/reverseproxy_test.go
@@ -436,3 +436,57 @@ func TestReverseProxyHealthCheckUnixSocket(t *testing.T) {
tester.AssertGetResponse("http://localhost:9080/", 200, "Hello, World!")
}
+
+func TestReverseProxyHealthCheckUnixSocketWithoutPort(t *testing.T) {
+ if runtime.GOOS == "windows" {
+ t.SkipNow()
+ }
+ tester := caddytest.NewTester(t)
+ f, err := ioutil.TempFile("", "*.sock")
+ if err != nil {
+ t.Errorf("failed to create TempFile: %s", err)
+ return
+ }
+ // a hack to get a file name within a valid path to use as socket
+ socketName := f.Name()
+ os.Remove(f.Name())
+
+ server := http.Server{
+ Handler: http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
+ if strings.HasPrefix(req.URL.Path, "/health") {
+ w.Write([]byte("ok"))
+ return
+ }
+ w.Write([]byte("Hello, World!"))
+ }),
+ }
+
+ unixListener, err := net.Listen("unix", socketName)
+ if err != nil {
+ t.Errorf("failed to listen on the socket: %s", err)
+ return
+ }
+ go server.Serve(unixListener)
+ t.Cleanup(func() {
+ server.Close()
+ })
+ runtime.Gosched() // Allow other goroutines to run
+
+ tester.InitServer(fmt.Sprintf(`
+ {
+ http_port 9080
+ https_port 9443
+ }
+ http://localhost:9080 {
+ reverse_proxy {
+ to unix/%s
+
+ health_path /health
+ health_interval 2s
+ health_timeout 5s
+ }
+ }
+ `, socketName), "caddyfile")
+
+ tester.AssertGetResponse("http://localhost:9080/", 200, "Hello, World!")
+}