protected async Task <HttpContent> ReadBody(TestContext ctx, HttpStreamReader reader, bool readNonChunked, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); if (TransferEncoding != null) { if (!TransferEncoding.Equals("chunked")) { throw new InvalidOperationException(); } if (readNonChunked) { return(await ChunkedContent.ReadNonChunked(reader, cancellationToken)); } return(await ChunkedContent.Read(ctx, reader, cancellationToken)); } if (ContentType != null && ContentType.Equals("application/octet-stream")) { return(await BinaryContent.Read(reader, ContentLength.Value, cancellationToken)); } if (ContentLength != null) { return(await StringContent.Read(ctx, reader, ContentLength.Value, cancellationToken)); } return(null); }
public GZipContent(ChunkedContent chunked) { chunks = new List <byte[]> (); foreach (var chunk in chunked.CopyChunks()) { chunks.Add(chunk); } Compress(); }
public override async Task WriteToAsync(TestContext ctx, Stream stream, CancellationToken cancellationToken) { for (int i = 0; i < compressed.Count; i++) { if (HasLength) { await stream.WriteAsync(compressed[i], cancellationToken).ConfigureAwait(false); } else { await ChunkedContent.WriteChunk(stream, compressed [i], cancellationToken).ConfigureAwait(false); } } if (!HasLength) { await ChunkedContent.WriteChunkTrailer(stream, cancellationToken).ConfigureAwait(false); } }
async Task DoReadBody() { if (hasBody) { return; } hasBody = true; string contentType = null; string transferEncoding = null; int? contentLength = null; string value; if (Headers.TryGetValue("Content-Type", out value)) { contentType = value; } if (Headers.TryGetValue("Transfer-Encoding", out value)) { transferEncoding = value; } if (Headers.TryGetValue("Content-Length", out value)) { contentLength = int.Parse(value); } if (contentType != null && contentType.Equals("application/octet-stream")) { body = await BinaryContent.Read(reader, contentLength.Value); } else if (contentLength != null) { body = await StringContent.Read(reader, contentLength.Value); } else if (transferEncoding != null) { if (!transferEncoding.Equals("chunked")) { throw new InvalidOperationException(); } body = await ChunkedContent.Read(reader); } }