fix(inbound-api): endpoint filter hot-reads MaxRequestBodyBytes via IOptionsMonitor
Claude-Session: https://claude.ai/code/session_01MtdgwpEeCUn6cUA5f1LMPj
This commit is contained in:
@@ -15,7 +15,7 @@ public class EndpointGatingTests
|
||||
{
|
||||
private static InboundApiEndpointFilter CreateFilter(InboundApiOptions? options = null) =>
|
||||
new(NullLogger<InboundApiEndpointFilter>.Instance,
|
||||
Options.Create(options ?? new InboundApiOptions()));
|
||||
new TestOptionsMonitor<InboundApiOptions>(options ?? new InboundApiOptions()));
|
||||
|
||||
private static (DefaultHttpContext ctx, DefaultEndpointFilterInvocationContext invocation)
|
||||
BuildInvocation(bool? activeNode, long? contentLength)
|
||||
@@ -144,4 +144,37 @@ public class EndpointGatingTests
|
||||
public bool IsReadOnly => false;
|
||||
public long? MaxRequestBodySize { get; set; }
|
||||
}
|
||||
|
||||
// --- InboundAPI hot-reload: options must be re-read per request, not cached at ctor time ---
|
||||
|
||||
[Fact]
|
||||
public async Task BodySizeCap_HotReloads_WithoutRestart()
|
||||
{
|
||||
var monitor = new TestOptionsMonitor<InboundApiOptions>(new InboundApiOptions { MaxRequestBodyBytes = 10 });
|
||||
var filter = new InboundApiEndpointFilter(NullLogger<InboundApiEndpointFilter>.Instance, monitor);
|
||||
|
||||
var (_, firstInvocation) = BuildInvocation(activeNode: true, contentLength: 20);
|
||||
var firstNext = NextSentinel(out var firstHandlerRan);
|
||||
var firstResult = await filter.InvokeAsync(firstInvocation, firstNext);
|
||||
|
||||
Assert.False(firstHandlerRan());
|
||||
var firstStatus = Assert.IsAssignableFrom<IStatusCodeHttpResult>(firstResult);
|
||||
Assert.Equal(StatusCodes.Status413PayloadTooLarge, firstStatus.StatusCode);
|
||||
|
||||
monitor.CurrentValue = new InboundApiOptions { MaxRequestBodyBytes = 1024 * 1024 };
|
||||
|
||||
var (_, secondInvocation) = BuildInvocation(activeNode: true, contentLength: 20);
|
||||
var secondNext = NextSentinel(out var secondHandlerRan);
|
||||
await filter.InvokeAsync(secondInvocation, secondNext);
|
||||
|
||||
Assert.True(secondHandlerRan());
|
||||
}
|
||||
|
||||
private sealed class TestOptionsMonitor<T> : IOptionsMonitor<T>
|
||||
{
|
||||
public TestOptionsMonitor(T currentValue) => CurrentValue = currentValue;
|
||||
public T CurrentValue { get; set; }
|
||||
public T Get(string? name) => CurrentValue;
|
||||
public IDisposable? OnChange(Action<T, string?> listener) => null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user