namespace BigRegister.Api.Zgw; /// /// Opt-in only (wired in Program.cs behind ZGW_DEBUG_HTTP=1) — chases the /// still-unexplained flake where a freshly-(re)started `api` container has every outbound ZGW /// POST fail with what looks like an empty body reaching OpenZaak (see /// scripts/openzaak-ui-up.sh's header comment). Logs the one signal that would actually /// distinguish "client built an empty body" from "something ate it after send": the declared /// Content-Length vs. the byte count actually read from the request right before it goes out. /// A mismatch here would prove client-side corruption; agreement would point downstream instead. /// public sealed class ZgwDiagnosticHandler(ILogger logger) : DelegatingHandler { protected override async Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { if (request.Content is not null) { var bytes = await request.Content.ReadAsByteArrayAsync(cancellationToken); logger.LogInformation( "ZGW {Method} {Url}: Content-Length={ContentLength} actualBytes={Actual}", request.Method, request.RequestUri, request.Content.Headers.ContentLength, bytes.Length); } return await base.SendAsync(request, cancellationToken); } }