Fix route data handling (#6176)

* Fix route data handling

* Cleanup
This commit is contained in:
Sipke Schoorstra 2024-12-04 11:31:03 +01:00 committed by GitHub
parent a0a0482f5d
commit 8c40475cc6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 50 additions and 3 deletions

View file

@ -53,7 +53,6 @@ public class HttpWorkflowsMiddleware(RequestDelegate next, ITenantAccessor tenan
}
// Strip the base path.
path = path[basePath.Length..];
matchingPath = matchingPath[basePath.Length..];
}
@ -62,7 +61,7 @@ public class HttpWorkflowsMiddleware(RequestDelegate next, ITenantAccessor tenan
var input = new Dictionary<string, object>
{
[HttpEndpoint.HttpContextInputKey] = true,
[HttpEndpoint.RequestPathInputKey] = path
[HttpEndpoint.RequestPathInputKey] = path.NormalizeRoute()
};
var cancellationToken = httpContext.RequestAborted;

View file

@ -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();

View file

@ -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);
}
}

View file

@ -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")
}
]
};
}
}