• R/O
  • HTTP
  • SSH
  • HTTPS

open-tween: コミット

開発に使用するリポジトリ


コミットメタ情報

リビジョンe6a1d3ffbc62224d200c2b914fcc4c3c0bc4bde3 (tree)
日時2015-08-11 17:25:52
作者Kimura Youichi <kim.upsilon@bucy...>
コミッターKimura Youichi

ログメッセージ

pbs.twimg.comへの接続にIPv4を強制するコードが意図した動作をしなかったことに対する修正

変更サマリ

差分

--- a/OpenTween/Connection/Networking.cs
+++ b/OpenTween/Connection/Networking.cs
@@ -70,24 +70,10 @@ namespace OpenTween.Connection
7070 if (forceIPv4 == value)
7171 return;
7272
73- if (value)
74- {
75- BindIPEndPoint forceIPv4Delegate = (_, __, ___) => new IPEndPoint(IPAddress.Any, 0);
76-
77- ServicePointManager.FindServicePoint("http://pbs.twimg.com/", proxy)
78- .BindIPEndPointDelegate = forceIPv4Delegate;
79- ServicePointManager.FindServicePoint("https://pbs.twimg.com/", proxy)
80- .BindIPEndPointDelegate = forceIPv4Delegate;
81- }
82- else
83- {
84- ServicePointManager.FindServicePoint("http://pbs.twimg.com/", proxy)
85- .BindIPEndPointDelegate = null;
86- ServicePointManager.FindServicePoint("https://pbs.twimg.com/", proxy)
87- .BindIPEndPointDelegate = null;
88- }
89-
9073 forceIPv4 = value;
74+
75+ // Network.Http を再作成させる
76+ OnWebProxyChanged(EventArgs.Empty);
9177 }
9278 }
9379
@@ -167,7 +153,12 @@ namespace OpenTween.Connection
167153 handler.UseProxy = false;
168154 }
169155
170- var client = new HttpClient(handler);
156+ HttpClient client;
157+ if (ForceIPv4)
158+ client = new HttpClient(new ForceIPv4Handler(handler));
159+ else
160+ client = new HttpClient(handler);
161+
171162 client.Timeout = Networking.DefaultTimeout;
172163 client.DefaultRequestHeaders.Add("User-Agent", Networking.GetUserAgentString());
173164
@@ -201,6 +192,32 @@ namespace OpenTween.Connection
201192 if (WebProxyChanged != null)
202193 WebProxyChanged(null, e);
203194 }
195+
196+ private class ForceIPv4Handler : DelegatingHandler
197+ {
198+ private readonly IPAddress ipv4Address;
199+
200+ public ForceIPv4Handler(HttpMessageHandler innerHandler)
201+ : base(innerHandler)
202+ {
203+ foreach (var address in Dns.GetHostAddresses("pbs.twimg.com"))
204+ if (address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
205+ this.ipv4Address = address;
206+ }
207+
208+ protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
209+ {
210+ var requestUri = request.RequestUri;
211+ if (requestUri.Host == "pbs.twimg.com")
212+ {
213+ var rewriteUriStr = requestUri.GetLeftPart(UriPartial.Scheme) + this.ipv4Address + requestUri.PathAndQuery;
214+ request.RequestUri = new Uri(rewriteUriStr);
215+ request.Headers.Host = "pbs.twimg.com";
216+ }
217+
218+ return base.SendAsync(request, cancellationToken);
219+ }
220+ }
204221 }
205222
206223 public enum ProxyType
旧リポジトリブラウザで表示