Merge pull request #1562 from Bond-009/buffered

Don't copy the complete response stream
pull/1568/head
Anthony Lavado 5 years ago committed by GitHub
commit 80145cd5a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -284,47 +284,24 @@ namespace Emby.Server.Implementations.HttpClientManager
options.CancellationToken.ThrowIfCancellationRequested(); options.CancellationToken.ThrowIfCancellationRequested();
if (!options.BufferContent) var response = await client.SendAsync(
{ httpWebRequest,
var response = await client.SendAsync(httpWebRequest, HttpCompletionOption.ResponseHeadersRead, options.CancellationToken).ConfigureAwait(false); options.BufferContent ? HttpCompletionOption.ResponseContentRead : HttpCompletionOption.ResponseHeadersRead,
options.CancellationToken).ConfigureAwait(false);
await EnsureSuccessStatusCode(response, options).ConfigureAwait(false);
options.CancellationToken.ThrowIfCancellationRequested(); await EnsureSuccessStatusCode(response, options).ConfigureAwait(false);
var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false); options.CancellationToken.ThrowIfCancellationRequested();
return new HttpResponseInfo(response.Headers, response.Content.Headers)
{
Content = stream,
StatusCode = response.StatusCode,
ContentType = response.Content.Headers.ContentType?.MediaType,
ContentLength = response.Content.Headers.ContentLength,
ResponseUrl = response.Content.Headers.ContentLocation?.ToString()
};
}
using (var response = await client.SendAsync(httpWebRequest, HttpCompletionOption.ResponseHeadersRead, options.CancellationToken).ConfigureAwait(false)) var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
return new HttpResponseInfo(response.Headers, response.Content.Headers)
{ {
await EnsureSuccessStatusCode(response, options).ConfigureAwait(false); Content = stream,
StatusCode = response.StatusCode,
options.CancellationToken.ThrowIfCancellationRequested(); ContentType = response.Content.Headers.ContentType?.MediaType,
ContentLength = response.Content.Headers.ContentLength,
using (var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false)) ResponseUrl = response.Content.Headers.ContentLocation?.ToString()
{ };
var memoryStream = new MemoryStream();
await stream.CopyToAsync(memoryStream, StreamDefaults.DefaultCopyToBufferSize, options.CancellationToken).ConfigureAwait(false);
memoryStream.Position = 0;
return new HttpResponseInfo(response.Headers, response.Content.Headers)
{
Content = memoryStream,
StatusCode = response.StatusCode,
ContentType = response.Content.Headers.ContentType?.MediaType,
ContentLength = memoryStream.Length,
ResponseUrl = response.Content.Headers.ContentLocation?.ToString()
};
}
}
} }
public Task<HttpResponseInfo> Post(HttpRequestOptions options) public Task<HttpResponseInfo> Post(HttpRequestOptions options)

Loading…
Cancel
Save