From 9c1e771af5c89142c1e80f5eddce6f1de8e3fa16 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 20 Apr 2013 15:33:20 -0400 Subject: [PATCH] refactored GetMemoryStream to use Get --- .../HttpClientManager/HttpClientManager.cs | 51 ++----------------- 1 file changed, 4 insertions(+), 47 deletions(-) diff --git a/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs b/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs index e605910cc..1b1d37ff2 100644 --- a/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs +++ b/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs @@ -363,68 +363,25 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager cancellationToken.ThrowIfCancellationRequested(); - var message = new HttpRequestMessage(HttpMethod.Get, url); - - if (resourcePool != null) - { - await resourcePool.WaitAsync(cancellationToken).ConfigureAwait(false); - } + _logger.Info("HttpClientManager.GetMemoryStream url: {0}", url); var ms = new MemoryStream(); - _logger.Info("HttpClientManager.GetMemoryStream url: {0}", url); - try { - cancellationToken.ThrowIfCancellationRequested(); - - using (var response = await GetHttpClient(GetHostFromUrl(url)).SendAsync(message, HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false)) + using (var stream = await Get(url, resourcePool, cancellationToken).ConfigureAwait(false)) { - EnsureSuccessStatusCode(response); - - cancellationToken.ThrowIfCancellationRequested(); - - using (var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false)) - { - await stream.CopyToAsync(ms, StreamDefaults.DefaultCopyToBufferSize, cancellationToken).ConfigureAwait(false); - } - - cancellationToken.ThrowIfCancellationRequested(); + await stream.CopyToAsync(ms, StreamDefaults.DefaultCopyToBufferSize, cancellationToken).ConfigureAwait(false); } - ms.Position = 0; - return ms; } - catch (OperationCanceledException ex) + catch { ms.Dispose(); - throw GetCancellationException(url, cancellationToken, ex); - } - catch (HttpRequestException ex) - { - _logger.ErrorException("Error getting response from " + url, ex); - - ms.Dispose(); - - throw new HttpException(ex.Message, ex); - } - catch (Exception ex) - { - _logger.ErrorException("Error getting response from " + url, ex); - - ms.Dispose(); - throw; } - finally - { - if (resourcePool != null) - { - resourcePool.Release(); - } - } } ///