Merge pull request #6715 from owncloud/requestID-response
add request id to all responses
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
Enhancement: Add X-Request-Id to all responses
|
||||||
|
|
||||||
|
We added the X-Request-Id to all responses to increase the debuggability of the platform.
|
||||||
|
|
||||||
|
https://github.com/owncloud/ocis/pull/6715
|
||||||
@@ -13,12 +13,15 @@ func AccessLog(logger log.Logger) func(http.Handler) http.Handler {
|
|||||||
return func(next http.Handler) http.Handler {
|
return func(next http.Handler) http.Handler {
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
|
requestID := middleware.GetReqID(r.Context())
|
||||||
|
// add Request Id to all responses
|
||||||
|
w.Header().Set(middleware.RequestIDHeader, requestID)
|
||||||
wrap := middleware.NewWrapResponseWriter(w, r.ProtoMajor)
|
wrap := middleware.NewWrapResponseWriter(w, r.ProtoMajor)
|
||||||
next.ServeHTTP(wrap, r)
|
next.ServeHTTP(wrap, r)
|
||||||
|
|
||||||
logger.Info().
|
logger.Info().
|
||||||
Str("proto", r.Proto).
|
Str("proto", r.Proto).
|
||||||
Str(log.RequestIDString, middleware.GetReqID(r.Context())).
|
Str(log.RequestIDString, requestID).
|
||||||
Str("remote-addr", r.RemoteAddr).
|
Str("remote-addr", r.RemoteAddr).
|
||||||
Str("method", r.Method).
|
Str("method", r.Method).
|
||||||
Int("status", wrap.Status()).
|
Int("status", wrap.Status()).
|
||||||
|
|||||||
Reference in New Issue
Block a user