Skip to content

Commit

Permalink
Disable zero-byte-reads on 3.1 and 5.0 (#1666)
Browse files Browse the repository at this point in the history
  • Loading branch information
MihaZupan authored Apr 25, 2022
1 parent e684ba5 commit 7d8b815
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/ReverseProxy/Forwarder/StreamCopier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ internal static class StreamCopier
{
read = 0;

#if NET6_0_OR_GREATER
// Issue a zero-byte read to the input stream to defer buffer allocation until data is available.
// Note that if the underlying stream does not supporting blocking on zero byte reads, then this will
// complete immediately and won't save any memory, but will still function correctly.
Expand All @@ -67,6 +68,7 @@ internal static class StreamCopier

buffer = ArrayPool<byte>.Shared.Rent(DefaultBufferSize);
}
#endif

read = await input.ReadAsync(buffer.AsMemory(), cancellation);
contentLength += read;
Expand Down

0 comments on commit 7d8b815

Please sign in to comment.