Repository: amir20/dozzle (language: go)

Issue:
Forward Proxy Auth + Healthcheck  = Unable to find remote user
**Describe the bug**
After configuring forwardAuth with authelia + traefik according to the Dozzle documentation, enable Healthcheck.

**To Reproduce**
Steps to reproduce the behavior:

Docker Compose:
```yaml
  # ...

  dozzle:
    container_name: dozzle
    image: amir20/dozzle:latest
    expose:
      - 8080
    networks:
      - traefik
    environment:
      DOZZLE_ENABLE_ACTIONS: true
      DOZZLE_AUTH_PROVIDER: forward-proxy
      DOZZLE_LEVEL: debug
    healthcheck:
      test: [ "CMD", "/dozzle", "healthcheck" ]
      interval: 3s
      timeout: 30s
      retries: 5
      start_period: 30s
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    labels:
      - reverse-proxy=traefik
      - traefik.http.routers.dozzle.rule=Host(`dozzle.example.com`)
      - traefik.http.routers.dozzle.tls=true
      - traefik.http.routers.dozzle.tls.certresolver=le
      - traefik.http.routers.dozzle.middlewares=authelia@docker
  # ...
```

logs: 
```
dozzle  | level=info msg="Dozzle version v5.8.1"
dozzle  | level=debug msg="filterArgs = {map[]}"
dozzle  | level=debug msg="Connected to local Docker Engine"
dozzle  | level=info msg="Connected to 1 Docker Engine(s)"
dozzle  | level=info msg="Accepting connections on :8080"
dozzle  | level=error msg="Unable to find remote user. Please check your proxy configuration. Expecting headers Remote-Email, Remote-User, Remote-Name."
dozzle  | level=debug msg="Dumping all headers for url //healthcheck"
dozzle  | level=debug msg="User-Agent: [Go-http-client/1.1]"
dozzle  | level=debug msg="Accept-Encoding: [gzip]"
dozzle  | level=error msg="Unable to find remote user. Please check your proxy configuration. Expecting headers Remote-Email, Remote-User, Remote-Name."
dozzle  | level=debug msg="Dumping all headers for url //healthcheck"
dozzle  | level=debug msg="User-Agent: [Go-http-client/1.1]"
dozzle  | level=debug msg="Accept-Encoding: [gzip]"
dozzle  | level=error msg="Unable to find remote user. Please check your proxy configuration. Expecting headers Remote-Email, Remote-User, Remote-Name."
```

If the health check is not enabled and only ForwardProxy is enabled, Dozzle can obtain my user information.

**Desktop (please complete the following information):**

- Docker version 24.0.7
- Version 5.8.1




Discussion / hints:
Hmm yea. That is a bug. I'll take a look. Seems like I expected user headers for health shock too. 
I was able to reproduce this. 🤔 I think I know what the problem is. 

Fix patch:
diff --git a/internal/healthcheck/http.go b/internal/healthcheck/http.go
index f23753470f54..539508c66b6a 100644
--- a/internal/healthcheck/http.go
+++ b/internal/healthcheck/http.go
@@ -3,7 +3,6 @@ package healthcheck
 import (
 	"fmt"
 	"net/http"
-	"os"
 	"strings"
 
 	log "github.com/sirupsen/logrus"
@@ -14,7 +13,16 @@ func HttpRequest(addr string, base string) error {
 		addr = "localhost" + addr
 	}
 
-	url := fmt.Sprintf("http://%s%s/healthcheck", addr, base)
+	if base == "/" {
+		base = ""
+	}
+
+	url := fmt.Sprintf("%s%s/healthcheck", addr, base)
+
+	if !strings.HasPrefix(url, "http") {
+		url = "http://" + url
+	}
+
 	log.Info("Checking health of " + url)
 	resp, err := http.Get(url)
 
@@ -24,10 +32,8 @@ func HttpRequest(addr string, base string) error {
 	defer resp.Body.Close()
 
 	if resp.StatusCode == 200 {
-		os.Exit(0)
+		return nil
 	}
 
-	os.Exit(1)
-
-	return nil
+	return fmt.Errorf("Healthcheck failed with status code %d", resp.StatusCode)
 }
diff --git a/main.go b/main.go
index 59196b8aac75..cbd76302553c 100644
--- a/main.go
+++ b/main.go
@@ -74,7 +74,7 @@ func main() {
 		if err := healthcheck.HttpRequest(args.Addr, args.Base); err != nil {
 			log.Fatal(err)
 		}
-		return
+		os.Exit(0)
 	}
 
 	if args.AuthProvider != "none" && args.AuthProvider != "forward-proxy" && args.AuthProvider != "simple" {


Test patch:
diff --git a/internal/healthcheck/http_test.go b/internal/healthcheck/http_test.go
new file mode 100644
index 000000000000..08cf9aed3878
--- /dev/null
+++ b/internal/healthcheck/http_test.go
@@ -0,0 +1,51 @@
+package healthcheck
+
+import (
+	"net/http"
+	"net/http/httptest"
+	"testing"
+)
+
+func TestHttpRequest(t *testing.T) {
+	// Test server that always responds with a status code of 200
+	server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
+		rw.WriteHeader(http.StatusOK)
+	}))
+	defer server.Close()
+
+	// Test server that always responds with a status code of 500
+	errorServer := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
+		rw.WriteHeader(http.StatusInternalServerError)
+	}))
+	defer errorServer.Close()
+
+	tests := []struct {
+		name    string
+		addr    string
+		base    string
+		wantErr bool
+	}{
+		{
+			name:    "Healthcheck OK",
+			addr:    server.URL,
+			base:    "/",
+			wantErr: false,
+		},
+		{
+			name:    "Healthcheck Fail",
+			addr:    errorServer.URL,
+			base:    "/",
+			wantErr: true,
+		},
+	}
+
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			err := HttpRequest(tt.addr, tt.base)
+
+			if (err != nil) != tt.wantErr {
+				t.Errorf("HttpRequest() error = %v, wantErr %v", err, tt.wantErr)
+			}
+		})
+	}
+}