-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make HttpResponseMessage.Content non-nullable (#35910)
* Make HttpResponseMessage.Content non-nullable * Fix Microsoft.Extensions.Http test
- Loading branch information
1 parent
43b5d81
commit b48900f
Showing
11 changed files
with
118 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/libraries/System.Net.Http/src/System/Net/Http/EmptyContent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.IO; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace System.Net.Http | ||
{ | ||
/// <summary>Provides a zero-length HttpContent implementation.</summary> | ||
internal sealed class EmptyContent : HttpContent | ||
{ | ||
protected internal override bool TryComputeLength(out long length) | ||
{ | ||
length = 0; | ||
return true; | ||
} | ||
|
||
protected override Task SerializeToStreamAsync(Stream stream, TransportContext? context) => | ||
Task.CompletedTask; | ||
|
||
protected override Task SerializeToStreamAsync(Stream stream, TransportContext? context, CancellationToken cancellationToken) => | ||
cancellationToken.IsCancellationRequested ? Task.FromCanceled(cancellationToken) : | ||
SerializeToStreamAsync(stream, context); | ||
|
||
protected override Task<Stream> CreateContentReadStreamAsync() => | ||
Task.FromResult<Stream>(EmptyReadStream.Instance); | ||
|
||
protected override Task<Stream> CreateContentReadStreamAsync(CancellationToken cancellationToken) => | ||
cancellationToken.IsCancellationRequested ? Task.FromCanceled<Stream>(cancellationToken) : | ||
CreateContentReadStreamAsync(); | ||
|
||
internal override Stream? TryCreateContentReadStream() => EmptyReadStream.Instance; | ||
|
||
internal override bool AllowDuplex => false; | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.