aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2013-07-20 17:36:59 -0400
committerLuke Pulverenti <luke.pulverenti@gmail.com>2013-07-20 17:36:59 -0400
commit7e5bdc837a95067b304872c3a757e39e434adaba (patch)
tree28fb79ea5d7ce449f003ee479104aa04f029b5f4 /MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs
parentcf057c5b2736f1e25bb1a8f9091c3954311889ab (diff)
added GetTempFileResponse
Diffstat (limited to 'MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs')
-rw-r--r--MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs28
1 files changed, 20 insertions, 8 deletions
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
@@ -375,6 +375,13 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
/// <exception cref="MediaBrowser.Model.Net.HttpException"></exception>
public async Task<string> GetTempFile(HttpRequestOptions options)
{
+ var response = await GetTempFileResponse(options).ConfigureAwait(false);
+
+ return response.TempFilePath;
+ }
+
+ public async Task<HttpResponseInfo> GetTempFileResponse(HttpRequestOptions options)
+ {
ValidateParams(options.Url, options.CancellationToken);
var tempFile = Path.Combine(_appPaths.TempDirectory, Guid.NewGuid() + ".tmp");
@@ -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;
}
/// <summary>
@@ -501,7 +513,7 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
/// <param name="tempFile">The temp file.</param>
/// <returns>Task.</returns>
/// <exception cref="HttpException"></exception>
- 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;
}
/// <summary>