The Free Software Media System - Server Backend & API
possible timeout fix
Luke Pulverenti07b7ab9a0b64
diff --git a/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs b/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.csindex 99ce17ebdd..d01c9e205d 100644--- a/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs+++ b/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs@@ -160,90 +160,89 @@ namespace MediaBrowser.Common.Implementations.HttpClientManageroptions.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();}}}