withRawRequest stashes the request so Huma handlers can recover it for the auth path. Storing the request in its own derived context is the standard bridge; only headers/cookies are read downstream, so the pre-derivation request is equivalent for authentication.
(next http.Handler)
| 385 | // standard bridge; only headers/cookies are read downstream, so the |
| 386 | // pre-derivation request is equivalent for authentication. |
| 387 | func withRawRequest(next http.Handler) http.Handler { |
| 388 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 389 | ctx := context.WithValue(r.Context(), reqCtxKey{}, r) |
| 390 | next.ServeHTTP(w, r.WithContext(ctx)) |
| 391 | }) |
| 392 | } |
| 393 | |
| 394 | // RequestFromContext recovers the raw request stashed by withRawRequest. |
| 395 | func RequestFromContext(ctx context.Context) *http.Request { |