fix(inbound-api): endpoint filter hot-reads MaxRequestBodyBytes via IOptionsMonitor

Claude-Session: https://claude.ai/code/session_01MtdgwpEeCUn6cUA5f1LMPj
This commit is contained in:
Joseph Doherty
2026-07-10 03:48:49 -04:00
parent 9b0cf44c02
commit aa1c1093e4
2 changed files with 39 additions and 6 deletions
@@ -24,17 +24,17 @@ namespace ZB.MOM.WW.ScadaBridge.InboundAPI;
public sealed class InboundApiEndpointFilter : IEndpointFilter
{
private readonly ILogger<InboundApiEndpointFilter> _logger;
private readonly InboundApiOptions _options;
private readonly IOptionsMonitor<InboundApiOptions> _options;
/// <summary>Initializes a new <see cref="InboundApiEndpointFilter"/> with the given logger and options.</summary>
/// <param name="logger">Logger for request rejection diagnostics.</param>
/// <param name="options">Inbound API options including the maximum request body size.</param>
/// <param name="options">Live-reloadable inbound API options, read per-request.</param>
public InboundApiEndpointFilter(
ILogger<InboundApiEndpointFilter> logger,
IOptions<InboundApiOptions> options)
IOptionsMonitor<InboundApiOptions> options)
{
_logger = logger;
_options = options.Value;
_options = options;
}
/// <summary>Applies active-node gating and request body size checks before delegating to the next filter or handler.</summary>
@@ -63,7 +63,7 @@ public sealed class InboundApiEndpointFilter : IEndpointFilter
// Cap the request body size. Reject an over-limit body up
// front via Content-Length; also lower the per-request max body size so a
// chunked/unknown-length stream is cut off by Kestrel as it is read.
var maxBytes = _options.MaxRequestBodyBytes;
var maxBytes = _options.CurrentValue.MaxRequestBodyBytes;
if (httpContext.Request.ContentLength is { } declaredLength && declaredLength > maxBytes)
{
_logger.LogWarning(