requestID middleware honors a caller-supplied X-Request-Id (so a trace id can flow across services) and otherwise mints one, then stashes it in the request context and sets it on the response header. Because it runs at the chi root it covers both the new Huma surface and the legacy fallback — every
(next http.Handler)
| 50 | // chi root it covers both the new Huma surface and the legacy fallback — |
| 51 | // every response carries a request id. |
| 52 | func requestID(next http.Handler) http.Handler { |
| 53 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 54 | id := r.Header.Get(requestIDHeader) |
| 55 | if id == "" { |
| 56 | id = newRequestID() |
| 57 | } |
| 58 | w.Header().Set(requestIDHeader, id) |
| 59 | ctx := context.WithValue(r.Context(), requestIDKey, id) |
| 60 | next.ServeHTTP(w, r.WithContext(ctx)) |
| 61 | }) |
| 62 | } |
| 63 | |
| 64 | // authChallenge injects the RFC 6750 §3 WWW-Authenticate header on any 401 |
| 65 | // response. Every 401 on this Bearer-accepting surface must advertise the |
nothing calls this directly
no test coverage detected