using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
namespace ZB.MOM.WW.ScadaBridge.InboundAPI;
///
/// Endpoint filter applied to POST /api/{methodName} that enforces two
/// cross-cutting guards before the request handler runs:
///
///
///
/// Active-node gating. The inbound API is central-active-node-only;
/// a standby node returns HTTP 503 so it never executes method scripts.
///
///
/// Request body size cap. Oversized bodies are rejected with HTTP
/// 413 before being buffered into a JsonDocument.
///
///
///
public sealed class InboundApiEndpointFilter : IEndpointFilter
{
private readonly ILogger _logger;
private readonly IOptionsMonitor _options;
/// Initializes a new with the given logger and options.
/// Logger for request rejection diagnostics.
/// Live-reloadable inbound API options, read per-request.
public InboundApiEndpointFilter(
ILogger logger,
IOptionsMonitor options)
{
_logger = logger;
_options = options;
}
/// Applies active-node gating and request body size checks before delegating to the next filter or handler.
/// The endpoint filter invocation context containing the HTTP context and arguments.
/// The next filter or endpoint handler in the pipeline.
/// A value task that resolves to the filter pipeline result, or an error result if gating fails.
public async ValueTask