Improve HTTP server.
Linting and tests / Linting (push) Successful in 19s
Linting and tests / Tests (push) Successful in 17s

This commit is contained in:
2026-06-10 10:39:12 +05:00
parent 0db14666d0
commit 7cc06a9ef1
4 changed files with 21 additions and 15 deletions
@@ -3,22 +3,24 @@ package httpserver
import (
"fmt"
"net/http"
"time"
"github.com/felixge/httpsnoop"
)
func (h *httpServer) requestLoggingMiddleware(fn http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
startTime := time.Now()
fn(w, r)
return func(w http.ResponseWriter, req *http.Request) {
metrics := httpsnoop.CaptureMetrics(fn, w, req)
h.logger.Info(
"HTTP request.",
"remote_addr", r.RemoteAddr,
"user_agent", r.UserAgent(),
"host", r.Host,
"path", fmt.Sprintf("%s %s", r.Method, r.RequestURI),
"duration", time.Since(startTime),
"remote_addr", req.RemoteAddr,
"user_agent", req.UserAgent(),
"host", req.Host,
"path", fmt.Sprintf("%s %s", req.Method, req.RequestURI),
"duration", metrics.Duration,
"req_size", req.ContentLength,
"resp_size", metrics.Written,
"http_code", metrics.Code,
)
}
}