possible timeout fix

pull/702/head
Luke Pulverenti 12 years ago
parent 3cd8d64784
commit 07b7ab9a0b

@ -160,90 +160,89 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
options.CancellationToken.ThrowIfCancellationRequested(); options.CancellationToken.ThrowIfCancellationRequested();
using (var message = GetHttpRequestMessage(options)) var message = GetHttpRequestMessage(options);
{
//if (options.EnableResponseCache && cachedInfo != null) //if (options.EnableResponseCache && cachedInfo != null)
//{ //{
// if (!string.IsNullOrEmpty(cachedInfo.Etag)) // if (!string.IsNullOrEmpty(cachedInfo.Etag))
// { // {
// message.Headers.Add("If-None-Match", cachedInfo.Etag); // message.Headers.Add("If-None-Match", cachedInfo.Etag);
// } // }
// else if (cachedInfo.LastModified.HasValue) // else if (cachedInfo.LastModified.HasValue)
// { // {
// message.Headers.IfModifiedSince = new DateTimeOffset(cachedInfo.LastModified.Value); // message.Headers.IfModifiedSince = new DateTimeOffset(cachedInfo.LastModified.Value);
// } // }
//} //}
if (options.ResourcePool != null) if (options.ResourcePool != null)
{ {
await options.ResourcePool.WaitAsync(options.CancellationToken).ConfigureAwait(false); 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 try
{ {
options.CancellationToken.ThrowIfCancellationRequested(); 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);
{ }
EnsureSuccessStatusCode(response);
}
options.CancellationToken.ThrowIfCancellationRequested();
cachedInfo = UpdateInfoCache(cachedInfo, options.Url, cachedInfoPath, response);
if (response.StatusCode == HttpStatusCode.NotModified) options.CancellationToken.ThrowIfCancellationRequested();
{
_logger.Debug("Server indicates not modified for {0}. Returning cached result.", options.Url);
return GetCachedResponse(cachedReponsePath); cachedInfo = UpdateInfoCache(cachedInfo, options.Url, cachedInfoPath, response);
}
if (!string.IsNullOrEmpty(cachedInfo.Etag) || cachedInfo.LastModified.HasValue || if (response.StatusCode == HttpStatusCode.NotModified)
(cachedInfo.Expires.HasValue && cachedInfo.Expires.Value > DateTime.UtcNow)) {
{ _logger.Debug("Server indicates not modified for {0}. Returning cached result.", options.Url);
await UpdateResponseCache(response, cachedReponsePath).ConfigureAwait(false);
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); EnsureSuccessStatusCode(response);
}
catch (HttpRequestException ex)
{
_logger.ErrorException("Error getting response from " + options.Url, ex);
throw new HttpException(ex.Message, ex); options.CancellationToken.ThrowIfCancellationRequested();
} }
catch (Exception ex)
{
_logger.ErrorException("Error getting response from " + options.Url, ex);
throw; return await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
} }
finally 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();
}
} }
} }
} }

Loading…
Cancel
Save