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); }
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); } }