actorMiddleware injects actor identity into request context. In production, the user ID should be extracted from auth headers/tokens.
(next http.Handler)
| 112 | // actorMiddleware injects actor identity into request context. |
| 113 | // In production, the user ID should be extracted from auth headers/tokens. |
| 114 | func actorMiddleware(next http.Handler) http.Handler { |
| 115 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 116 | userID := r.Header.Get("X-User-ID") |
| 117 | if userID == "" { |
| 118 | userID = "anonymous" |
| 119 | } |
| 120 | ctx := aibcontext.AsActor(r.Context(), userID, nil) |
| 121 | next.ServeHTTP(w, r.WithContext(ctx)) |
| 122 | }) |
| 123 | } |