Files
opencloud/pkg/middleware/audit.go
micbar a12cca9a5f feat: read the audit request context in the HTTP services
The HTTP services put the X-Audit-Context header of the proxy into the request context, so it reaches reva with the next call.
2026-11-26 16:52:55 +01:00

21 lines
676 B
Go

package middleware
import (
"net/http"
"github.com/opencloud-eu/reva/v3/pkg/audit"
)
// AuditContext reads the audit request context the proxy sets in the
// X-Audit-Context header. The service can then emit audit events with it, and
// its gRPC calls pass it on. Only the proxy is reachable from outside and it
// always replaces the header, so the value can be trusted here.
func AuditContext(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if v := r.Header.Get(audit.Header); v != "" {
r = r.WithContext(audit.ContextSetRequest(r.Context(), audit.ParseRequestContext(v)))
}
next.ServeHTTP(w, r)
})
}