From b762c8046a86a4c56980db73e9a6c4c2cdc80bff Mon Sep 17 00:00:00 2001 From: Gang Zhuo Date: Fri, 20 Mar 2015 21:14:27 +0800 Subject: [PATCH] Direct set the system PAC to the online PAC URL --- shadowsocks-csharp/Controller/PACServer.cs | 29 +------------------- shadowsocks-csharp/Controller/SystemProxy.cs | 7 ++++- 2 files changed, 7 insertions(+), 29 deletions(-) diff --git a/shadowsocks-csharp/Controller/PACServer.cs b/shadowsocks-csharp/Controller/PACServer.cs index b987e84d..e193d9b4 100755 --- a/shadowsocks-csharp/Controller/PACServer.cs +++ b/shadowsocks-csharp/Controller/PACServer.cs @@ -71,10 +71,7 @@ namespace Shadowsocks.Controller } if (hostMatch && pathMatch) { - if (_config.useOnlinePac && !string.IsNullOrEmpty(_config.pacUrl)) - RedirectToOnlinePAC(firstPacket, length, socket, useSocks); - else - SendResponse(firstPacket, length, socket, useSocks); + SendResponse(firstPacket, length, socket, useSocks); return true; } return false; @@ -124,30 +121,6 @@ namespace Shadowsocks.Controller } } - private void RedirectToOnlinePAC(byte[] firstPacket, int length, Socket socket, bool useSocks) - { - try - { - string friendlyMessage = "Redirect to online pac " + _config.pacUrl; - string text = String.Format(@"HTTP/1.1 302 Found -Server: Shadowsocks -Content-Type: text/html; charset=utf-8 -Location: {0} -Content-Length: {1} -Connection: Close - -", _config.pacUrl, System.Text.Encoding.UTF8.GetBytes(friendlyMessage).Length) + friendlyMessage; - byte[] response = System.Text.Encoding.UTF8.GetBytes(text); - socket.BeginSend(response, 0, response.Length, 0, new AsyncCallback(SendCallback), socket); - Util.Utils.ReleaseMemory(); - } - catch (Exception e) - { - Console.WriteLine(e); - socket.Close(); - } - } - public void SendResponse(byte[] firstPacket, int length, Socket socket, bool useSocks) { try diff --git a/shadowsocks-csharp/Controller/SystemProxy.cs b/shadowsocks-csharp/Controller/SystemProxy.cs index dfbc4bc1..5fe8a244 100755 --- a/shadowsocks-csharp/Controller/SystemProxy.cs +++ b/shadowsocks-csharp/Controller/SystemProxy.cs @@ -49,9 +49,14 @@ namespace Shadowsocks.Controller } else { + string pacUrl; + if (config.useOnlinePac && !string.IsNullOrEmpty(config.pacUrl)) + pacUrl = config.pacUrl; + else + pacUrl = "http://127.0.0.1:" + config.localPort.ToString() + "/pac?t=" + GetTimestamp(DateTime.Now); registry.SetValue("ProxyEnable", 0); registry.SetValue("ProxyServer", ""); - registry.SetValue("AutoConfigURL", "http://127.0.0.1:" + config.localPort.ToString() + "/pac?t=" + GetTimestamp(DateTime.Now)); + registry.SetValue("AutoConfigURL", pacUrl); } } else