Skip to content

Commit

Permalink
Allow zero byte reads on raw HTTP/1.1 response streams
Browse files Browse the repository at this point in the history
  • Loading branch information
MihaZupan committed Nov 22, 2021
1 parent 9a9a4f3 commit 25029a7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1747,7 +1747,7 @@ private ValueTask<int> ReadBufferedAsync(Memory<byte> destination)
// If the caller provided buffer, and thus the amount of data desired to be read,
// is larger than the internal buffer, there's no point going through the internal
// buffer, so just do an unbuffered read.
return destination.Length >= _readBuffer.Length ?
return destination.Length == 0 || destination.Length >= _readBuffer.Length ?
ReadAsync(destination) :
ReadBufferedAsyncCore(destination);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ public override async ValueTask<int> ReadAsync(Memory<byte> buffer, Cancellation
CancellationHelper.ThrowIfCancellationRequested(cancellationToken);

HttpConnection? connection = _connection;
if (connection == null || buffer.Length == 0)
if (connection == null)
{
// Response body fully consumed or the caller didn't ask for any data
// Response body fully consumed
return 0;
}

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

if (bytesRead == 0)
if (bytesRead == 0 && buffer.Length != 0)
{
// A cancellation request may have caused the EOF.
CancellationHelper.ThrowIfCancellationRequested(cancellationToken);
Expand Down

0 comments on commit 25029a7

Please sign in to comment.