Commit 494b0e6f authored by justcoding121's avatar justcoding121

fix UpstreamEndpoint override

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