Unverified Commit f221ccaa authored by justcoding121's avatar justcoding121 Committed by GitHub

Merge pull request #438 from justcoding121/master

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