Skip to content

Commit

Permalink
add https support
Browse files Browse the repository at this point in the history
  • Loading branch information
myangelkamikaze committed Oct 21, 2023
1 parent 5d76236 commit da7e426
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 40 deletions.
24 changes: 14 additions & 10 deletions ElectronicObserver/Observer/APIObserver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
}

Expand Down
35 changes: 5 additions & 30 deletions ElectronicObserver/Window/FormBrowserHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit da7e426

Please sign in to comment.