- if (WebProxyChanged != null)
- WebProxyChanged(null, e);
+ WebProxyChanged?.Invoke(null, e);
+ }
+
+ private class ForceIPv4Handler : DelegatingHandler
+ {
+ private readonly IPAddress? ipv4Address;
+
+ public ForceIPv4Handler(HttpMessageHandler innerHandler)
+ : base(innerHandler)
+ {
+ foreach (var address in Dns.GetHostAddresses("pbs.twimg.com"))
+ {
+ if (address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
+ this.ipv4Address = address;
+ }
+ }
+
+ protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
+ {
+ if (this.ipv4Address != null)
+ {
+ var requestUri = request.RequestUri;
+ if (requestUri.Host == "pbs.twimg.com")
+ {
+ var rewriteUriStr = requestUri.GetLeftPart(UriPartial.Scheme) + this.ipv4Address + requestUri.PathAndQuery;
+ request.RequestUri = new Uri(rewriteUriStr);
+ request.Headers.Host = "pbs.twimg.com";
+ }
+ }
+
+ return base.SendAsync(request, cancellationToken);
+ }