Skip to content

Commit

Permalink
Fix route data handling (#6176)
Browse files Browse the repository at this point in the history
* Fix route data handling

* Cleanup
  • Loading branch information
sfmskywalker authored Dec 4, 2024
1 parent a0a0482 commit 8c40475
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 3 deletions.
3 changes: 1 addition & 2 deletions src/modules/Elsa.Http/Middleware/HttpWorkflowsMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public async Task InvokeAsync(HttpContext httpContext, IServiceProvider serviceP
}

// Strip the base path.
path = path[basePath.Length..];
matchingPath = matchingPath[basePath.Length..];
}

Expand All @@ -62,7 +61,7 @@ public async Task InvokeAsync(HttpContext httpContext, IServiceProvider serviceP
var input = new Dictionary<string, object>
{
[HttpEndpoint.HttpContextInputKey] = true,
[HttpEndpoint.RequestPathInputKey] = path
[HttpEndpoint.RequestPathInputKey] = path.NormalizeRoute()
};

var cancellationToken = httpContext.RequestAborted;
Expand Down
3 changes: 2 additions & 1 deletion src/modules/Elsa.Http/Services/RouteMatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ public class RouteMatcher : IRouteMatcher
public RouteValueDictionary? Match(string routeTemplate, string route)
{
var normalizedRoute = route.NormalizeRoute();
var template = TemplateParser.Parse(routeTemplate);
var normalizedRouteTemplate = routeTemplate.NormalizeRoute();
var template = TemplateParser.Parse(normalizedRouteTemplate);
var matcher = new TemplateMatcher(template, GetDefaults(template));
var values = new RouteValueDictionary();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Elsa.Workflows.ComponentTests.Abstractions;
using Elsa.Workflows.ComponentTests.Fixtures;

namespace Elsa.Workflows.ComponentTests.Scenarios.HttpWorkflows;

public class RouteDataTests(App app) : AppComponentTest(app)
{
[Fact]
public async Task RouteDataWorkflow_ShouldRespondWithRouteData()
{
var client = WorkflowServer.CreateHttpWorkflowClient();
var response = await client.GetStringAsync("orders/42");
Assert.Equal("42", response);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Elsa.Http;
using Elsa.Workflows.Activities;
using Microsoft.AspNetCore.Http;

namespace Elsa.Workflows.ComponentTests.Scenarios.HttpWorkflows.Workflows;

public class RouteDataWorkflow : WorkflowBase
{
protected override void Build(IWorkflowBuilder builder)
{
var routeDataVariable = builder.WithVariable<IDictionary<string, object>>();

builder.Root = new Sequence
{
Activities =
[
new HttpEndpoint
{
Path = new("orders/{id}"),
SupportedMethods = new([HttpMethods.Get]),
CanStartWorkflow = true,
RouteData = new(routeDataVariable)
},
new WriteHttpResponse
{
Content = new(context => routeDataVariable.Get(context)!["id"].ToString()),
ContentType = new("text/plain")
}
]
};
}
}

0 comments on commit 8c40475

Please sign in to comment.