A middleware right after chi's RequestID sets the X-Request-Id response header from the ID RequestID stored in the request context, so every response carries it and a client can quote it when reporting a problem. README "Routes" says where the ID comes from. Model: opus-5-5
This commit is contained in:
@@ -115,6 +115,20 @@ func (s *Middleware) RateLimit(
|
||||
})
|
||||
}
|
||||
|
||||
// RequestIDResponseHeader returns a middleware that sends the request's ID as
|
||||
// the X-Request-Id response header, so a client can quote it when reporting a
|
||||
// problem. The ID is the one chi's RequestID middleware stored in the request
|
||||
// context, so RequestID must run first.
|
||||
func (s *Middleware) RequestIDResponseHeader() func(http.Handler) http.Handler {
|
||||
return func(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set(middleware.RequestIDHeader,
|
||||
middleware.GetReqID(r.Context()))
|
||||
next.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
type loggingResponseWriter struct {
|
||||
http.ResponseWriter
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ func (s *Server) SetupRoutes() {
|
||||
|
||||
s.router.Use(middleware.Recoverer)
|
||||
s.router.Use(middleware.RequestID)
|
||||
s.router.Use(s.mw.RequestIDResponseHeader())
|
||||
s.router.Use(s.mw.ClientIP())
|
||||
s.router.Use(s.mw.SecurityHeaders())
|
||||
s.router.Use(s.mw.Logging())
|
||||
|
||||
Reference in New Issue
Block a user