MCPcopy Create free account
hub / github.com/Mnexa-AI/e2a / requestID

Function requestID

internal/httpapi/middleware.go:52–62  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

50// chi root it covers both the new Huma surface and the legacy fallback —
51// every response carries a request id.
52func 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

Callers

nothing calls this directly

Calls 3

newRequestIDFunction · 0.85
GetMethod · 0.65
ServeHTTPMethod · 0.45

Tested by

no test coverage detected