| | | 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.Collections.Generic; |
| | | 5 | | using System.Diagnostics; |
| | | 6 | | using System.IO; |
| | | 7 | | using System.IO.Compression; |
| | | 8 | | using System.Net.Http.Headers; |
| | | 9 | | using System.Threading; |
| | | 10 | | using System.Threading.Tasks; |
| | | 11 | | |
| | | 12 | | namespace System.Net.Http |
| | | 13 | | { |
| | | 14 | | internal sealed class DecompressionHandler : HttpMessageHandlerStage |
| | | 15 | | { |
| | | 16 | | private readonly HttpMessageHandlerStage _innerHandler; |
| | | 17 | | private readonly DecompressionMethods _decompressionMethods; |
| | | 18 | | |
| | | 19 | | private const string Gzip = "gzip"; |
| | | 20 | | private const string Deflate = "deflate"; |
| | | 21 | | private const string Brotli = "br"; |
| | 0 | 22 | | private static readonly StringWithQualityHeaderValue s_gzipHeaderValue = new(Gzip); |
| | 0 | 23 | | private static readonly StringWithQualityHeaderValue s_deflateHeaderValue = new(Deflate); |
| | 0 | 24 | | private static readonly StringWithQualityHeaderValue s_brotliHeaderValue = new(Brotli); |
| | | 25 | | |
| | | 26 | | /// <summary>Header value for all enabled decompression methods, e.g. "gzip, deflate".</summary> |
| | | 27 | | private readonly string _acceptEncodingHeaderValue; |
| | | 28 | | |
| | 0 | 29 | | public DecompressionHandler(DecompressionMethods decompressionMethods, HttpMessageHandlerStage innerHandler) |
| | 0 | 30 | | { |
| | 0 | 31 | | Debug.Assert(decompressionMethods != DecompressionMethods.None); |
| | 0 | 32 | | Debug.Assert(innerHandler != null); |
| | | 33 | | |
| | 0 | 34 | | _decompressionMethods = decompressionMethods; |
| | 0 | 35 | | _innerHandler = innerHandler; |
| | | 36 | | |
| | 0 | 37 | | List<string?> methods = [GZipEnabled ? Gzip : null, DeflateEnabled ? Deflate : null, BrotliEnabled ? Brotli |
| | 0 | 38 | | methods.RemoveAll(item => item is null); |
| | 0 | 39 | | _acceptEncodingHeaderValue = string.Join(", ", methods); |
| | 0 | 40 | | } |
| | | 41 | | |
| | 0 | 42 | | internal bool GZipEnabled => (_decompressionMethods & DecompressionMethods.GZip) != 0; |
| | 0 | 43 | | internal bool DeflateEnabled => (_decompressionMethods & DecompressionMethods.Deflate) != 0; |
| | 0 | 44 | | internal bool BrotliEnabled => (_decompressionMethods & DecompressionMethods.Brotli) != 0; |
| | | 45 | | |
| | | 46 | | private static bool EncodingExists(HttpHeaderValueCollection<StringWithQualityHeaderValue> acceptEncodingHeader, |
| | 0 | 47 | | { |
| | 0 | 48 | | foreach (StringWithQualityHeaderValue existingEncoding in acceptEncodingHeader) |
| | 0 | 49 | | { |
| | 0 | 50 | | if (string.Equals(existingEncoding.Value, encoding, StringComparison.OrdinalIgnoreCase)) |
| | 0 | 51 | | { |
| | 0 | 52 | | return true; |
| | | 53 | | } |
| | 0 | 54 | | } |
| | | 55 | | |
| | 0 | 56 | | return false; |
| | 0 | 57 | | } |
| | | 58 | | |
| | | 59 | | internal override async ValueTask<HttpResponseMessage> SendAsync(HttpRequestMessage request, bool async, Cancell |
| | 0 | 60 | | { |
| | 0 | 61 | | if (!request.Headers.Contains(KnownHeaders.AcceptEncoding.Descriptor)) |
| | 0 | 62 | | { |
| | | 63 | | // Very common case: no Accept-Encoding header yet, so just add one with all supported encodings. |
| | 0 | 64 | | request.Headers.TryAddWithoutValidation(KnownHeaders.AcceptEncoding.Descriptor, _acceptEncodingHeaderVal |
| | 0 | 65 | | } |
| | | 66 | | else |
| | 0 | 67 | | { |
| | 0 | 68 | | HttpHeaderValueCollection<StringWithQualityHeaderValue> acceptEncoding = request.Headers.AcceptEncoding; |
| | | 69 | | |
| | 0 | 70 | | if (GZipEnabled && !EncodingExists(acceptEncoding, Gzip)) |
| | 0 | 71 | | { |
| | 0 | 72 | | acceptEncoding.Add(s_gzipHeaderValue); |
| | 0 | 73 | | } |
| | | 74 | | |
| | 0 | 75 | | if (DeflateEnabled && !EncodingExists(acceptEncoding, Deflate)) |
| | 0 | 76 | | { |
| | 0 | 77 | | acceptEncoding.Add(s_deflateHeaderValue); |
| | 0 | 78 | | } |
| | | 79 | | |
| | 0 | 80 | | if (BrotliEnabled && !EncodingExists(acceptEncoding, Brotli)) |
| | 0 | 81 | | { |
| | 0 | 82 | | acceptEncoding.Add(s_brotliHeaderValue); |
| | 0 | 83 | | } |
| | 0 | 84 | | } |
| | | 85 | | |
| | 0 | 86 | | HttpResponseMessage response = await _innerHandler.SendAsync(request, async, cancellationToken).ConfigureAwa |
| | | 87 | | |
| | 0 | 88 | | Debug.Assert(response.Content != null); |
| | 0 | 89 | | if (response.Content.Headers.TryGetValues(KnownHeaders.ContentEncoding.Descriptor, out IEnumerable<string>? |
| | 0 | 90 | | { |
| | 0 | 91 | | Debug.Assert(contentEncodings is string[] { Length: > 0 }); |
| | | 92 | | |
| | 0 | 93 | | string[] encodings = (string[])contentEncodings; |
| | 0 | 94 | | string? last = encodings[^1]; |
| | | 95 | | |
| | 0 | 96 | | if (GZipEnabled && string.Equals(last, Gzip, StringComparison.OrdinalIgnoreCase)) |
| | 0 | 97 | | { |
| | 0 | 98 | | response.Content = new GZipDecompressedContent(response.Content, encodings); |
| | 0 | 99 | | } |
| | 0 | 100 | | else if (DeflateEnabled && string.Equals(last, Deflate, StringComparison.OrdinalIgnoreCase)) |
| | 0 | 101 | | { |
| | 0 | 102 | | response.Content = new DeflateDecompressedContent(response.Content, encodings); |
| | 0 | 103 | | } |
| | 0 | 104 | | else if (BrotliEnabled && string.Equals(last, Brotli, StringComparison.OrdinalIgnoreCase)) |
| | 0 | 105 | | { |
| | 0 | 106 | | response.Content = new BrotliDecompressedContent(response.Content, encodings); |
| | 0 | 107 | | } |
| | 0 | 108 | | } |
| | | 109 | | |
| | 0 | 110 | | return response; |
| | 0 | 111 | | } |
| | | 112 | | |
| | | 113 | | protected override void Dispose(bool disposing) |
| | 0 | 114 | | { |
| | 0 | 115 | | if (disposing) |
| | 0 | 116 | | { |
| | 0 | 117 | | _innerHandler.Dispose(); |
| | 0 | 118 | | } |
| | | 119 | | |
| | 0 | 120 | | base.Dispose(disposing); |
| | 0 | 121 | | } |
| | | 122 | | |
| | | 123 | | private abstract class DecompressedContent : HttpContent |
| | | 124 | | { |
| | | 125 | | private readonly HttpContent _originalContent; |
| | | 126 | | private bool _contentConsumed; |
| | | 127 | | |
| | 0 | 128 | | public DecompressedContent(HttpContent originalContent, string[] contentEncodings) |
| | 0 | 129 | | { |
| | 0 | 130 | | _originalContent = originalContent; |
| | 0 | 131 | | _contentConsumed = false; |
| | | 132 | | |
| | | 133 | | // Copy original response headers, but with the following changes: |
| | | 134 | | // Content-Length is removed, since it no longer applies to the decompressed content |
| | | 135 | | // The last Content-Encoding is removed, since we are processing that here. |
| | 0 | 136 | | SetHeaders(originalContent.Headers); |
| | 0 | 137 | | Headers.ContentLength = null; |
| | 0 | 138 | | Headers.Remove(KnownHeaders.ContentEncoding.Descriptor); |
| | | 139 | | |
| | 0 | 140 | | if (contentEncodings.Length > 1) |
| | 0 | 141 | | { |
| | 0 | 142 | | Headers.TryAddWithoutValidation(KnownHeaders.ContentEncoding.Descriptor, contentEncodings[..^1]); |
| | 0 | 143 | | } |
| | 0 | 144 | | } |
| | | 145 | | |
| | | 146 | | protected abstract Stream GetDecompressedStream(Stream originalStream); |
| | | 147 | | |
| | | 148 | | protected override void SerializeToStream(Stream stream, TransportContext? context, CancellationToken cancel |
| | 0 | 149 | | { |
| | 0 | 150 | | using Stream decompressedStream = CreateContentReadStream(cancellationToken); |
| | 0 | 151 | | decompressedStream.CopyTo(stream); |
| | 0 | 152 | | } |
| | | 153 | | |
| | | 154 | | protected override Task SerializeToStreamAsync(Stream stream, TransportContext? context) => |
| | 0 | 155 | | SerializeToStreamAsync(stream, context, CancellationToken.None); |
| | | 156 | | |
| | | 157 | | protected override async Task SerializeToStreamAsync(Stream stream, TransportContext? context, CancellationT |
| | 0 | 158 | | { |
| | 0 | 159 | | using (Stream decompressedStream = TryCreateContentReadStream() ?? await CreateContentReadStreamAsync(ca |
| | 0 | 160 | | { |
| | 0 | 161 | | await decompressedStream.CopyToAsync(stream, cancellationToken).ConfigureAwait(false); |
| | 0 | 162 | | } |
| | 0 | 163 | | } |
| | | 164 | | |
| | | 165 | | protected override Stream CreateContentReadStream(CancellationToken cancellationToken) |
| | 0 | 166 | | { |
| | 0 | 167 | | ValueTask<Stream> task = CreateContentReadStreamAsyncCore(async: false, cancellationToken); |
| | 0 | 168 | | Debug.Assert(task.IsCompleted); |
| | 0 | 169 | | return task.GetAwaiter().GetResult(); |
| | 0 | 170 | | } |
| | | 171 | | |
| | | 172 | | protected override Task<Stream> CreateContentReadStreamAsync(CancellationToken cancellationToken) => |
| | 0 | 173 | | CreateContentReadStreamAsyncCore(async: true, cancellationToken).AsTask(); |
| | | 174 | | |
| | | 175 | | private async ValueTask<Stream> CreateContentReadStreamAsyncCore(bool async, CancellationToken cancellationT |
| | 0 | 176 | | { |
| | 0 | 177 | | if (_contentConsumed) |
| | 0 | 178 | | { |
| | 0 | 179 | | throw new InvalidOperationException(SR.net_http_content_stream_already_read); |
| | | 180 | | } |
| | | 181 | | |
| | 0 | 182 | | _contentConsumed = true; |
| | | 183 | | |
| | | 184 | | Stream originalStream; |
| | 0 | 185 | | if (async) |
| | 0 | 186 | | { |
| | 0 | 187 | | originalStream = _originalContent.TryReadAsStream() ?? await _originalContent.ReadAsStreamAsync(canc |
| | 0 | 188 | | } |
| | | 189 | | else |
| | 0 | 190 | | { |
| | 0 | 191 | | originalStream = _originalContent.ReadAsStream(cancellationToken); |
| | 0 | 192 | | } |
| | 0 | 193 | | return GetDecompressedStream(originalStream); |
| | 0 | 194 | | } |
| | | 195 | | |
| | | 196 | | internal override Stream? TryCreateContentReadStream() |
| | 0 | 197 | | { |
| | 0 | 198 | | Stream? originalStream = _originalContent.TryReadAsStream(); |
| | 0 | 199 | | return originalStream is null ? null : GetDecompressedStream(originalStream); |
| | 0 | 200 | | } |
| | | 201 | | |
| | | 202 | | protected internal override bool TryComputeLength(out long length) |
| | 0 | 203 | | { |
| | 0 | 204 | | length = 0; |
| | 0 | 205 | | return false; |
| | 0 | 206 | | } |
| | | 207 | | |
| | 0 | 208 | | internal override bool AllowDuplex => false; |
| | | 209 | | |
| | | 210 | | protected override void Dispose(bool disposing) |
| | 0 | 211 | | { |
| | 0 | 212 | | if (disposing) |
| | 0 | 213 | | { |
| | 0 | 214 | | _originalContent.Dispose(); |
| | 0 | 215 | | } |
| | 0 | 216 | | base.Dispose(disposing); |
| | 0 | 217 | | } |
| | | 218 | | } |
| | | 219 | | |
| | 0 | 220 | | private sealed class GZipDecompressedContent(HttpContent originalContent, string[] contentEncodings) : Decompres |
| | | 221 | | { |
| | | 222 | | protected override Stream GetDecompressedStream(Stream originalStream) => |
| | 0 | 223 | | new GZipStream(originalStream, CompressionMode.Decompress); |
| | | 224 | | } |
| | | 225 | | |
| | 0 | 226 | | private sealed class DeflateDecompressedContent(HttpContent originalContent, string[] contentEncodings) : Decomp |
| | | 227 | | { |
| | | 228 | | protected override Stream GetDecompressedStream(Stream originalStream) => |
| | 0 | 229 | | new ZLibOrDeflateStream(originalStream); |
| | | 230 | | |
| | | 231 | | /// <summary>Stream that wraps either <see cref="ZLibStream"/> or <see cref="DeflateStream"/> for decompress |
| | | 232 | | private sealed class ZLibOrDeflateStream : HttpBaseStream |
| | | 233 | | { |
| | | 234 | | // As described in RFC 2616, the deflate content-coding is the "zlib" format (RFC 1950) in combination w |
| | | 235 | | // the "deflate" compression algorithm (RFC 1951). Thus, the right stream to use here is ZLibStream. Ho |
| | | 236 | | // some servers incorrectly interpret "deflate" to mean the raw, unwrapped deflate protocol. To account |
| | | 237 | | // that, this switches between using ZLibStream (correct) and DeflateStream (incorrect) in order to maxi |
| | | 238 | | // compatibility with servers. |
| | | 239 | | |
| | | 240 | | private readonly PeekFirstByteReadStream _stream; |
| | | 241 | | private Stream? _decompressionStream; |
| | | 242 | | |
| | 0 | 243 | | public ZLibOrDeflateStream(Stream stream) => _stream = new PeekFirstByteReadStream(stream); |
| | | 244 | | |
| | | 245 | | protected override void Dispose(bool disposing) |
| | 0 | 246 | | { |
| | 0 | 247 | | if (disposing) |
| | 0 | 248 | | { |
| | 0 | 249 | | _decompressionStream?.Dispose(); |
| | 0 | 250 | | _stream.Dispose(); |
| | 0 | 251 | | } |
| | 0 | 252 | | base.Dispose(disposing); |
| | 0 | 253 | | } |
| | | 254 | | |
| | 0 | 255 | | public override bool CanRead => true; |
| | 0 | 256 | | public override bool CanWrite => false; |
| | 0 | 257 | | public override ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken) = |
| | | 258 | | |
| | | 259 | | // On the first read request, peek at the first nibble of the response. If it's an 8, use ZLibStream, ot |
| | | 260 | | // use DeflateStream. This heuristic works because we're deciding only between raw deflate and zlib wrap |
| | | 261 | | // deflate, in which case the first nibble will always be 8 for zlib and never be 8 for deflate. |
| | | 262 | | // https://stackoverflow.com/a/37528114 provides an explanation for why. |
| | | 263 | | |
| | | 264 | | public override int Read(Span<byte> buffer) |
| | 0 | 265 | | { |
| | 0 | 266 | | if (_decompressionStream is null) |
| | 0 | 267 | | { |
| | 0 | 268 | | int firstByte = _stream.PeekFirstByte(); |
| | 0 | 269 | | _decompressionStream = CreateDecompressionStream(firstByte, _stream); |
| | 0 | 270 | | } |
| | | 271 | | |
| | 0 | 272 | | return _decompressionStream.Read(buffer); |
| | 0 | 273 | | } |
| | | 274 | | |
| | | 275 | | public override ValueTask<int> ReadAsync(Memory<byte> buffer, CancellationToken cancellationToken) |
| | 0 | 276 | | { |
| | 0 | 277 | | if (_decompressionStream is null) |
| | 0 | 278 | | { |
| | 0 | 279 | | return CreateAndReadAsync(this, buffer, cancellationToken); |
| | | 280 | | |
| | | 281 | | static async ValueTask<int> CreateAndReadAsync(ZLibOrDeflateStream thisRef, Memory<byte> buffer, |
| | 0 | 282 | | { |
| | 0 | 283 | | int firstByte = await thisRef._stream.PeekFirstByteAsync(cancellationToken).ConfigureAwait(f |
| | 0 | 284 | | thisRef._decompressionStream = CreateDecompressionStream(firstByte, thisRef._stream); |
| | 0 | 285 | | return await thisRef._decompressionStream.ReadAsync(buffer, cancellationToken).ConfigureAwai |
| | 0 | 286 | | } |
| | | 287 | | } |
| | | 288 | | |
| | 0 | 289 | | return _decompressionStream.ReadAsync(buffer, cancellationToken); |
| | 0 | 290 | | } |
| | | 291 | | |
| | | 292 | | public override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken |
| | 0 | 293 | | { |
| | 0 | 294 | | ValidateCopyToArguments(destination, bufferSize); |
| | 0 | 295 | | return Core(destination, bufferSize, cancellationToken); |
| | | 296 | | async Task Core(Stream destination, int bufferSize, CancellationToken cancellationToken) |
| | 0 | 297 | | { |
| | 0 | 298 | | if (_decompressionStream is null) |
| | 0 | 299 | | { |
| | 0 | 300 | | int firstByte = await _stream.PeekFirstByteAsync(cancellationToken).ConfigureAwait(false); |
| | 0 | 301 | | _decompressionStream = CreateDecompressionStream(firstByte, _stream); |
| | 0 | 302 | | } |
| | | 303 | | |
| | 0 | 304 | | await _decompressionStream.CopyToAsync(destination, bufferSize, cancellationToken).ConfigureAwai |
| | 0 | 305 | | } |
| | 0 | 306 | | } |
| | | 307 | | |
| | | 308 | | private static Stream CreateDecompressionStream(int firstByte, Stream stream) => |
| | 0 | 309 | | (firstByte & 0xF) == 8 ? |
| | 0 | 310 | | new ZLibStream(stream, CompressionMode.Decompress) : |
| | 0 | 311 | | new DeflateStream(stream, CompressionMode.Decompress); |
| | | 312 | | |
| | | 313 | | private sealed class PeekFirstByteReadStream : HttpBaseStream |
| | | 314 | | { |
| | | 315 | | private readonly Stream _stream; |
| | | 316 | | private byte _firstByte; |
| | | 317 | | private FirstByteStatus _firstByteStatus; |
| | | 318 | | |
| | 0 | 319 | | public PeekFirstByteReadStream(Stream stream) => _stream = stream; |
| | | 320 | | |
| | | 321 | | protected override void Dispose(bool disposing) |
| | 0 | 322 | | { |
| | 0 | 323 | | if (disposing) |
| | 0 | 324 | | { |
| | 0 | 325 | | _stream.Dispose(); |
| | 0 | 326 | | } |
| | 0 | 327 | | base.Dispose(disposing); |
| | 0 | 328 | | } |
| | | 329 | | |
| | 0 | 330 | | public override bool CanRead => true; |
| | 0 | 331 | | public override bool CanWrite => false; |
| | 0 | 332 | | public override ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToke |
| | | 333 | | |
| | | 334 | | public int PeekFirstByte() |
| | 0 | 335 | | { |
| | 0 | 336 | | Debug.Assert(_firstByteStatus == FirstByteStatus.None); |
| | | 337 | | |
| | 0 | 338 | | int value = _stream.ReadByte(); |
| | 0 | 339 | | if (value == -1) |
| | 0 | 340 | | { |
| | 0 | 341 | | _firstByteStatus = FirstByteStatus.Consumed; |
| | 0 | 342 | | return -1; |
| | | 343 | | } |
| | | 344 | | |
| | 0 | 345 | | _firstByte = (byte)value; |
| | 0 | 346 | | _firstByteStatus = FirstByteStatus.Available; |
| | 0 | 347 | | return value; |
| | 0 | 348 | | } |
| | | 349 | | |
| | | 350 | | public async ValueTask<int> PeekFirstByteAsync(CancellationToken cancellationToken) |
| | 0 | 351 | | { |
| | 0 | 352 | | Debug.Assert(_firstByteStatus == FirstByteStatus.None); |
| | | 353 | | |
| | 0 | 354 | | var buffer = new byte[1]; |
| | | 355 | | |
| | 0 | 356 | | int bytesRead = await _stream.ReadAsync(buffer, cancellationToken).ConfigureAwait(false); |
| | 0 | 357 | | if (bytesRead == 0) |
| | 0 | 358 | | { |
| | 0 | 359 | | _firstByteStatus = FirstByteStatus.Consumed; |
| | 0 | 360 | | return -1; |
| | | 361 | | } |
| | | 362 | | |
| | 0 | 363 | | _firstByte = buffer[0]; |
| | 0 | 364 | | _firstByteStatus = FirstByteStatus.Available; |
| | 0 | 365 | | return buffer[0]; |
| | 0 | 366 | | } |
| | | 367 | | |
| | | 368 | | public override int Read(Span<byte> buffer) |
| | 0 | 369 | | { |
| | 0 | 370 | | if (_firstByteStatus == FirstByteStatus.Available) |
| | 0 | 371 | | { |
| | 0 | 372 | | if (buffer.Length != 0) |
| | 0 | 373 | | { |
| | 0 | 374 | | buffer[0] = _firstByte; |
| | 0 | 375 | | _firstByteStatus = FirstByteStatus.Consumed; |
| | 0 | 376 | | return 1; |
| | | 377 | | } |
| | | 378 | | |
| | 0 | 379 | | return 0; |
| | | 380 | | } |
| | | 381 | | |
| | 0 | 382 | | Debug.Assert(_firstByteStatus == FirstByteStatus.Consumed); |
| | 0 | 383 | | return _stream.Read(buffer); |
| | 0 | 384 | | } |
| | | 385 | | |
| | | 386 | | public override ValueTask<int> ReadAsync(Memory<byte> buffer, CancellationToken cancellationToken) |
| | 0 | 387 | | { |
| | 0 | 388 | | if (_firstByteStatus == FirstByteStatus.Available) |
| | 0 | 389 | | { |
| | 0 | 390 | | if (buffer.Length != 0) |
| | 0 | 391 | | { |
| | 0 | 392 | | buffer.Span[0] = _firstByte; |
| | 0 | 393 | | _firstByteStatus = FirstByteStatus.Consumed; |
| | 0 | 394 | | return new ValueTask<int>(1); |
| | | 395 | | } |
| | | 396 | | |
| | 0 | 397 | | return new ValueTask<int>(0); |
| | | 398 | | } |
| | | 399 | | |
| | 0 | 400 | | Debug.Assert(_firstByteStatus == FirstByteStatus.Consumed); |
| | 0 | 401 | | return _stream.ReadAsync(buffer, cancellationToken); |
| | 0 | 402 | | } |
| | | 403 | | |
| | | 404 | | public override async Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancell |
| | 0 | 405 | | { |
| | 0 | 406 | | Debug.Assert(_firstByteStatus != FirstByteStatus.None); |
| | | 407 | | |
| | 0 | 408 | | ValidateCopyToArguments(destination, bufferSize); |
| | 0 | 409 | | if (_firstByteStatus == FirstByteStatus.Available) |
| | 0 | 410 | | { |
| | 0 | 411 | | await destination.WriteAsync(new byte[] { _firstByte }, cancellationToken).ConfigureAwait(fa |
| | 0 | 412 | | _firstByteStatus = FirstByteStatus.Consumed; |
| | 0 | 413 | | } |
| | | 414 | | |
| | 0 | 415 | | await _stream.CopyToAsync(destination, bufferSize, cancellationToken).ConfigureAwait(false); |
| | 0 | 416 | | } |
| | | 417 | | |
| | | 418 | | private enum FirstByteStatus : byte |
| | | 419 | | { |
| | | 420 | | None = 0, |
| | | 421 | | Available = 1, |
| | | 422 | | Consumed = 2 |
| | | 423 | | } |
| | | 424 | | } |
| | | 425 | | } |
| | | 426 | | } |
| | | 427 | | |
| | 0 | 428 | | private sealed class BrotliDecompressedContent(HttpContent originalContent, string[] contentEncodings) : Decompr |
| | | 429 | | { |
| | | 430 | | protected override Stream GetDecompressedStream(Stream originalStream) => |
| | 0 | 431 | | new BrotliStream(originalStream, CompressionMode.Decompress); |
| | | 432 | | } |
| | | 433 | | } |
| | | 434 | | } |