mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-06-04 22:24:28 -04:00
* implement correct Etag and If-None-Match handling, responding with 304 Not Modified if they match * introduce SessionState and State string type aliases to ensure we are using the correct fields for those, respectively * extract the SessionState from the JMAP response bodies in the groupware framework instead of having to do that in every single groupware API * use uint instead of int in some places to clarify that the values are >= 0 * trace-log how long a Session was held in cache before being evicted * add Trace-Id header handling: add to response when specified in request, and implement a custom request logger to include it as a field * implement a more compact trace-logging of all the methods and URIs that are served, to put them into a single log entry instead of creating one log entry for every URI
46 lines
970 B
Go
46 lines
970 B
Go
package middleware
|
|
|
|
import (
|
|
"net/http"
|
|
"time"
|
|
|
|
"github.com/go-chi/chi/v5/middleware"
|
|
"github.com/opencloud-eu/opencloud/pkg/log"
|
|
)
|
|
|
|
func GroupwareLogger(logger log.Logger) func(http.Handler) http.Handler {
|
|
return func(next http.Handler) http.Handler {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
level := logger.Debug()
|
|
if !level.Enabled() {
|
|
next.ServeHTTP(w, r)
|
|
return
|
|
}
|
|
|
|
start := time.Now()
|
|
wrap := middleware.NewWrapResponseWriter(w, r.ProtoMajor)
|
|
next.ServeHTTP(wrap, r)
|
|
|
|
ctx := r.Context()
|
|
|
|
requestID := middleware.GetReqID(ctx)
|
|
traceID := GetTraceID(ctx)
|
|
|
|
level.Str(log.RequestIDString, requestID)
|
|
|
|
if traceID != "" {
|
|
level.Str("traceId", traceID)
|
|
}
|
|
|
|
level.
|
|
Str("proto", r.Proto).
|
|
Str("method", r.Method).
|
|
Int("status", wrap.Status()).
|
|
Str("path", r.URL.Path).
|
|
Dur("duration", time.Since(start)).
|
|
Int("bytes", wrap.BytesWritten()).
|
|
Msg("")
|
|
})
|
|
}
|
|
}
|