| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System.IO; |
| | | 5 | | using System.Threading; |
| | | 6 | | using System.Threading.Tasks; |
| | | 7 | | |
| | | 8 | | namespace System.Net.Http |
| | | 9 | | { |
| | | 10 | | /// <summary>Provides a zero-length HttpContent implementation.</summary> |
| | | 11 | | internal sealed class EmptyContent : HttpContent |
| | | 12 | | { |
| | | 13 | | protected internal override bool TryComputeLength(out long length) |
| | 0 | 14 | | { |
| | 0 | 15 | | length = 0; |
| | 0 | 16 | | return true; |
| | 0 | 17 | | } |
| | | 18 | | |
| | | 19 | | protected override void SerializeToStream(Stream stream, TransportContext? context, CancellationToken cancellati |
| | 0 | 20 | | { } |
| | | 21 | | |
| | | 22 | | protected override Task SerializeToStreamAsync(Stream stream, TransportContext? context) => |
| | 0 | 23 | | Task.CompletedTask; |
| | | 24 | | |
| | | 25 | | protected override Task SerializeToStreamAsync(Stream stream, TransportContext? context, CancellationToken cance |
| | 0 | 26 | | cancellationToken.IsCancellationRequested ? Task.FromCanceled(cancellationToken) : |
| | 0 | 27 | | SerializeToStreamAsync(stream, context); |
| | | 28 | | |
| | | 29 | | protected override Stream CreateContentReadStream(CancellationToken cancellationToken) => |
| | 0 | 30 | | EmptyReadStream.Instance; |
| | | 31 | | |
| | | 32 | | protected override Task<Stream> CreateContentReadStreamAsync() => |
| | 0 | 33 | | Task.FromResult<Stream>(EmptyReadStream.Instance); |
| | | 34 | | |
| | | 35 | | protected override Task<Stream> CreateContentReadStreamAsync(CancellationToken cancellationToken) => |
| | 0 | 36 | | cancellationToken.IsCancellationRequested ? Task.FromCanceled<Stream>(cancellationToken) : |
| | 0 | 37 | | CreateContentReadStreamAsync(); |
| | | 38 | | |
| | 0 | 39 | | internal override Stream? TryCreateContentReadStream() => EmptyReadStream.Instance; |
| | | 40 | | |
| | 0 | 41 | | internal override bool AllowDuplex => false; |
| | | 42 | | } |
| | | 43 | | } |