Commit 494b0e6f authored by justcoding121's avatar justcoding121

fix UpstreamEndpoint override

parent 15f2969b
...@@ -99,14 +99,14 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -99,14 +99,14 @@ namespace Titanium.Web.Proxy.EventArguments
/// Constructor to initialize the proxy /// Constructor to initialize the proxy
/// </summary> /// </summary>
internal SessionEventArgs(int bufferSize, internal SessionEventArgs(int bufferSize,
ProxyEndPoint endPoint, IPEndPoint upStreamEndPoint, ProxyEndPoint endPoint,
Func<SessionEventArgs, Task> httpResponseHandler) Func<SessionEventArgs, Task> httpResponseHandler)
{ {
this.bufferSize = bufferSize; this.bufferSize = bufferSize;
this.httpResponseHandler = httpResponseHandler; this.httpResponseHandler = httpResponseHandler;
ProxyClient = new ProxyClient(); ProxyClient = new ProxyClient();
WebSession = new HttpWebClient(bufferSize, upStreamEndPoint); WebSession = new HttpWebClient(bufferSize);
WebSession.ProcessId = new Lazy<int>(() => WebSession.ProcessId = new Lazy<int>(() =>
{ {
......
...@@ -7,8 +7,8 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -7,8 +7,8 @@ namespace Titanium.Web.Proxy.EventArguments
{ {
public bool IsHttpsConnect { get; set; } public bool IsHttpsConnect { get; set; }
public TunnelConnectSessionEventArgs(int bufferSize, ProxyEndPoint endPoint, IPEndPoint upStreamEndPoint) public TunnelConnectSessionEventArgs(int bufferSize, ProxyEndPoint endPoint)
: base(bufferSize, endPoint, upStreamEndPoint, null) : base(bufferSize, endPoint, null)
{ {
} }
......
...@@ -56,10 +56,9 @@ namespace Titanium.Web.Proxy.Http ...@@ -56,10 +56,9 @@ namespace Titanium.Web.Proxy.Http
/// </summary> /// </summary>
public bool IsHttps => Request.IsHttps; public bool IsHttps => Request.IsHttps;
internal HttpWebClient(int bufferSize, IPEndPoint upStreamEndPoint) internal HttpWebClient(int bufferSize)
{ {
this.bufferSize = bufferSize; this.bufferSize = bufferSize;
UpStreamEndPoint = upStreamEndPoint;
RequestId = Guid.NewGuid(); RequestId = Guid.NewGuid();
Request = new Request(); Request = new Request();
......
...@@ -55,7 +55,7 @@ namespace Titanium.Web.Proxy.Network.Tcp ...@@ -55,7 +55,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
try try
{ {
#if NET45 #if NET45
client = new TcpClient(upStreamEndPoint??server.UpStreamEndPoint); client = new TcpClient(upStreamEndPoint);
#else #else
client = new TcpClient(); client = new TcpClient();
client.Client.Bind(server.UpStreamEndPoint); client.Client.Bind(server.UpStreamEndPoint);
...@@ -131,6 +131,7 @@ namespace Titanium.Web.Proxy.Network.Tcp ...@@ -131,6 +131,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
{ {
UpStreamHttpProxy = externalHttpProxy, UpStreamHttpProxy = externalHttpProxy,
UpStreamHttpsProxy = externalHttpsProxy, UpStreamHttpsProxy = externalHttpsProxy,
UpStreamEndPoint = upStreamEndPoint,
HostName = remoteHostName, HostName = remoteHostName,
Port = remotePort, Port = remotePort,
IsHttps = isHttps, IsHttps = isHttps,
......
...@@ -86,7 +86,7 @@ namespace Titanium.Web.Proxy ...@@ -86,7 +86,7 @@ namespace Titanium.Web.Proxy
await HeaderParser.ReadHeaders(clientStreamReader, connectRequest.RequestHeaders); await HeaderParser.ReadHeaders(clientStreamReader, connectRequest.RequestHeaders);
var connectArgs = new TunnelConnectSessionEventArgs(BufferSize, endPoint, UpStreamEndPoint); var connectArgs = new TunnelConnectSessionEventArgs(BufferSize, endPoint);
connectArgs.WebSession.Request = connectRequest; connectArgs.WebSession.Request = connectRequest;
connectArgs.ProxyClient.TcpClient = tcpClient; connectArgs.ProxyClient.TcpClient = tcpClient;
connectArgs.ProxyClient.ClientStream = clientStream; connectArgs.ProxyClient.ClientStream = clientStream;
...@@ -293,7 +293,7 @@ namespace Titanium.Web.Proxy ...@@ -293,7 +293,7 @@ namespace Titanium.Web.Proxy
break; break;
} }
var args = new SessionEventArgs(BufferSize, endPoint, UpStreamEndPoint, HandleHttpSessionResponse) var args = new SessionEventArgs(BufferSize, endPoint, HandleHttpSessionResponse)
{ {
ProxyClient = { TcpClient = client }, ProxyClient = { TcpClient = client },
WebSession = { ConnectRequest = connectRequest } WebSession = { ConnectRequest = connectRequest }
...@@ -355,9 +355,10 @@ namespace Titanium.Web.Proxy ...@@ -355,9 +355,10 @@ namespace Titanium.Web.Proxy
} }
//create a new connection if hostname/upstream end point changes //create a new connection if hostname/upstream end point changes
if (connection != null if (connection != null
&& (!connection.HostName.Equals(args.WebSession.Request.RequestUri.Host, StringComparison.OrdinalIgnoreCase) && (!connection.HostName.Equals(args.WebSession.Request.RequestUri.Host, StringComparison.OrdinalIgnoreCase)
|| args.WebSession.UpStreamEndPoint != connection.UpStreamEndPoint)) || (args.WebSession.UpStreamEndPoint != null
&& !args.WebSession.UpStreamEndPoint.Equals(connection.UpStreamEndPoint))))
{ {
connection.Dispose(); connection.Dispose();
UpdateServerConnectionCount(false); UpdateServerConnectionCount(false);
...@@ -573,7 +574,7 @@ namespace Titanium.Web.Proxy ...@@ -573,7 +574,7 @@ namespace Titanium.Web.Proxy
/// <param name="args"></param> /// <param name="args"></param>
/// <param name="isConnect"></param> /// <param name="isConnect"></param>
/// <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 customUpStreamHttpProxy = null;
ExternalProxy customUpStreamHttpsProxy = null; ExternalProxy customUpStreamHttpsProxy = null;
...@@ -601,7 +602,7 @@ namespace Titanium.Web.Proxy ...@@ -601,7 +602,7 @@ namespace Titanium.Web.Proxy
args.WebSession.Request.RequestUri.Port, args.WebSession.Request.RequestUri.Port,
args.WebSession.Request.HttpVersion, args.WebSession.Request.HttpVersion,
args.IsHttps, isConnect, args.IsHttps, isConnect,
args.WebSession.UpStreamEndPoint, args.WebSession.UpStreamEndPoint ?? UpStreamEndPoint,
customUpStreamHttpProxy ?? UpStreamHttpProxy, customUpStreamHttpProxy ?? UpStreamHttpProxy,
customUpStreamHttpsProxy ?? UpStreamHttpsProxy); customUpStreamHttpsProxy ?? UpStreamHttpsProxy);
} }
......
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