diff --git a/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs b/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs
index f4d4826ebf..054c5aaafb 100644
--- a/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs
+++ b/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs
@@ -164,22 +164,9 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
}
}
- //request.ServicePoint.BindIPEndPointDelegate = BindIPEndPointCallback;
-
return request;
}
- private static IPEndPoint BindIPEndPointCallback(ServicePoint servicePoint, IPEndPoint remoteEndPoint, int retryCount)
- {
- // Prefer local ipv4
- if (remoteEndPoint.AddressFamily == AddressFamily.InterNetworkV6)
- {
- return new IPEndPoint(IPAddress.IPv6Any, 0);
- }
-
- return new IPEndPoint(IPAddress.Any, 0);
- }
-
private void AddRequestHeaders(HttpWebRequest request, HttpRequestOptions options)
{
foreach (var header in options.RequestHeaders.ToList())
@@ -199,20 +186,6 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
}
}
- ///
- /// The _semaphoreLocks
- ///
- private readonly ConcurrentDictionary _semaphoreLocks = new ConcurrentDictionary(StringComparer.OrdinalIgnoreCase);
- ///
- /// Gets the lock.
- ///
- /// The filename.
- /// System.Object.
- private SemaphoreSlim GetLock(string url)
- {
- return _semaphoreLocks.GetOrAdd(url, key => new SemaphoreSlim(1, 1));
- }
-
///
/// Gets the response internal.
///
@@ -283,7 +256,7 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
var url = options.Url;
var urlHash = url.ToLower().GetMD5().ToString("N");
-
+
var responseCachePath = Path.Combine(_appPaths.CachePath, "httpclient", urlHash);
response = await GetCachedResponse(responseCachePath, options.CacheLength, url).ConfigureAwait(false);
@@ -292,31 +265,14 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
return response;
}
- var semaphore = GetLock(url);
-
- await semaphore.WaitAsync(options.CancellationToken).ConfigureAwait(false);
+ response = await SendAsyncInternal(options, httpMethod).ConfigureAwait(false);
- try
+ if (response.StatusCode == HttpStatusCode.OK)
{
- response = await GetCachedResponse(responseCachePath, options.CacheLength, url).ConfigureAwait(false);
- if (response != null)
- {
- return response;
- }
-
- response = await SendAsyncInternal(options, httpMethod).ConfigureAwait(false);
-
- if (response.StatusCode == HttpStatusCode.OK)
- {
- await CacheResponse(response, responseCachePath).ConfigureAwait(false);
- }
-
- return response;
- }
- finally
- {
- semaphore.Release();
+ await CacheResponse(response, responseCachePath).ConfigureAwait(false);
}
+
+ return response;
}
private async Task GetCachedResponse(string responseCachePath, TimeSpan cacheLength, string url)
@@ -361,13 +317,12 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
using (var responseStream = response.Content)
{
- using (var fileStream = _fileSystem.GetFileStream(responseCachePath, FileMode.Create, FileAccess.Write, FileShare.Read, true))
- {
- var memoryStream = new MemoryStream();
-
- await responseStream.CopyToAsync(memoryStream).ConfigureAwait(false);
+ var memoryStream = new MemoryStream();
+ await responseStream.CopyToAsync(memoryStream).ConfigureAwait(false);
+ memoryStream.Position = 0;
- memoryStream.Position = 0;
+ using (var fileStream = _fileSystem.GetFileStream(responseCachePath, FileMode.Create, FileAccess.Write, FileShare.None, true))
+ {
await memoryStream.CopyToAsync(fileStream).ConfigureAwait(false);
memoryStream.Position = 0;