diff --git a/Netch/Utils/HttpProxyHandler/HttpWebServer.cs b/Netch/Utils/HttpProxyHandler/HttpWebServer.cs deleted file mode 100644 index 00ad981a..00000000 --- a/Netch/Utils/HttpProxyHandler/HttpWebServer.cs +++ /dev/null @@ -1,77 +0,0 @@ -using System; -using System.Net; -using System.Text; - -namespace Netch.Utils.HttpProxyHandler -{ - public class HttpWebServer - { - private readonly Func? _responderMethod; - private HttpListener? _listener; - - public HttpWebServer(string[] prefixes, Func method) - { - _listener = new HttpListener(); - - // URI prefixes are required, for example - // "http://localhost:8080/index/". - if (prefixes == null || prefixes.Length == 0) - throw new ArgumentException("prefixes"); - - // A responder method is required - if (method == null) - throw new ArgumentException("method"); - - foreach (var s in prefixes) - _listener.Prefixes.Add(s); - - _responderMethod = method; - _listener.Start(); - } - - public HttpWebServer(Func method, params string[] prefixes) : this(prefixes, method) - { - } - - public void StartWaitingRequest() - { - Logging.Info("Webserver running..."); - while (_listener?.IsListening ?? false) - { - HttpListenerContext ctx; - try - { - ctx = _listener.GetContext(); - } - catch - { - break; - } - - try - { - var rstr = _responderMethod!(ctx.Request); - var buf = Encoding.UTF8.GetBytes(rstr); - ctx.Response.StatusCode = 200; - ctx.Response.ContentType = "application/x-ns-proxy-autoconfig"; - ctx.Response.ContentLength64 = buf.Length; - ctx.Response.OutputStream.Write(buf, 0, buf.Length); - } - finally - { - ctx.Response.OutputStream.Close(); - } - } - } - - public void Stop() - { - if (_listener != null) - { - _listener.Stop(); - _listener.Close(); - _listener = null; - } - } - } -} \ No newline at end of file diff --git a/Netch/Utils/HttpProxyHandler/PACServerHandle.cs b/Netch/Utils/HttpProxyHandler/PACServerHandle.cs deleted file mode 100644 index d4c6451b..00000000 --- a/Netch/Utils/HttpProxyHandler/PACServerHandle.cs +++ /dev/null @@ -1,83 +0,0 @@ -using System; -using System.IO; -using System.Net; -using System.Text; -using System.Threading.Tasks; -using Netch.Controllers; - -namespace Netch.Utils.HttpProxyHandler -{ - /// - /// 提供PAC功能支持 - /// - internal static class PACServerHandle - { - private static HttpWebServer? _httpWebServer; - private static string? _pacContent; - public static readonly string PacPrefix= $"http://127.0.0.1:{Global.Settings.Pac_Port}/pac/"; - - public static string InitPACServer() - { - try - { - _pacContent = GetPacList("127.0.0.1"); - - _httpWebServer = new HttpWebServer(SendResponse, PacPrefix); - Task.Run(() => _httpWebServer.StartWaitingRequest()); - - var pacUrl = GetPacUrl(); - Logging.Info($"Webserver InitServer OK: {pacUrl}"); - return pacUrl; - } - catch - { - Logging.Error("Webserver InitServer Failed"); - throw; - } - } - - public static string SendResponse(HttpListenerRequest request) - { - return _pacContent!; - } - - public static void Stop() - { - try - { - _httpWebServer?.Stop(); - } - catch - { - // ignored - } - - _httpWebServer = null; - } - - private static string GetPacList(string address) - { - try - { - var proxy = $"PROXY {address}:{Global.Settings.HTTPLocalPort};"; - var pacfile = Path.Combine(Global.NetchDir, "bin\\pac.txt"); - - var pac = File.ReadAllText(pacfile, Encoding.UTF8).Replace("__PROXY__", proxy); - return pac; - } - catch - { - throw new MessageException("Pac file not found!"); - } - } - - /// - /// 获取PAC地址 - /// - /// - public static string GetPacUrl() - { - return PacPrefix + $"?t={DateTime.Now:yyyyMMddHHmmssfff}"; - } - } -} \ No newline at end of file diff --git a/binaries b/binaries index b2222285..fd8975b1 160000 --- a/binaries +++ b/binaries @@ -1 +1 @@ -Subproject commit b22222857bc111d8c261642f4e38e83b615bd1ec +Subproject commit fd8975b17014cf34e978a99d1737f98425746678