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:
///
///
///
/// InboundAPI-008 — active-node gating. The inbound API is central-active-node-only;
/// a standby node returns HTTP 503 so it never executes method scripts.
///
///
/// InboundAPI-006 — 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 InboundApiOptions _options;
/// Initializes a new with the given logger and options.
/// Logger for request rejection diagnostics.
/// Inbound API options including the maximum request body size.
public InboundApiEndpointFilter(
ILogger logger,
IOptions options)
{
_logger = logger;
_options = options.Value;
}
/// 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