예제 #1
0
        internal static async Task SetContentAsync(this HttpResponseMessage response,
                                                   IAsyncEnumerator <byte> enumerator,
                                                   CancellationToken cancellationToken)
        {
            // Validate parameters.
            if (response == null)
            {
                throw new ArgumentNullException(nameof(response));
            }
            if (enumerator == null)
            {
                throw new ArgumentNullException(nameof(enumerator));
            }

            // Check the transmission.
            if (response.Headers.TransferEncodingChunked ?? false)
            {
                // Set the content.
                response.Content = await enumerator.ReadHttpContentFromChunkedTransferEncoding(response, cancellationToken).
                                   ConfigureAwait(false);
            }
            else
            {
                // Read the remainder of the content.
                response.Content = await enumerator.ReadHttpContent(response, cancellationToken).
                                   ConfigureAwait(false);
            }
        }