From 58f1a314b5ef3d13c2bc034f8a8949d9e88d1c20 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 30 Nov 2013 13:32:39 -0500 Subject: update to service stack 3.0.70.0 --- .../HttpClientManager/HttpClientManager.cs | 112 ++++----------------- 1 file changed, 18 insertions(+), 94 deletions(-) (limited to 'MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs') diff --git a/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs b/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs index 8d80185ad..8fccb7c2a 100644 --- a/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs +++ b/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs @@ -27,7 +27,7 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager /// /// When one request to a host times out, we'll ban all other requests for this period of time, to prevent scans from stalling /// - private int TimeoutSeconds = 30; + private const int TimeoutSeconds = 30; /// /// The _logger @@ -42,16 +42,14 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager private readonly IFileSystem _fileSystem; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The app paths. /// The logger. - /// The get HTTP client handler. - /// - /// appPaths + /// The file system. + /// appPaths /// or - /// logger - /// + /// logger public HttpClientManager(IApplicationPaths appPaths, ILogger logger, IFileSystem fileSystem) { if (appPaths == null) @@ -143,7 +141,6 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager /// Gets the response internal. /// /// The options. - /// The HTTP method. /// Task{HttpResponseInfo}. /// /// @@ -490,27 +487,19 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager } catch (OperationCanceledException ex) { - var exception = GetCancellationException(options.Url, options.CancellationToken, ex); - - throw exception; + throw GetTempFileException(ex, options, tempFile); } catch (HttpRequestException ex) { - _logger.ErrorException("Error getting response from " + options.Url, ex); - - throw new HttpException(ex.Message, ex); + throw GetTempFileException(ex, options, tempFile); } catch (WebException ex) { - _logger.ErrorException("Error getting response from " + options.Url, ex); - - throw new HttpException(ex.Message, ex); + throw GetTempFileException(ex, options, tempFile); } catch (Exception ex) { - _logger.ErrorException("Error getting response from " + options.Url, ex); - - throw; + throw GetTempFileException(ex, options, tempFile); } finally { @@ -521,65 +510,6 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager } } - /// - /// Gets the message. - /// - /// The options. - /// HttpResponseMessage. - private HttpRequestMessage GetHttpRequestMessage(HttpRequestOptions options) - { - var message = new HttpRequestMessage(HttpMethod.Get, options.Url); - - foreach (var pair in options.RequestHeaders.ToList()) - { - if (!message.Headers.TryAddWithoutValidation(pair.Key, pair.Value)) - { - _logger.Error("Unable to add request header {0} with value {1}", pair.Key, pair.Value); - } - } - - return message; - } - - /// - /// Gets the length of the content. - /// - /// The response. - /// System.Nullable{System.Int64}. - private long? GetContentLength(HttpResponseMessage response) - { - IEnumerable lengthValues = null; - - // Seeing some InvalidOperationException here under mono - try - { - response.Headers.TryGetValues("content-length", out lengthValues); - } - catch (InvalidOperationException ex) - { - _logger.ErrorException("Error accessing response.Headers.TryGetValues Content-Length", ex); - } - - if (lengthValues == null) - { - try - { - response.Content.Headers.TryGetValues("content-length", out lengthValues); - } - catch (InvalidOperationException ex) - { - _logger.ErrorException("Error accessing response.Content.Headers.TryGetValues Content-Length", ex); - } - } - - if (lengthValues == null) - { - return null; - } - - return long.Parse(string.Join(string.Empty, lengthValues.ToArray()), UsCulture); - } - private long? GetContentLength(HttpWebResponse response) { var length = response.ContentLength; @@ -616,16 +546,23 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager _logger.ErrorException("Error getting response from " + options.Url, ex); - var httpRequestException = ex as HttpRequestException; - // Cleanup DeleteTempFile(tempFile); + var httpRequestException = ex as HttpRequestException; + if (httpRequestException != null) { return new HttpException(ex.Message, ex); } + var webException = ex as WebException; + + if (webException != null) + { + return new HttpException(ex.Message, ex); + } + return ex; } @@ -711,19 +648,6 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager return exception; } - /// - /// Ensures the success status code. - /// - /// The response. - /// - private void EnsureSuccessStatusCode(HttpResponseMessage response) - { - if (!response.IsSuccessStatusCode) - { - throw new HttpException(response.ReasonPhrase) { StatusCode = response.StatusCode }; - } - } - private void EnsureSuccessStatusCode(HttpWebResponse response) { var statusCode = response.StatusCode; -- cgit v1.2.3