From 4fd91fc94804a16cf792f855e87e2f89ceea4a98 Mon Sep 17 00:00:00 2001 From: Marcin Jahn <10273406+marcinjahn@users.noreply.github.com> Date: Mon, 9 Dec 2024 18:17:31 +0100 Subject: [PATCH] Skip copy when non-seekable stream --- .../httpClient/Middleware/BodyInspectionHandler.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/http/httpClient/Middleware/BodyInspectionHandler.cs b/src/http/httpClient/Middleware/BodyInspectionHandler.cs index 3b6656a..03f5004 100644 --- a/src/http/httpClient/Middleware/BodyInspectionHandler.cs +++ b/src/http/httpClient/Middleware/BodyInspectionHandler.cs @@ -85,9 +85,18 @@ CancellationToken cancellationToken return null; } + if (httpContent.Headers.ContentLength == 0) + { + return Stream.Null; + } + var stream = new MemoryStream(); await httpContent.CopyToAsync(stream); - stream.Position = 0; + + if (stream.CanSeek) + { + stream.Position = 0; + } return stream; }