Commit fe81398b authored by justcoding121's avatar justcoding121

reduce timeout; cleanup

parent 8317c222
...@@ -252,7 +252,7 @@ namespace Titanium.Web.Proxy ...@@ -252,7 +252,7 @@ namespace Titanium.Web.Proxy
public ProxyServer(string rootCertificateName, string rootCertificateIssuerName) public ProxyServer(string rootCertificateName, string rootCertificateIssuerName)
{ {
//default values //default values
ConnectionTimeOutSeconds = 120; ConnectionTimeOutSeconds = 30;
CertificateCacheTimeOutMinutes = 60; CertificateCacheTimeOutMinutes = 60;
ProxyEndPoints = new List<ProxyEndPoint>(); ProxyEndPoints = new List<ProxyEndPoint>();
......
...@@ -217,11 +217,16 @@ namespace Titanium.Web.Proxy ...@@ -217,11 +217,16 @@ namespace Titanium.Web.Proxy
endPoint.EnableSsl ? endPoint.GenericCertificateName : null, endPoint, null); endPoint.EnableSsl ? endPoint.GenericCertificateName : null, endPoint, null);
} }
/// <summary>
/// Create a Server Connection
/// </summary>
/// <param name="args"></param>
/// <returns></returns>
private async Task<TcpConnection> GetServerConnection( private async Task<TcpConnection> GetServerConnection(
SessionEventArgs args, SessionEventArgs args)
ExternalProxy customUpStreamHttpProxy,
ExternalProxy customUpStreamHttpsProxy, bool closeConnection)
{ {
ExternalProxy customUpStreamHttpProxy = null;
ExternalProxy customUpStreamHttpsProxy = null;
if (args.WebSession.Request.RequestUri.Scheme == "http") if (args.WebSession.Request.RequestUri.Scheme == "http")
{ {
...@@ -243,7 +248,8 @@ namespace Titanium.Web.Proxy ...@@ -243,7 +248,8 @@ namespace Titanium.Web.Proxy
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.HttpVersion, args.WebSession.Request.RequestUri.Port,
args.WebSession.Request.HttpVersion,
args.IsHttps, args.IsHttps,
customUpStreamHttpProxy ?? UpStreamHttpProxy, customUpStreamHttpProxy ?? UpStreamHttpProxy,
customUpStreamHttpsProxy ?? UpStreamHttpsProxy, customUpStreamHttpsProxy ?? UpStreamHttpsProxy,
...@@ -392,7 +398,7 @@ namespace Titanium.Web.Proxy ...@@ -392,7 +398,7 @@ namespace Titanium.Web.Proxy
/// <returns></returns> /// <returns></returns>
private async Task HandleHttpSessionRequest(TcpClient client, string httpCmd, Stream clientStream, private async Task HandleHttpSessionRequest(TcpClient client, string httpCmd, Stream clientStream,
CustomBinaryReader clientStreamReader, StreamWriter clientStreamWriter, string httpsHostName, CustomBinaryReader clientStreamReader, StreamWriter clientStreamWriter, string httpsHostName,
ProxyEndPoint endPoint, List<HttpHeader> connectHeaders, ExternalProxy customUpStreamHttpProxy = null, ExternalProxy customUpStreamHttpsProxy = null) ProxyEndPoint endPoint, List<HttpHeader> connectHeaders)
{ {
TcpConnection connection = null; TcpConnection connection = null;
...@@ -410,8 +416,7 @@ namespace Titanium.Web.Proxy ...@@ -410,8 +416,7 @@ namespace Titanium.Web.Proxy
break; break;
} }
var args = var args = new SessionEventArgs(BufferSize, HandleHttpSessionResponse)
new SessionEventArgs(BufferSize, HandleHttpSessionResponse)
{ {
ProxyClient = { TcpClient = client }, ProxyClient = { TcpClient = client },
WebSession = { ConnectHeaders = connectHeaders } WebSession = { ConnectHeaders = connectHeaders }
...@@ -464,12 +469,14 @@ namespace Titanium.Web.Proxy ...@@ -464,12 +469,14 @@ namespace Titanium.Web.Proxy
args.ProxyClient.ClientStreamReader = clientStreamReader; args.ProxyClient.ClientStreamReader = clientStreamReader;
args.ProxyClient.ClientStreamWriter = clientStreamWriter; args.ProxyClient.ClientStreamWriter = clientStreamWriter;
if (httpsHostName == null && await CheckAuthorization(clientStreamWriter, args.WebSession.Request.RequestHeaders.Values) == false) if (httpsHostName == null &&
await CheckAuthorization(clientStreamWriter,
args.WebSession.Request.RequestHeaders.Values) == false)
{ {
Dispose(clientStream, Dispose(clientStream,
clientStreamReader, clientStreamReader,
clientStreamWriter, clientStreamWriter,
args.WebSession.ServerConnection); connection);
break; break;
} }
...@@ -502,14 +509,14 @@ namespace Titanium.Web.Proxy ...@@ -502,14 +509,14 @@ namespace Titanium.Web.Proxy
Dispose(clientStream, Dispose(clientStream,
clientStreamReader, clientStreamReader,
clientStreamWriter, clientStreamWriter,
args.WebSession.ServerConnection); connection);
break; break;
} }
if (connection == null) if (connection == null)
{ {
connection = await GetServerConnection(args, customUpStreamHttpProxy, customUpStreamHttpsProxy, false); connection = await GetServerConnection(args);
} }
//construct the web request that we are going to issue on behalf of the client. //construct the web request that we are going to issue on behalf of the client.
...@@ -526,7 +533,7 @@ namespace Titanium.Web.Proxy ...@@ -526,7 +533,7 @@ namespace Titanium.Web.Proxy
Dispose(clientStream, Dispose(clientStream,
clientStreamReader, clientStreamReader,
clientStreamWriter, clientStreamWriter,
args.WebSession.ServerConnection); connection);
break; break;
} }
...@@ -537,7 +544,7 @@ namespace Titanium.Web.Proxy ...@@ -537,7 +544,7 @@ namespace Titanium.Web.Proxy
Dispose(clientStream, Dispose(clientStream,
clientStreamReader, clientStreamReader,
clientStreamWriter, clientStreamWriter,
args.WebSession.ServerConnection); connection);
break; break;
} }
...@@ -552,7 +559,7 @@ namespace Titanium.Web.Proxy ...@@ -552,7 +559,7 @@ namespace Titanium.Web.Proxy
Dispose(clientStream, Dispose(clientStream,
clientStreamReader, clientStreamReader,
clientStreamWriter, clientStreamWriter,
args.WebSession.ServerConnection); connection);
break; break;
} }
} }
......
...@@ -59,9 +59,9 @@ namespace Titanium.Web.Proxy ...@@ -59,9 +59,9 @@ namespace Titanium.Web.Proxy
ServerConnectionCount--; ServerConnectionCount--;
} }
var connection = await GetServerConnection(args, null, null, true); var connection = await GetServerConnection(args);
await HandleHttpSessionRequestInternal(null, args, true); var result = await HandleHttpSessionRequestInternal(null, args, true);
return true; return result;
} }
args.WebSession.Response.ResponseLocked = true; args.WebSession.Response.ResponseLocked = true;
......
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