Move HTTP base-path gate ahead of route matching - #7715
Conversation
|
I requested Copilot review multiple times for the current head ( |
Greptile SummaryThis PR optimizes the HTTP workflow middleware by moving the base-path gate check ahead of route-table matching, so requests outside the configured base path never touch the route table. It also refactors the nested
Confidence Score: 5/5Safe to merge — the reordering of the base-path gate and route-table lookup is a pure optimization with no observable behavior change for callers. The functional contract of the middleware is unchanged: GetMatchingRoute is still called with the full, un-stripped path and the matched template is stripped by basePath.Length before computing the bookmark hash — exactly as before. The early-exit guard just avoids the route-table scan for requests that could never match. The three new tests exercise the early-exit path, the in-scope matching path, and the existing tenant-scoped bookmark filter, giving good direct coverage of the changed code paths. No files require special attention.
|
| Filename | Overview |
|---|---|
| src/modules/Elsa.Http/Middleware/HttpWorkflowsMiddleware.cs | Early-exit gate moved before GetMatchingRoute; functional behavior is preserved — matchingPath is still computed against the full path and then stripped by basePath length. |
| test/unit/Elsa.Http.UnitTests/Middleware/HttpWorkflowsMiddlewareTests.cs | Refactored from constructor-based to factory-based test setup; adds two new tests for the early-exit and in-scope paths; CapturingStimulusHasher correctly captures the stripped path for assertion. |
Sequence Diagram
sequenceDiagram
participant Client
participant Middleware as HttpWorkflowsMiddleware
participant RouteTable as IRouteTable / IRouteMatcher
participant WorkflowLookup as IHttpWorkflowLookupService
participant Next as Next Middleware
Client->>Middleware: HTTP Request (path)
Middleware->>Middleware: NormalizeRoute(path)
Middleware->>Middleware: Check hasBasePath
alt hasBasePath AND path does NOT start with basePath
Middleware->>Next: await next(httpContext) [early exit — no route matching]
else No basePath OR path starts with basePath
Middleware->>RouteTable: GetMatchingRoute(path)
RouteTable-->>Middleware: matchingPath (template or fallback)
Middleware->>Middleware: Strip basePath from matchingPath (if hasBasePath)
Middleware->>Middleware: NormalizeRoute(matchingPath)
Middleware->>WorkflowLookup: FindWorkflowAsync(bookmarkHash)
WorkflowLookup-->>Middleware: result
alt Workflow / Bookmark found
Middleware->>Client: Execute workflow response
else Not found AND basePath configured
Middleware->>Client: 404 Not Found
else Not found AND no basePath
Middleware->>Next: await next(httpContext)
end
end
Reviews (1): Last reviewed commit: "Register middleware test doubles by inte..." | Re-trigger Greptile
|
@copilot resolve the merge conflicts in this pull request |
Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>
Resolved. The only conflict was in |
Summary
Testing
Closes #7709