From f44a304eaccf66cf5a9d1543a0de742ef0e246da Mon Sep 17 00:00:00 2001 From: Diogo Martins Date: Sat, 15 Aug 2026 17:44:21 +0100 Subject: [PATCH] Raise the response read buffer to 128KiB MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ReadResponseAsync reads into a single fixed 64KiB buffer, and both the header loop and DrainAvailable stop at buffer.Length. Anything past that is silently dropped: no exception, no truncation flag, just a short response that later assertions read as the server's actual reply. Four tests send payloads of 100,000 bytes — MAL-LONG-URL, MAL-LONG-HEADER-NAME, MAL-LONG-HEADER-VALUE and MAL-LONG-METHOD. A server that echoes one back in its error response overruns the buffer, so what the probe records for those cases is a truncation artifact rather than what the server sent. Raise the buffer to 128KiB, which clears the 100,000-byte ceiling with room for status line and headers, and name it so the bound is documented where the tests that set it are listed. --- src/Http11Probe/Client/RawTcpClient.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Http11Probe/Client/RawTcpClient.cs b/src/Http11Probe/Client/RawTcpClient.cs index e5a16b1..9f71946 100644 --- a/src/Http11Probe/Client/RawTcpClient.cs +++ b/src/Http11Probe/Client/RawTcpClient.cs @@ -5,6 +5,12 @@ namespace Http11Probe.Client; public sealed class RawTcpClient : IAsyncDisposable { + // Responses are read into a single fixed buffer and truncated at its size. Keep this above the + // largest payload any test sends — 100,000 bytes (MAL-LONG-URL, MAL-LONG-HEADER-NAME, + // MAL-LONG-HEADER-VALUE, MAL-LONG-METHOD) — so a server that echoes one back in an error + // response doesn't get cut off and misread as a truncated reply. + private const int ReadBufferSize = 128 * 1024; + private Socket? _socket; private readonly TimeSpan _connectTimeout; private readonly TimeSpan _readTimeout; @@ -60,7 +66,7 @@ public async Task SendAsync(ReadOnlyMemory data) if (_socket is null) return ([], 0, ConnectionState.Error, false); - var buffer = new byte[65536]; + var buffer = new byte[ReadBufferSize]; var totalRead = 0; using var cts = new CancellationTokenSource(_readTimeout);