aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Common.Implementations/HttpClientManager
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2013-05-22 08:45:03 -0400
committerLuke Pulverenti <luke.pulverenti@gmail.com>2013-05-22 08:45:03 -0400
commit07b7ab9a0b64d51646addc9a2a75189c2981a854 (patch)
tree02b7c251fd5f3e0b2b1f3fb4995ca5c0a1ceda3b /MediaBrowser.Common.Implementations/HttpClientManager
parent3cd8d64784dafff2d13ec00ec9baf4589418f1a3 (diff)
possible timeout fix
Diffstat (limited to 'MediaBrowser.Common.Implementations/HttpClientManager')
-rw-r--r--MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs127
1 files changed, 63 insertions, 64 deletions
diff --git a/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs b/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs
index 99ce17ebd..d01c9e205 100644
--- a/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs
+++ b/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs
@@ -160,90 +160,89 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
options.CancellationToken.ThrowIfCancellationRequested();
- using (var message = GetHttpRequestMessage(options))
- {
- //if (options.EnableResponseCache && cachedInfo != null)
- //{
- // if (!string.IsNullOrEmpty(cachedInfo.Etag))
- // {
- // message.Headers.Add("If-None-Match", cachedInfo.Etag);
- // }
- // else if (cachedInfo.LastModified.HasValue)
- // {
- // message.Headers.IfModifiedSince = new DateTimeOffset(cachedInfo.LastModified.Value);
- // }
- //}
+ var message = GetHttpRequestMessage(options);
+
+ //if (options.EnableResponseCache && cachedInfo != null)
+ //{
+ // if (!string.IsNullOrEmpty(cachedInfo.Etag))
+ // {
+ // message.Headers.Add("If-None-Match", cachedInfo.Etag);
+ // }
+ // else if (cachedInfo.LastModified.HasValue)
+ // {
+ // message.Headers.IfModifiedSince = new DateTimeOffset(cachedInfo.LastModified.Value);
+ // }
+ //}
- if (options.ResourcePool != null)
- {
- await options.ResourcePool.WaitAsync(options.CancellationToken).ConfigureAwait(false);
- }
+ if (options.ResourcePool != null)
+ {
+ await options.ResourcePool.WaitAsync(options.CancellationToken).ConfigureAwait(false);
+ }
- _logger.Info("HttpClientManager.Get url: {0}", options.Url);
+ _logger.Info("HttpClientManager.Get url: {0}", options.Url);
- try
- {
- options.CancellationToken.ThrowIfCancellationRequested();
+ try
+ {
+ options.CancellationToken.ThrowIfCancellationRequested();
- var response = await GetHttpClient(GetHostFromUrl(options.Url), options.EnableHttpCompression).SendAsync(message, HttpCompletionOption.ResponseHeadersRead, options.CancellationToken).ConfigureAwait(false);
+ var response = await GetHttpClient(GetHostFromUrl(options.Url), options.EnableHttpCompression).SendAsync(message, HttpCompletionOption.ResponseHeadersRead, options.CancellationToken).ConfigureAwait(false);
- if (options.EnableResponseCache)
+ if (options.EnableResponseCache)
+ {
+ if (response.StatusCode != HttpStatusCode.NotModified)
{
- if (response.StatusCode != HttpStatusCode.NotModified)
- {
- EnsureSuccessStatusCode(response);
- }
-
- options.CancellationToken.ThrowIfCancellationRequested();
-
- cachedInfo = UpdateInfoCache(cachedInfo, options.Url, cachedInfoPath, response);
+ EnsureSuccessStatusCode(response);
+ }
- if (response.StatusCode == HttpStatusCode.NotModified)
- {
- _logger.Debug("Server indicates not modified for {0}. Returning cached result.", options.Url);
+ options.CancellationToken.ThrowIfCancellationRequested();
- return GetCachedResponse(cachedReponsePath);
- }
+ cachedInfo = UpdateInfoCache(cachedInfo, options.Url, cachedInfoPath, response);
- if (!string.IsNullOrEmpty(cachedInfo.Etag) || cachedInfo.LastModified.HasValue ||
- (cachedInfo.Expires.HasValue && cachedInfo.Expires.Value > DateTime.UtcNow))
- {
- await UpdateResponseCache(response, cachedReponsePath).ConfigureAwait(false);
+ if (response.StatusCode == HttpStatusCode.NotModified)
+ {
+ _logger.Debug("Server indicates not modified for {0}. Returning cached result.", options.Url);
- return GetCachedResponse(cachedReponsePath);
- }
+ return GetCachedResponse(cachedReponsePath);
}
- else
+
+ if (!string.IsNullOrEmpty(cachedInfo.Etag) || cachedInfo.LastModified.HasValue ||
+ (cachedInfo.Expires.HasValue && cachedInfo.Expires.Value > DateTime.UtcNow))
{
- EnsureSuccessStatusCode(response);
+ await UpdateResponseCache(response, cachedReponsePath).ConfigureAwait(false);
- options.CancellationToken.ThrowIfCancellationRequested();
+ return GetCachedResponse(cachedReponsePath);
}
-
- return await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
}
- catch (OperationCanceledException ex)
+ else
{
- throw GetCancellationException(options.Url, options.CancellationToken, ex);
- }
- catch (HttpRequestException ex)
- {
- _logger.ErrorException("Error getting response from " + options.Url, ex);
+ EnsureSuccessStatusCode(response);
- throw new HttpException(ex.Message, ex);
+ options.CancellationToken.ThrowIfCancellationRequested();
}
- catch (Exception ex)
- {
- _logger.ErrorException("Error getting response from " + options.Url, ex);
- throw;
- }
- finally
+ return await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
+ }
+ catch (OperationCanceledException ex)
+ {
+ throw GetCancellationException(options.Url, options.CancellationToken, ex);
+ }
+ catch (HttpRequestException ex)
+ {
+ _logger.ErrorException("Error getting response from " + options.Url, ex);
+
+ throw new HttpException(ex.Message, ex);
+ }
+ catch (Exception ex)
+ {
+ _logger.ErrorException("Error getting response from " + options.Url, ex);
+
+ throw;
+ }
+ finally
+ {
+ if (options.ResourcePool != null)
{
- if (options.ResourcePool != null)
- {
- options.ResourcePool.Release();
- }
+ options.ResourcePool.Release();
}
}
}