From 22730746eb5242fa71de34f35898c031e7a565de Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 25 Mar 2016 01:39:49 -0400 Subject: ipv6 update --- .../HttpClientManager/HttpClientManager.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs') diff --git a/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs b/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs index c30cdf1a7..f9dbd766f 100644 --- a/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs +++ b/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs @@ -126,6 +126,23 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager } } + private void AddIpv4Option(HttpWebRequest request, HttpRequestOptions options) + { + if (!options.PreferIpv4) + { + return; + } + + request.ServicePoint.BindIPEndPointDelegate = (servicePount, remoteEndPoint, retryCount) => + { + if (remoteEndPoint.AddressFamily == AddressFamily.InterNetwork) + { + return new IPEndPoint(IPAddress.Any, 0); + } + throw new InvalidOperationException("no IPv4 address"); + }; + } + private WebRequest GetRequest(HttpRequestOptions options, string method, bool enableHttpCompression) { var request = CreateWebRequest(options.Url); @@ -133,6 +150,8 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager if (httpWebRequest != null) { + AddIpv4Option(httpWebRequest, options); + AddRequestHeaders(httpWebRequest, options); httpWebRequest.AutomaticDecompression = enableHttpCompression ? DecompressionMethods.Deflate : DecompressionMethods.None; -- cgit v1.2.3