Commit 20921442 authored by justcoding121's avatar justcoding121

remove version & connect from cache key

parent d329afdd
...@@ -43,22 +43,19 @@ namespace Titanium.Web.Proxy.Network.Tcp ...@@ -43,22 +43,19 @@ namespace Titanium.Web.Proxy.Network.Tcp
internal ProxyServer server { get; set; } internal ProxyServer server { get; set; }
internal string GetConnectionCacheKey(string remoteHostName, int remotePort, internal string GetConnectionCacheKey(string remoteHostName, int remotePort,
Version httpVersion, bool isHttps, List<SslApplicationProtocol> applicationProtocols, bool isConnect, bool isHttps, List<SslApplicationProtocol> applicationProtocols,
ProxyServer proxyServer, IPEndPoint upStreamEndPoint, ExternalProxy externalProxy) ProxyServer proxyServer, IPEndPoint upStreamEndPoint, ExternalProxy externalProxy)
{ {
//http version is ignored since its an application level decision b/w HTTP 1.0/1.1 //http version is ignored since its an application level decision b/w HTTP 1.0/1.1
//also when doing connect request MS Edge browser sends http 1.0 but uses 1.1 after server sends 1.1 its response. //also when doing connect request MS Edge browser sends http 1.0 but uses 1.1 after server sends 1.1 its response.
//That can create cache miss for same server connection unneccessarily expecially when prefetcing with Connect. //That can create cache miss for same server connection unneccessarily expecially when prefetcing with Connect.
//http version 2 is separated using applicationProtocols below. //http version 2 is separated using applicationProtocols below.
var cacheKeyBuilder = new StringBuilder($"{remoteHostName}-{remotePort}" + var cacheKeyBuilder = new StringBuilder($"{remoteHostName}-{remotePort}-" +
//when creating Tcp client if isHttps is true then isConnect won't matter //when creating Tcp client isConnect won't matter
//using {isHttps||isConnect} will prevent getting different cacheKeys $"{isHttps}-");
//in Explicit client handler for prefetch and in Request handler
//when checking for changed cache key!
$"-{isHttps}-{isHttps||isConnect}-");
if (applicationProtocols != null) if (applicationProtocols != null)
{ {
foreach (var protocol in applicationProtocols) foreach (var protocol in applicationProtocols.OrderBy(x=>x))
{ {
cacheKeyBuilder.Append($"{protocol}-"); cacheKeyBuilder.Append($"{protocol}-");
} }
...@@ -92,7 +89,7 @@ namespace Titanium.Web.Proxy.Network.Tcp ...@@ -92,7 +89,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
CancellationToken cancellationToken) CancellationToken cancellationToken)
{ {
var cacheKey = GetConnectionCacheKey(remoteHostName, remotePort, var cacheKey = GetConnectionCacheKey(remoteHostName, remotePort,
httpVersion, isHttps, applicationProtocols, isConnect, isHttps, applicationProtocols,
proxyServer, upStreamEndPoint, externalProxy); proxyServer, upStreamEndPoint, externalProxy);
if (proxyServer.EnableConnectionPool) if (proxyServer.EnableConnectionPool)
......
...@@ -192,7 +192,7 @@ namespace Titanium.Web.Proxy ...@@ -192,7 +192,7 @@ namespace Titanium.Web.Proxy
// only gets hit when connection pool is disabled. // only gets hit when connection pool is disabled.
// or when prefetch task has a unexpectedly different connection. // or when prefetch task has a unexpectedly different connection.
if (serverConnection != null if (serverConnection != null
&& (await getConnectionCacheKey(args, false, && (await getConnectionCacheKey(args,
clientConnection.NegotiatedApplicationProtocol) clientConnection.NegotiatedApplicationProtocol)
!= serverConnection.CacheKey)) != serverConnection.CacheKey))
{ {
...@@ -475,7 +475,7 @@ namespace Titanium.Web.Proxy ...@@ -475,7 +475,7 @@ namespace Titanium.Web.Proxy
/// <param name="isConnect">Is this a CONNECT request.</param> /// <param name="isConnect">Is this a CONNECT request.</param>
/// <param name="applicationProtocol"></param> /// <param name="applicationProtocol"></param>
/// <returns></returns> /// <returns></returns>
private async Task<string> getConnectionCacheKey(SessionEventArgsBase args, bool isConnect, private async Task<string> getConnectionCacheKey(SessionEventArgsBase args,
SslApplicationProtocol applicationProtocol) SslApplicationProtocol applicationProtocol)
{ {
List<SslApplicationProtocol> applicationProtocols = null; List<SslApplicationProtocol> applicationProtocols = null;
...@@ -497,8 +497,7 @@ namespace Titanium.Web.Proxy ...@@ -497,8 +497,7 @@ namespace Titanium.Web.Proxy
return tcpConnectionFactory.GetConnectionCacheKey( return tcpConnectionFactory.GetConnectionCacheKey(
args.WebSession.Request.RequestUri.Host, args.WebSession.Request.RequestUri.Host,
args.WebSession.Request.RequestUri.Port, args.WebSession.Request.RequestUri.Port,
args.WebSession.Request.HttpVersion, isHttps, applicationProtocols,
isHttps, applicationProtocols, isConnect,
this, args.WebSession.UpStreamEndPoint ?? UpStreamEndPoint, this, args.WebSession.UpStreamEndPoint ?? UpStreamEndPoint,
customUpStreamProxy ?? (isHttps ? UpStreamHttpsProxy : UpStreamHttpProxy)); customUpStreamProxy ?? (isHttps ? UpStreamHttpsProxy : UpStreamHttpProxy));
} }
......
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