Commit ebc25f50 authored by justcoding121's avatar justcoding121

optional prefetch

parent b6bdf046
...@@ -24,7 +24,6 @@ namespace Titanium.Web.Proxy.Examples.Basic ...@@ -24,7 +24,6 @@ namespace Titanium.Web.Proxy.Examples.Basic
public ProxyTestController() public ProxyTestController()
{ {
proxyServer = new ProxyServer(); proxyServer = new ProxyServer();
proxyServer.EnableConnectionPool = true;
// generate root certificate without storing it in file system // generate root certificate without storing it in file system
//proxyServer.CertificateManager.CreateRootCertificate(false); //proxyServer.CertificateManager.CreateRootCertificate(false);
......
...@@ -152,11 +152,14 @@ namespace Titanium.Web.Proxy ...@@ -152,11 +152,14 @@ namespace Titanium.Web.Proxy
SslStream sslStream = null; SslStream sslStream = null;
if (EnableTcpServerConnectionPrefetch)
{
//don't pass cancellation token here //don't pass cancellation token here
//it could cause floating server connections when client exits //it could cause floating server connections when client exits
prefetchConnectionTask = tcpConnectionFactory.GetServerConnection(this, connectArgs, prefetchConnectionTask = tcpConnectionFactory.GetServerConnection(this, connectArgs,
isConnect: true, applicationProtocols: null, noCache: false, isConnect: true, applicationProtocols: null, noCache: false,
cancellationToken: CancellationToken.None); cancellationToken: CancellationToken.None);
}
try try
{ {
...@@ -204,7 +207,7 @@ namespace Titanium.Web.Proxy ...@@ -204,7 +207,7 @@ namespace Titanium.Web.Proxy
decryptSsl = false; decryptSsl = false;
} }
if(!decryptSsl) if (!decryptSsl)
{ {
await tcpConnectionFactory.Release(prefetchConnectionTask, true); await tcpConnectionFactory.Release(prefetchConnectionTask, true);
prefetchConnectionTask = null; prefetchConnectionTask = null;
......
...@@ -161,9 +161,19 @@ namespace Titanium.Web.Proxy ...@@ -161,9 +161,19 @@ namespace Titanium.Web.Proxy
/// <summary> /// <summary>
/// Should we enable experimental server connection pool? /// Should we enable experimental server connection pool?
/// Defaults to disable. /// Defaults to true.
/// </summary> /// </summary>
public bool EnableConnectionPool { get; set; } public bool EnableConnectionPool { get; set; } = true;
/// <summary>
/// Should we enable tcp server connection prefetching?
/// When enabled, as soon as we receive a client connection we concurrently initiate
/// corresponding server connection process using CONNECT hostname or SNI hostname on a separate task so that after parsing client request
/// we will have the server connection immediately ready or in the process of getting ready.
/// If a server connection is available in cache then this prefetch task will immediatly return with the available connection from cache.
/// Defaults to true.
/// </summary>
public bool EnableTcpServerConnectionPrefetch { get; set; } = true;
/// <summary> /// <summary>
/// Buffer size in bytes used throughout this proxy. /// Buffer size in bytes used throughout this proxy.
......
...@@ -62,6 +62,8 @@ namespace Titanium.Web.Proxy ...@@ -62,6 +62,8 @@ namespace Titanium.Web.Proxy
} }
if (endPoint.DecryptSsl && args.DecryptSsl) if (endPoint.DecryptSsl && args.DecryptSsl)
{
if(EnableTcpServerConnectionPrefetch)
{ {
//don't pass cancellation token here //don't pass cancellation token here
//it could cause floating server connections when client exits //it could cause floating server connections when client exits
...@@ -69,6 +71,7 @@ namespace Titanium.Web.Proxy ...@@ -69,6 +71,7 @@ namespace Titanium.Web.Proxy
httpVersion: null, isHttps: true, applicationProtocols: null, isConnect: false, httpVersion: null, isHttps: true, applicationProtocols: null, isConnect: false,
proxyServer: this, upStreamEndPoint: UpStreamEndPoint, externalProxy: UpStreamHttpsProxy, proxyServer: this, upStreamEndPoint: UpStreamEndPoint, externalProxy: UpStreamHttpsProxy,
noCache: false, cancellationToken: CancellationToken.None); noCache: false, cancellationToken: CancellationToken.None);
}
SslStream sslStream = null; SslStream sslStream = null;
......
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