From 7e5bdc837a95067b304872c3a757e39e434adaba Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 20 Jul 2013 17:36:59 -0400 Subject: added GetTempFileResponse --- .../HttpClientManager/HttpClientManager.cs | 28 +++++++++++++++------- 1 file changed, 20 insertions(+), 8 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 d664d0bba..82c385522 100644 --- a/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs +++ b/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs @@ -374,6 +374,13 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager /// /// public async Task GetTempFile(HttpRequestOptions options) + { + var response = await GetTempFileResponse(options).ConfigureAwait(false); + + return response.TempFilePath; + } + + public async Task GetTempFileResponse(HttpRequestOptions options) { ValidateParams(options.Url, options.CancellationToken); @@ -433,13 +440,20 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager options.Progress.Report(100); - options.CancellationToken.ThrowIfCancellationRequested(); + return new HttpResponseInfo + { + TempFilePath = tempFile, + + StatusCode = response.StatusCode, + + ContentType = response.Content.Headers.ContentType.MediaType + }; } } } catch (Exception ex) { - HandleTempFileException(ex, options, tempFile); + throw GetTempFileException(ex, options, tempFile); } finally { @@ -448,8 +462,6 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager options.ResourcePool.Release(); } } - - return tempFile; } /// @@ -501,7 +513,7 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager /// The temp file. /// Task. /// - private void HandleTempFileException(Exception ex, HttpRequestOptions options, string tempFile) + private Exception GetTempFileException(Exception ex, HttpRequestOptions options, string tempFile) { var operationCanceledException = ex as OperationCanceledException; @@ -513,7 +525,7 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager File.Delete(tempFile); } - throw GetCancellationException(options.Url, options.CancellationToken, operationCanceledException); + return GetCancellationException(options.Url, options.CancellationToken, operationCanceledException); } _logger.ErrorException("Error getting response from " + options.Url, ex); @@ -528,10 +540,10 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager if (httpRequestException != null) { - throw new HttpException(ex.Message, ex); + return new HttpException(ex.Message, ex); } - throw ex; + return ex; } /// -- cgit v1.2.3