diff --git a/services/collaboration/pkg/connector/httpadapter.go b/services/collaboration/pkg/connector/httpadapter.go index 201ee769e..4075722b4 100644 --- a/services/collaboration/pkg/connector/httpadapter.go +++ b/services/collaboration/pkg/connector/httpadapter.go @@ -65,6 +65,7 @@ func (h *HttpAdapter) GetLock(w http.ResponseWriter, r *http.Request) { return } w.Header().Set(HeaderWopiLock, lockID) + w.WriteHeader(http.StatusOK) } // Lock adapts the "Lock" and "UnlockAndRelock" operations for WOPI. @@ -91,8 +92,7 @@ func (h *HttpAdapter) Lock(w http.ResponseWriter, r *http.Request) { } return } - // If no error, a HTTP 200 should be sent automatically. - // X-WOPI-Lock header isn't needed on HTTP 200 + w.WriteHeader(http.StatusOK) } // RefreshLock adapts the "RefreshLock" operation for WOPI @@ -119,8 +119,7 @@ func (h *HttpAdapter) RefreshLock(w http.ResponseWriter, r *http.Request) { } return } - // If no error, a HTTP 200 should be sent automatically. - // X-WOPI-Lock header isn't needed on HTTP 200 + w.WriteHeader(http.StatusOK) } // UnLock adapts the "Unlock" operation for WOPI @@ -145,8 +144,7 @@ func (h *HttpAdapter) UnLock(w http.ResponseWriter, r *http.Request) { } return } - // If no error, a HTTP 200 should be sent automatically. - // X-WOPI-Lock header isn't needed on HTTP 200 + w.WriteHeader(http.StatusOK) } // CheckFileInfo will retrieve the information of the file in json format @@ -229,6 +227,5 @@ func (h *HttpAdapter) PutFile(w http.ResponseWriter, r *http.Request) { } return } - // If no error, a HTTP 200 should be sent automatically. - // X-WOPI-Lock header isn't needed on HTTP 200 + w.WriteHeader(http.StatusOK) } diff --git a/services/collaboration/pkg/middleware/accesslog.go b/services/collaboration/pkg/middleware/accesslog.go new file mode 100644 index 000000000..e51faeb4b --- /dev/null +++ b/services/collaboration/pkg/middleware/accesslog.go @@ -0,0 +1,37 @@ +package middleware + +import ( + "net/http" + "time" + + "github.com/go-chi/chi/v5/middleware" + "github.com/owncloud/ocis/v2/ocis-pkg/log" + "go.opentelemetry.io/otel/trace" +) + +// AccessLog is a middleware to log http requests at info level logging. +func AccessLog(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) { + 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) + next.ServeHTTP(wrap, r) + + spanContext := trace.SpanContextFromContext(r.Context()) + logger.Info(). + Str("proto", r.Proto). + Str(log.RequestIDString, requestID). + Str("traceid", spanContext.TraceID().String()). + Str("remote-addr", r.RemoteAddr). + Str("method", r.Method). + Int("status", wrap.Status()). + Str("path", r.URL.Path). + Dur("duration", time.Since(start)). + Int("bytes", wrap.BytesWritten()). + Msg("access-log") + }) + } +} diff --git a/services/collaboration/pkg/server/http/server.go b/services/collaboration/pkg/server/http/server.go index ca494549a..5eab32766 100644 --- a/services/collaboration/pkg/server/http/server.go +++ b/services/collaboration/pkg/server/http/server.go @@ -44,7 +44,7 @@ func Server(opts ...Option) (http.Service, error) { options.Config.Service.Name+"."+options.Config.App.Name, version.GetString(), ), - middleware.Logger( + colabmiddleware.AccessLog( options.Logger, ), middleware.ExtractAccountUUID(