Commit f93804eb authored by Honfika's avatar Honfika

common proxy property for Http and Https in SessionEventArgs since only one...

common proxy property for Http and Https in SessionEventArgs since only one them was set (or neither). You can use args.IsHttps whether it is a Http ot Https proxy.
parent c80b2174
...@@ -82,14 +82,9 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -82,14 +82,9 @@ namespace Titanium.Web.Proxy.EventArguments
public HttpWebClient WebSession { get; } public HttpWebClient WebSession { get; }
/// <summary> /// <summary>
/// Are we using a custom upstream HTTP proxy? /// Are we using a custom upstream HTTP(S) proxy?
/// </summary> /// </summary>
public ExternalProxy CustomUpStreamHttpProxyUsed { get; internal set; } public ExternalProxy CustomUpStreamProxyUsed { get; internal set; }
/// <summary>
/// Are we using a custom upstream HTTPS proxy?
/// </summary>
public ExternalProxy CustomUpStreamHttpsProxyUsed { get; internal set; }
public event EventHandler<DataEventArgs> DataSent; public event EventHandler<DataEventArgs> DataSent;
...@@ -519,8 +514,7 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -519,8 +514,7 @@ namespace Titanium.Web.Proxy.EventArguments
public void Dispose() public void Dispose()
{ {
httpResponseHandler = null; httpResponseHandler = null;
CustomUpStreamHttpProxyUsed = null; CustomUpStreamProxyUsed = null;
CustomUpStreamHttpsProxyUsed = null;
WebSession.FinishSession(); WebSession.FinishSession();
} }
......
...@@ -87,7 +87,7 @@ namespace Titanium.Web.Proxy.Http ...@@ -87,7 +87,7 @@ namespace Titanium.Web.Proxy.Http
using (var ms = new MemoryStream()) using (var ms = new MemoryStream())
using (var writer = new HttpRequestWriter(ms, bufferSize)) using (var writer = new HttpRequestWriter(ms, bufferSize))
{ {
var upstreamProxy = ServerConnection.UpStreamHttpProxy; var upstreamProxy = ServerConnection.UpStreamProxy;
bool useUpstreamProxy = upstreamProxy != null && ServerConnection.IsHttps == false; bool useUpstreamProxy = upstreamProxy != null && ServerConnection.IsHttps == false;
......
...@@ -12,11 +12,7 @@ namespace Titanium.Web.Proxy.Network.Tcp ...@@ -12,11 +12,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
/// </summary> /// </summary>
internal class TcpConnection : IDisposable internal class TcpConnection : IDisposable
{ {
internal ExternalProxy UpStreamHttpProxy { get; set; } internal ExternalProxy UpStreamProxy { get; set; }
internal ExternalProxy UpStreamHttpsProxy { get; set; }
internal ExternalProxy UpStreamProxy => UseUpstreamProxy ? IsHttps ? UpStreamHttpsProxy : UpStreamHttpProxy : null;
internal string HostName { get; set; } internal string HostName { get; set; }
......
...@@ -27,15 +27,13 @@ namespace Titanium.Web.Proxy.Network.Tcp ...@@ -27,15 +27,13 @@ namespace Titanium.Web.Proxy.Network.Tcp
/// <param name="isHttps"></param> /// <param name="isHttps"></param>
/// <param name="isConnect"></param> /// <param name="isConnect"></param>
/// <param name="upStreamEndPoint"></param> /// <param name="upStreamEndPoint"></param>
/// <param name="externalHttpProxy"></param> /// <param name="externalProxy"></param>
/// <param name="externalHttpsProxy"></param>
/// <returns></returns> /// <returns></returns>
internal async Task<TcpConnection> CreateClient(ProxyServer server, internal async Task<TcpConnection> CreateClient(ProxyServer server,
string remoteHostName, int remotePort, Version httpVersion, bool isHttps, string remoteHostName, int remotePort, Version httpVersion, bool isHttps,
bool isConnect, IPEndPoint upStreamEndPoint, ExternalProxy externalHttpProxy, ExternalProxy externalHttpsProxy) bool isConnect, IPEndPoint upStreamEndPoint, ExternalProxy externalProxy)
{ {
bool useUpstreamProxy = false; bool useUpstreamProxy = false;
var externalProxy = isHttps ? externalHttpsProxy : externalHttpProxy;
//check if external proxy is set for HTTP/HTTPS //check if external proxy is set for HTTP/HTTPS
if (externalProxy != null && !(externalProxy.HostName == remoteHostName && externalProxy.Port == remotePort)) if (externalProxy != null && !(externalProxy.HostName == remoteHostName && externalProxy.Port == remotePort))
...@@ -129,8 +127,7 @@ namespace Titanium.Web.Proxy.Network.Tcp ...@@ -129,8 +127,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
return new TcpConnection return new TcpConnection
{ {
UpStreamHttpProxy = externalHttpProxy, UpStreamProxy = externalProxy,
UpStreamHttpsProxy = externalHttpsProxy,
UpStreamEndPoint = upStreamEndPoint, UpStreamEndPoint = upStreamEndPoint,
HostName = remoteHostName, HostName = remoteHostName,
Port = remotePort, Port = remotePort,
......
...@@ -273,16 +273,10 @@ namespace Titanium.Web.Proxy ...@@ -273,16 +273,10 @@ namespace Titanium.Web.Proxy
public string ProxyRealm { get; set; } = "TitaniumProxy"; public string ProxyRealm { get; set; } = "TitaniumProxy";
/// <summary> /// <summary>
/// A callback to provide authentication credentials for up stream proxy this proxy is using for HTTP requests /// A callback to provide authentication credentials for up stream proxy this proxy is using for HTTP(S) requests
/// return the ExternalProxy object with valid credentials /// return the ExternalProxy object with valid credentials
/// </summary> /// </summary>
public Func<SessionEventArgs, Task<ExternalProxy>> GetCustomUpStreamHttpProxyFunc { get; set; } public Func<SessionEventArgs, Task<ExternalProxy>> GetCustomUpStreamProxyFunc { get; set; }
/// <summary>
/// A callback to provide authentication credentials for up stream proxy this proxy is using for HTTPS requests
/// return the ExternalProxy object with valid credentials
/// </summary>
public Func<SessionEventArgs, Task<ExternalProxy>> GetCustomUpStreamHttpsProxyFunc { get; set; }
/// <summary> /// <summary>
/// A list of IpAddress and port this proxy is listening to /// A list of IpAddress and port this proxy is listening to
...@@ -571,16 +565,13 @@ namespace Titanium.Web.Proxy ...@@ -571,16 +565,13 @@ namespace Titanium.Web.Proxy
} }
} }
if (ForwardToUpstreamGateway if (ForwardToUpstreamGateway && GetCustomUpStreamProxyFunc == null && systemProxySettingsManager != null)
&& GetCustomUpStreamHttpProxyFunc == null && GetCustomUpStreamHttpsProxyFunc == null
&& systemProxySettingsManager != null)
{ {
// Use WinHttp to handle PAC/WAPD scripts. // Use WinHttp to handle PAC/WAPD scripts.
systemProxyResolver = new WinHttpWebProxyFinder(); systemProxyResolver = new WinHttpWebProxyFinder();
systemProxyResolver.LoadFromIE(); systemProxyResolver.LoadFromIE();
GetCustomUpStreamHttpProxyFunc = GetSystemUpStreamProxy; GetCustomUpStreamProxyFunc = GetSystemUpStreamProxy;
GetCustomUpStreamHttpsProxyFunc = GetSystemUpStreamProxy;
} }
#endif #endif
......
...@@ -581,35 +581,23 @@ namespace Titanium.Web.Proxy ...@@ -581,35 +581,23 @@ namespace Titanium.Web.Proxy
/// <returns></returns> /// <returns></returns>
private async Task<TcpConnection> GetServerConnection(SessionEventArgs args, bool isConnect) private async Task<TcpConnection> GetServerConnection(SessionEventArgs args, bool isConnect)
{ {
ExternalProxy customUpStreamHttpProxy = null; ExternalProxy customUpStreamProxy = null;
ExternalProxy customUpStreamHttpsProxy = null;
if (args.WebSession.Request.IsHttps) bool isHttps = args.IsHttps;
if (GetCustomUpStreamProxyFunc != null)
{ {
if (GetCustomUpStreamHttpsProxyFunc != null) customUpStreamProxy = await GetCustomUpStreamProxyFunc(args);
{
customUpStreamHttpsProxy = await GetCustomUpStreamHttpsProxyFunc(args);
}
}
else
{
if (GetCustomUpStreamHttpProxyFunc != null)
{
customUpStreamHttpProxy = await GetCustomUpStreamHttpProxyFunc(args);
}
} }
args.CustomUpStreamHttpProxyUsed = customUpStreamHttpProxy; args.CustomUpStreamProxyUsed = customUpStreamProxy;
args.CustomUpStreamHttpsProxyUsed = customUpStreamHttpsProxy;
return await tcpConnectionFactory.CreateClient(this, return await tcpConnectionFactory.CreateClient(this,
args.WebSession.Request.RequestUri.Host, args.WebSession.Request.RequestUri.Host,
args.WebSession.Request.RequestUri.Port, args.WebSession.Request.RequestUri.Port,
args.WebSession.Request.HttpVersion, args.WebSession.Request.HttpVersion,
args.IsHttps, isConnect, isHttps, isConnect,
args.WebSession.UpStreamEndPoint ?? UpStreamEndPoint, args.WebSession.UpStreamEndPoint ?? UpStreamEndPoint,
customUpStreamHttpProxy ?? UpStreamHttpProxy, customUpStreamProxy ?? (isHttps ? UpStreamHttpsProxy : UpStreamHttpProxy));
customUpStreamHttpsProxy ?? UpStreamHttpsProxy);
} }
/// <summary> /// <summary>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment