Skip to content

Move HTTP base-path gate ahead of route matching - #7715

Open
sfmskywalker wants to merge 4 commits into
mainfrom
codex/7709-http-basepath-gate-v1
Open

Move HTTP base-path gate ahead of route matching#7715
sfmskywalker wants to merge 4 commits into
mainfrom
codex/7709-http-basepath-gate-v1

Conversation

@sfmskywalker

Copy link
Copy Markdown
Member

Summary

  • skip route-table matching for requests outside the configured HTTP workflow base path
  • preserve route matching behavior for requests under the base path before stripping it
  • add focused middleware tests for the early-exit and in-scope matching paths

Testing

  • not run locally in this session; local shell/process startup is unavailable here

Closes #7709

Copy link
Copy Markdown
Member Author

I requested Copilot review multiple times for the current head (6a61005fa5a52b8825bc56c048ffb2d9074d2cc4) using the available GitHub tools, but no reviewer state, reviews, review threads, or PR comments materialized. Leaving this PR open and mergeable until Copilot review becomes available.

@greptile-apps

greptile-apps Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This 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 if into a single guard clause and adds focused unit tests covering early-exit and in-scope scenarios.

  • Middleware optimization: GetMatchingRoute is now called only after the base-path check passes, avoiding unnecessary route-table lookups for unrelated requests.
  • Tests added: Two new test cases verify that requests outside the base path skip route matching entirely and that requests within the base path produce the correctly stripped bookmark hash.

Confidence Score: 5/5

Safe 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.

Important Files Changed

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
Loading

Reviews (1): Last reviewed commit: "Register middleware test doubles by inte..." | Re-trigger Greptile

@sfmskywalker

Copy link
Copy Markdown
Member Author

@copilot resolve the merge conflicts in this pull request

Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>

Copilot AI commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

@copilot resolve the merge conflicts in this pull request

Resolved. The only conflict was in HttpWorkflowsMiddlewareTests.cs — the fault-handler and timeout tests added on main collided with the base-path gate tests added in this branch. The merged file keeps all 8 tests, adds the _middleware instance field needed by the fault/timeout reflection helpers, and retains the per-test static helpers and capturing test doubles from this branch. Commit: 54173e7.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Skip Elsa route matching before base-path gating in HTTP workflow middleware

2 participants