Repository: caddyserver/caddy (language: go)

Issue:
Can I use the php-fpm ping (via unix socket) as heathcheck ?
My Caddyfile (v2.6.2) :
```
localhost

route {
    root * /srv/app/public
    php_fastcgi unix//var/run/php/php-fpm.sock {
        health_uri /ping
    }
}
```

The error :

```json
"msg":"active health check panicked",
"error":"interface conversion: interface {} is nil, not http.Request
```

<details>
<summary>full log</summary>

```json
{"level":"error","ts":1672826972.5459127,"logger":"http.handlers.reverse_proxy.health_checker.active","msg":"active health check panicked","error":"interface conversion: interface {} is nil, not http.Request","stack":"goroutine 374 [running]:\nruntime/debug.Stack()\n\truntime/debug/stack.go:24 +0x65\ngithub.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy.(*Handler).doActiveHealthCheckForAllHosts.func1.1()\n\tgithub.com/caddyserver/caddy/v2@v2.6.2/modules/caddyhttp/reverseproxy/healthchecks.go:180 +0xe9\npanic({0x1a2baa0, 0xc00016a690})\n\truntime/panic.go:884 +0x212\ngithub.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy/fastcgi.Transport.buildEnv({{0x1cae8ea, 0x10}, {0xc0006fa500, 0x1, 0x4}, 0x0, 0x0, 0xb2d05e00, 0x0, 0x0, ...}, ...)\n\tgithub.com/caddyserver/caddy/v2@v2.6.2/modules/caddyhttp/reverseproxy/fastcgi/fastcgi.go:276 +0x14e5\ngithub.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy/fastcgi.Transport.RoundTrip({{0x1cae8ea, 0x10}, {0xc0006fa500, 0x1, 0x4}, 0x0, 0x0, 0xb2d05e00, 0x0, 0x0, ...}, ...)\n\tgithub.com/caddyserver/caddy/v2@v2.6.2/modules/caddyhttp/reverseproxy/fastcgi/fastcgi.go:126 +0x125\nnet/http.send(0xc000261400, {0x7fa1f2908bb0, 0xc00018b880}, {0x1c09440?, 0x4caa01?, 0x2dc30e0?})\n\tnet/http/client.go:251 +0x5f7\nnet/http.(*Client).send(0xc000860e70, 0xc000261400, {0x0?, 0xc00054f2d8?, 0x2dc30e0?})\n\tnet/http/client.go:175 +0x9b\nnet/http.(*Client).do(0xc000860e70, 0xc000261400)\n\tnet/http/client.go:715 +0x8fc\nnet/http.(*Client).Do(...)\n\tnet/http/client.go:581\ngithub.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy.(*Handler).doActiveHealthCheck(0xc0009ed860, {0x0, {0xc0009eb120, 0x4}, {0xc0009eb125, 0x19}, {0x0, 0x0}, {0x0, 0x0}}, ...)\n\tgithub.com/caddyserver/caddy/v2@v2.6.2/modules/caddyhttp/reverseproxy/healthchecks.go:295 +0x7dd\ngithub.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy.(*Handler).doActiveHealthCheckForAllHosts.func1(0xc000871380)\n\tgithub.com/caddyserver/caddy/v2@v2.6.2/modules/caddyhttp/reverseproxy/healthchecks.go:220 +0xa1e\ncreated by github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy.(*Handler).doActiveHealthCheckForAllHosts\n\tgithub.com/caddyserver/caddy/v2@v2.6.2/modules/caddyhttp/reverseproxy/healthchecks.go:175 +0x38\n"}
```

</details>

<details>
<summary>php fpm-config</summary>

```ini
[www]
listen = /var/run/php/php-fpm.sock
listen.mode = 0666
ping.path = /ping
```

</details>


Discussion / hints:

Fix patch:
diff --git a/modules/caddyhttp/reverseproxy/healthchecks.go b/modules/caddyhttp/reverseproxy/healthchecks.go
index e4c732ac7e9..c27b24f7e0f 100644
--- a/modules/caddyhttp/reverseproxy/healthchecks.go
+++ b/modules/caddyhttp/reverseproxy/healthchecks.go
@@ -266,7 +266,8 @@ func (h *Handler) doActiveHealthCheck(dialInfo DialInfo, hostAddr string, upstre
 		u.Host = net.JoinHostPort(host, portStr)
 	}
 
-	// attach dialing information to this request
+	// attach dialing information to this request, as well as context values that
+	// may be expected by handlers of this request
 	ctx := h.ctx.Context
 	ctx = context.WithValue(ctx, caddy.ReplacerCtxKey, caddy.NewReplacer())
 	ctx = context.WithValue(ctx, caddyhttp.VarsCtxKey, map[string]any{
@@ -276,6 +277,8 @@ func (h *Handler) doActiveHealthCheck(dialInfo DialInfo, hostAddr string, upstre
 	if err != nil {
 		return fmt.Errorf("making request: %v", err)
 	}
+	ctx = context.WithValue(ctx, caddyhttp.OriginalRequestCtxKey, *req)
+	req = req.WithContext(ctx)
 	for key, hdrs := range h.HealthChecks.Active.Headers {
 		if strings.ToLower(key) == "host" {
 			req.Host = h.HealthChecks.Active.Headers.Get(key)


Test patch: