Skip to content

Commit 25029a7

Browse files
committed
Allow zero byte reads on raw HTTP/1.1 response streams
1 parent 9a9a4f3 commit 25029a7

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1747,7 +1747,7 @@ private ValueTask<int> ReadBufferedAsync(Memory<byte> destination)
17471747
// If the caller provided buffer, and thus the amount of data desired to be read,
17481748
// is larger than the internal buffer, there's no point going through the internal
17491749
// buffer, so just do an unbuffered read.
1750-
return destination.Length >= _readBuffer.Length ?
1750+
return destination.Length == 0 || destination.Length >= _readBuffer.Length ?
17511751
ReadAsync(destination) :
17521752
ReadBufferedAsyncCore(destination);
17531753
}

src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/RawConnectionStream.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ public override async ValueTask<int> ReadAsync(Memory<byte> buffer, Cancellation
4545
CancellationHelper.ThrowIfCancellationRequested(cancellationToken);
4646

4747
HttpConnection? connection = _connection;
48-
if (connection == null || buffer.Length == 0)
48+
if (connection == null)
4949
{
50-
// Response body fully consumed or the caller didn't ask for any data
50+
// Response body fully consumed
5151
return 0;
5252
}
5353

@@ -74,7 +74,7 @@ public override async ValueTask<int> ReadAsync(Memory<byte> buffer, Cancellation
7474
}
7575
}
7676

77-
if (bytesRead == 0)
77+
if (bytesRead == 0 && buffer.Length != 0)
7878
{
7979
// A cancellation request may have caused the EOF.
8080
CancellationHelper.ThrowIfCancellationRequested(cancellationToken);

0 commit comments

Comments
 (0)