Skip to content

Commit 2013be5

Browse files
dougbuTratcher
andauthored
Apply suggestions from code review
Co-authored-by: Chris Ross <Tratcher@Outlook.com>
1 parent d5637fc commit 2013be5

File tree

2 files changed

+2
-7
lines changed

2 files changed

+2
-7
lines changed

src/System.Net.Http.Formatting/HttpMessageContent.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ private void ValidateStreamForReading(Stream stream)
361361
{
362362
// Stream is null case should be an extreme, incredibly unlikely corner case. Every HttpContent from
363363
// the framework (see dotnet/runtime or .NET Framework reference source) provides a non-null Stream
364-
// in the ReadAsStringAsync task's return value. Likely need a poorly-designed derived HttpContent
364+
// in the ReadAsStreamAsync task's return value. Likely need a poorly-designed derived HttpContent
365365
// to hit this. Mostly ignoring the fact this message doesn't make much sense for the case.
366366
if (stream is null || !stream.CanRead)
367367
{

test/System.Net.Http.Formatting.Test/HttpMessageContentTests.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,7 @@ private static async Task<string> ReadContentAsync(HttpContent content, bool unB
5050
{
5151
if (unBuffered)
5252
{
53-
var stream = new MemoryStream();
54-
await content.CopyToAsync(stream);
55-
stream.Position = 0L;
56-
57-
// StreamReader will dispose of the Stream.
58-
using var reader = new StreamReader(stream);
53+
using var reader = new StreamReader(await content.ReadAsStreamAsync());
5954

6055
return await reader.ReadToEndAsync();
6156
}

0 commit comments

Comments
 (0)