From f9503d61d3df3b8abbdbf23a624526aa62bde012 Mon Sep 17 00:00:00 2001
From: ChsBuffer <33744752+chsbuffer@users.noreply.github.com>
Date: Mon, 1 Mar 2021 21:07:14 +0800
Subject: [PATCH] Update HTTPController
---
Netch/Controllers/HTTPController.cs | 24 +++++++++++--------
Netch/Models/Setting.cs | 5 ----
.../Utils/HttpProxyHandler/PACServerHandle.cs | 23 ++++++------------
3 files changed, 21 insertions(+), 31 deletions(-)
diff --git a/Netch/Controllers/HTTPController.cs b/Netch/Controllers/HTTPController.cs
index 4dce0eeb..e880bac0 100644
--- a/Netch/Controllers/HTTPController.cs
+++ b/Netch/Controllers/HTTPController.cs
@@ -25,21 +25,22 @@ namespace Netch.Controllers
PrivoxyController.Start(MainController.Server!);
Global.Job.AddProcess(PrivoxyController.Instance!);
- if (mode.Type is 3 or 5)
+ if (mode.Type is 3)
{
+ using var service = new ProxyService();
+ _oldState = service.Query();
+
if (MainController.Server is Socks5 or Trojan && mode.BypassChina)
{
- PACServerHandle.InitPACServer("127.0.0.1");
+ service.AutoConfigUrl = PACServerHandle.InitPACServer("127.0.0.1");
+
+ service.Pac();
}
else
{
- using var service = new ProxyService
- {
- Server = $"127.0.0.1:{Global.Settings.HTTPLocalPort}",
- Bypass = string.Join(";", ProxyService.LanIp)
- };
+ service.Server = $"127.0.0.1:{Global.Settings.HTTPLocalPort}";
+ service.Bypass = string.Join(";", ProxyService.LanIp);
- _oldState = service.Query();
service.Global();
}
}
@@ -57,8 +58,11 @@ namespace Netch.Controllers
{
PACServerHandle.Stop();
- using var service = new ProxyService();
- service.Set(_oldState!);
+ if (_oldState != null)
+ {
+ using var service = new ProxyService();
+ service.Set(_oldState!);
+ }
})
};
diff --git a/Netch/Models/Setting.cs b/Netch/Models/Setting.cs
index 3e6b3b70..a2c4414e 100644
--- a/Netch/Models/Setting.cs
+++ b/Netch/Models/Setting.cs
@@ -176,11 +176,6 @@ namespace Netch.Models
///
public int Pac_Port { get; set; } = 2803;
- ///
- /// PAC URL
- ///
- public string Pac_Url { get; set; } = "";
-
///
/// 不代理TCP
///
diff --git a/Netch/Utils/HttpProxyHandler/PACServerHandle.cs b/Netch/Utils/HttpProxyHandler/PACServerHandle.cs
index 9b951836..d4e925fc 100644
--- a/Netch/Utils/HttpProxyHandler/PACServerHandle.cs
+++ b/Netch/Utils/HttpProxyHandler/PACServerHandle.cs
@@ -4,7 +4,6 @@ using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Text;
-using WindowsProxy;
namespace Netch.Utils.HttpProxyHandler
{
@@ -16,36 +15,28 @@ namespace Netch.Utils.HttpProxyHandler
private static readonly Hashtable httpWebServer = new();
private static readonly Hashtable pacList = new();
- public static void InitPACServer(string address)
+ public static string InitPACServer(string address)
{
try
{
if (!pacList.ContainsKey(address))
pacList.Add(address, GetPacList(address));
- var prefixes = string.Format("http://{0}:{1}/pac/", address, Global.Settings.Pac_Port);
+ var prefixes = $"http://{address}:{Global.Settings.Pac_Port}/pac/";
var ws = new HttpWebServer(SendResponse, prefixes);
ws.Run();
- if (!httpWebServer.ContainsKey(address) && ws != null)
+ if (!httpWebServer.ContainsKey(address))
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}");
+ var pacUrl = GetPacUrl();
+ Logging.Info($"Webserver InitServer OK: {pacUrl}");
+ return pacUrl;
}
catch (Exception ex)
{
- Logging.Error("Webserver InitServer " + ex.Message);
+ throw new Exception("Webserver InitServer Error:" + ex.Message);
}
}