httplog icon indicating copy to clipboard operation
httplog copied to clipboard

Logged request URLs contain duplicate host/port (e.g., "http://example.comhttp://example.com/api")

Open seb-schulz opened this issue 5 months ago • 2 comments

Problem: When using httplog with structured logging (e.g., SchemaGCP), the requestUrl field in logs incorrectly duplicates the host and port:

{
  "httpRequest": {
    "requestUrl": "http://localhost:8080http://localhost:8080/api/users",  // ❌ Duplicated
    "requestMethod": "GET",
    "requestPath": "/api/users"
  }
}

Expected:

{
  "httpRequest": {
    "requestUrl": "http://localhost:8080/api/users",  // ✅ Correct
    "requestMethod": "GET",
    "requestPath": "/api/users"
  }
}

How to Reproduce:

var requestLogger = httplog.RequestLogger(slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{
	Level: slog.LevelInfo,
})), &httplog.Options{
	Level:         slog.LevelInfo,
	RecoverPanics: true,
	Schema:        httplog.SchemaGCP,
})
  1. Use the logger middleware in your application.
  2. Make a request to any endpoint.
  3. Check the logs: The requestUrl field will show the host/port twice.

seb-schulz avatar Sep 18 '25 09:09 seb-schulz