Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions src/Http/WolverineWebApi/Bugs/FrameRearrangeEndpoint.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using JasperFx.CodeGeneration;
using Microsoft.AspNetCore.Mvc;
using Wolverine.Http;
using Wolverine.Http.Marten;
using Wolverine.Middleware;
using Wolverine.Runtime;
using WolverineWebApi.Marten;

namespace WolverineWebApi.Bugs;

public static class FrameRearrangeEndpoint
{
[WolverineGet("/frame-rearrange/{id}")]
public static Invoice Get([Document(Required = true, MaybeSoftDeleted = false)] Invoice invoice)
{
return invoice;
}
}

public static class FrameRearrangeMiddleware
{
public static void Before(HttpContext context)
{
// Very simplified code, but similar to what I have in production
var userAgents = context.Request.Headers.UserAgent;
if (userAgents.Any(f => f?.Contains("block-me") ?? false))
{
throw new Exception("Blocked client");
}
}

public class HttpPolicy : IHttpPolicy
{
public void Apply(IReadOnlyList<HttpChain> chains, GenerationRules rules, IServiceContainer container)
{
// Only apply this policy to the FrameRearrangeEndpoint, but in production it's applied to all endpoints
foreach (var chain in chains.Where(f => f.Method.HandlerType.Name == nameof(FrameRearrangeEndpoint)))
{
var middlewarePolicy = new MiddlewarePolicy();
middlewarePolicy.AddType(typeof(FrameRearrangeMiddleware));

middlewarePolicy.Apply([chain], rules, container);
}
}
}
}
2 changes: 2 additions & 0 deletions src/Http/WolverineWebApi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
using Wolverine.Http.Transport;
using Wolverine.Marten;
using WolverineWebApi;
using WolverineWebApi.Bugs;
using WolverineWebApi.Marten;
using WolverineWebApi.Samples;
using WolverineWebApi.Things;
Expand Down Expand Up @@ -264,6 +265,7 @@

opts.AddPolicy<StreamCollisionExceptionPolicy>();

opts.AddPolicy<FrameRearrangeMiddleware.HttpPolicy>();

#region sample_adding_custom_parameter_handling

Expand Down
Loading