public void PacTest(string url) { using var service = new ProxyService { AutoConfigUrl = url }; var old = service.Query(); var idn = new IdnMapping(); try { Assert.IsTrue(service.Pac()); var status = service.Query(); Assert.IsTrue(status.IsDirect); Assert.IsFalse(status.IsProxy); Assert.IsTrue(status.IsAutoProxyUrl); Assert.IsFalse(status.IsAutoDetect); Assert.AreEqual(service.AutoConfigUrl.Replace(@"中文.cn", idn.GetAscii(@"中文.cn")), status.AutoConfigUrl); } finally { Assert.IsTrue(service.Set(old)); Assert.AreEqual(old, service.Query()); } }
public static void InitPACServer(string address) { try { if (!pacList.ContainsKey(address)) { pacList.Add(address, GetPacList(address)); } string prefixes = string.Format("http://{0}:{1}/pac/", address, Global.Settings.Pac_Port); HttpWebServer ws = new HttpWebServer(SendResponse, prefixes); ws.Run(); if (!httpWebServer.ContainsKey(address) && ws != null) { httpWebServer.Add(address, ws); } Global.Settings.Pac_Url = GetPacUrl(); using var service = new ProxyService { AutoConfigUrl = Global.Settings.Pac_Url }; service.Pac(); Logging.Info(service.Set(service.Query()) + ""); Logging.Info($"Webserver InitServer OK: {Global.Settings.Pac_Url}"); } catch (Exception ex) { Logging.Error("Webserver InitServer " + ex.Message); } }
public static void Update(Configuration config, PACServer pacSrv) { var sysProxyMode = config.SysProxyMode; if (sysProxyMode == ProxyMode.NoModify) { Restore(); return; } try { using var proxy = new ProxyService(); switch (sysProxyMode) { case ProxyMode.Direct: { proxy.Direct(); break; } case ProxyMode.Pac: { proxy.AutoConfigUrl = pacSrv.PacUrl; proxy.Pac(); break; } case ProxyMode.Global: { proxy.Server = $@"localhost:{config.LocalPort}"; proxy.Bypass = string.Join(@";", ProxyService.LanIp); proxy.Global(); break; } default: { Restore(); break; } } } catch (Exception e) { Logging.LogUsefulException(e); } }