diff --git a/ElectronicObserver/Observer/APIObserver.cs b/ElectronicObserver/Observer/APIObserver.cs index 804eaf7b3..de5476fff 100644 --- a/ElectronicObserver/Observer/APIObserver.cs +++ b/ElectronicObserver/Observer/APIObserver.cs @@ -3,7 +3,6 @@ using System.IO; using System.Linq; using System.Net; -using System.Security.Cryptography.X509Certificates; using System.Text; using System.Threading.Channels; using System.Threading.Tasks; @@ -17,7 +16,6 @@ using Titanium.Web.Proxy; using Titanium.Web.Proxy.EventArguments; using Titanium.Web.Proxy.Models; -using static ElectronicObserver.Data.Constants; namespace ElectronicObserver.Observer; @@ -730,9 +728,9 @@ private APIObserver() ConnectionTimeOutSeconds = 15, ReuseSocket = false, EnableConnectionPool = false, - ForwardToUpstreamGateway = true + ForwardToUpstreamGateway = true, }; - Proxy.CertificateManager.RootCertificate = new X509Certificate2(); + Proxy.BeforeRequest += ProxyOnBeforeRequest; Proxy.BeforeResponse += ProxyOnBeforeResponse; @@ -761,19 +759,25 @@ public int Start(int portID, Control uiControl) UIControl = uiControl; - if (Proxy.ProxyRunning) Proxy.Stop(); + if (Proxy.ProxyRunning) + { + Proxy.Stop(); + } try { - Endpoint = new ExplicitProxyEndPoint(IPAddress.Any, portID, false); + Endpoint = new ExplicitProxyEndPoint(IPAddress.Any, portID); Proxy.AddEndPoint(Endpoint); - - Proxy.UpStreamHttpProxy = c switch + + ExternalProxy? upstreamProxy = c switch { - { UseUpstreamProxy: true } => new ExternalProxy(c.UpstreamProxyAddress, c.UpstreamProxyPort), + { UseUpstreamProxy: true } => new(c.UpstreamProxyAddress, c.UpstreamProxyPort), _ => null, }; + Proxy.UpStreamHttpProxy = upstreamProxy; + Proxy.UpStreamHttpsProxy = upstreamProxy; + Proxy.Start(); ProxyPort = portID; @@ -854,7 +858,7 @@ private async Task ProxyOnBeforeResponse(object sender, SessionEventArgs e) string url = body.Split('/')[2]; url = url.Split('\\')[0]; - db.Server = getKCServer(url); + db.Server = Constants.getKCServer(url); } } diff --git a/ElectronicObserver/Window/FormBrowserHost.cs b/ElectronicObserver/Window/FormBrowserHost.cs index de6865dac..5f31b10fc 100644 --- a/ElectronicObserver/Window/FormBrowserHost.cs +++ b/ElectronicObserver/Window/FormBrowserHost.cs @@ -457,51 +457,26 @@ private void ConnectToBrowserInternal(IntPtr hwnd) private string BuildDownstreamProxy() { - var config = Utility.Configuration.Config.Connection; + Configuration.ConfigurationData.ConfigConnection config = Configuration.Config.Connection; if (!string.IsNullOrEmpty(config.DownstreamProxy)) { return config.DownstreamProxy; - } - else if (config.UseSystemProxy) + + if (config.UseSystemProxy) { return APIObserver.Instance.ProxyPort.ToString(); } - else if (config.UseUpstreamProxy) - { - return string.Format( - "http=127.0.0.1:{0};https={1}:{2}", - APIObserver.Instance.ProxyPort, - config.UpstreamProxyAddress, - config.UpstreamProxyPort); - } - else - { - return string.Format("http=127.0.0.1:{0}", APIObserver.Instance.ProxyPort); - } - } + return string.Format("http=127.0.0.1:{0};https=127.0.0.1:{0}", APIObserver.Instance.ProxyPort); + } public void SetProxyCompleted() { InitializationStage |= InitializationStageFlag.SetProxyCompleted; } - - void Browser_Faulted(Exception e) - { - /*if ( Browser.Proxy == null ) - { - Utility.Logger.Add( 3, Resources.BrowserClosedWithoutWarning ); - } - else - { - Utility.ErrorReporter.SendErrorReport( e, Resources.BrowserThrewError ); - }*/ - } - - private void TerminateBrowserProcess() { // have to unset parent because the browsers Application.Exit call propagates up to EO otherwise