Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
T
Titanium-Web-Proxy
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Titanium-Web-Proxy
Commits
8d6d8ac0
Commit
8d6d8ac0
authored
May 09, 2018
by
justcoding121
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add max cached connections property
parent
bbcdb318
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
33 additions
and
11 deletions
+33
-11
ExplicitClientHandler.cs
Titanium.Web.Proxy/ExplicitClientHandler.cs
+9
-5
TcpConnectionFactory.cs
Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs
+7
-0
ProxyServer.cs
Titanium.Web.Proxy/ProxyServer.cs
+8
-0
RequestHandler.cs
Titanium.Web.Proxy/RequestHandler.cs
+9
-6
No files found.
Titanium.Web.Proxy/ExplicitClientHandler.cs
View file @
8d6d8ac0
...
@@ -129,7 +129,7 @@ namespace Titanium.Web.Proxy
...
@@ -129,7 +129,7 @@ namespace Titanium.Web.Proxy
{
{
connectRequest
.
RequestUri
=
new
Uri
(
"https://"
+
httpUrl
);
connectRequest
.
RequestUri
=
new
Uri
(
"https://"
+
httpUrl
);
bool
http2Supp
ro
ted
=
false
;
bool
http2Supp
or
ted
=
false
;
var
alpn
=
clientHelloInfo
.
GetAlpn
();
var
alpn
=
clientHelloInfo
.
GetAlpn
();
if
(
alpn
!=
null
&&
alpn
.
Contains
(
SslApplicationProtocol
.
Http2
))
if
(
alpn
!=
null
&&
alpn
.
Contains
(
SslApplicationProtocol
.
Http2
))
...
@@ -139,8 +139,12 @@ namespace Titanium.Web.Proxy
...
@@ -139,8 +139,12 @@ namespace Titanium.Web.Proxy
var
connection
=
await
getServerConnection
(
connectArgs
,
true
,
var
connection
=
await
getServerConnection
(
connectArgs
,
true
,
SslExtensions
.
Http2ProtocolAsList
,
cancellationToken
);
SslExtensions
.
Http2ProtocolAsList
,
cancellationToken
);
http2Supproted
=
connection
.
NegotiatedApplicationProtocol
==
SslApplicationProtocol
.
Http2
;
http2Supported
=
connection
.
NegotiatedApplicationProtocol
==
SslApplicationProtocol
.
Http2
;
tcpConnectionFactory
.
Release
(
connection
,
true
);
//release connection back to pool intead of closing when connection pool is enabled
//In future we can connect to server preemptively here for all HTTPS connections using connect hostname
//and then release it back to pool so that we can save time when reading client headers
tcpConnectionFactory
.
Release
(
connection
,
!
EnableConnectionPool
);
}
}
SslStream
sslStream
=
null
;
SslStream
sslStream
=
null
;
...
@@ -156,7 +160,7 @@ namespace Titanium.Web.Proxy
...
@@ -156,7 +160,7 @@ namespace Titanium.Web.Proxy
// Successfully managed to authenticate the client using the fake certificate
// Successfully managed to authenticate the client using the fake certificate
var
options
=
new
SslServerAuthenticationOptions
();
var
options
=
new
SslServerAuthenticationOptions
();
if
(
http2Supp
ro
ted
)
if
(
http2Supp
or
ted
)
{
{
options
.
ApplicationProtocols
=
clientHelloInfo
.
GetAlpn
();
options
.
ApplicationProtocols
=
clientHelloInfo
.
GetAlpn
();
if
(
options
.
ApplicationProtocols
==
null
||
options
.
ApplicationProtocols
.
Count
==
0
)
if
(
options
.
ApplicationProtocols
==
null
||
options
.
ApplicationProtocols
.
Count
==
0
)
...
@@ -202,7 +206,7 @@ namespace Titanium.Web.Proxy
...
@@ -202,7 +206,7 @@ namespace Titanium.Web.Proxy
{
{
// create new connection
// create new connection
var
connection
=
await
getServerConnection
(
connectArgs
,
true
,
var
connection
=
await
getServerConnection
(
connectArgs
,
true
,
clientConnection
.
NegotiatedApplicationProtoco
l
,
cancellationToken
);
nul
l
,
cancellationToken
);
if
(
isClientHello
)
if
(
isClientHello
)
{
{
...
...
Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs
View file @
8d6d8ac0
...
@@ -127,6 +127,13 @@ namespace Titanium.Web.Proxy.Network.Tcp
...
@@ -127,6 +127,13 @@ namespace Titanium.Web.Proxy.Network.Tcp
{
{
if
(
cache
.
TryGetValue
(
connection
.
CacheKey
,
out
var
existingConnections
))
if
(
cache
.
TryGetValue
(
connection
.
CacheKey
,
out
var
existingConnections
))
{
{
while
(
existingConnections
.
Count
>=
server
.
MaxCachedConnections
)
{
if
(
existingConnections
.
TryDequeue
(
out
var
staleConnection
))
{
disposalBag
.
Add
(
staleConnection
);
}
}
existingConnections
.
Enqueue
(
connection
);
existingConnections
.
Enqueue
(
connection
);
break
;
break
;
}
}
...
...
Titanium.Web.Proxy/ProxyServer.cs
View file @
8d6d8ac0
...
@@ -165,6 +165,14 @@ namespace Titanium.Web.Proxy
...
@@ -165,6 +165,14 @@ namespace Titanium.Web.Proxy
/// </summary>
/// </summary>
public
int
ConnectionTimeOutSeconds
{
get
;
set
;
}
public
int
ConnectionTimeOutSeconds
{
get
;
set
;
}
/// <summary>
/// Maximum number of concurrent connections per remote host in cache.
/// Only valid when connection pooling is enabled.
/// Default value is 3.
/// </summary>
public
int
MaxCachedConnections
{
get
;
set
;
}
=
3
;
/// <summary>
/// <summary>
/// Total number of active client connections.
/// Total number of active client connections.
/// </summary>
/// </summary>
...
...
Titanium.Web.Proxy/RequestHandler.cs
View file @
8d6d8ac0
...
@@ -196,13 +196,16 @@ namespace Titanium.Web.Proxy
...
@@ -196,13 +196,16 @@ namespace Titanium.Web.Proxy
connectionChanged
=
true
;
connectionChanged
=
true
;
}
}
//for connection pool retry attempt until we get a good connection
//for connection pool retry fails until cache is exhausted
int
attemt
=
0
;
//In future once connection pool becomes stable
while
(
attemt
<
3
)
//we can get connection for each HTTP session instead of per client connection
//That will be more efficient especially when client is holding connection but not using it
int
attempt
=
0
;
while
(
attempt
<
MaxCachedConnections
+
1
)
{
{
try
try
{
{
// if upgrading to websocket then relay the requet without reading the contents
// if upgrading to websocket then relay the reque
s
t without reading the contents
if
(
request
.
UpgradeToWebSocket
)
if
(
request
.
UpgradeToWebSocket
)
{
{
await
handleWebSocketUpgrade
(
httpCmd
,
args
,
request
,
await
handleWebSocketUpgrade
(
httpCmd
,
args
,
request
,
...
@@ -217,7 +220,7 @@ namespace Titanium.Web.Proxy
...
@@ -217,7 +220,7 @@ namespace Titanium.Web.Proxy
//connection pool retry
//connection pool retry
catch
(
ServerConnectionException
)
catch
(
ServerConnectionException
)
{
{
if
(!
connectionChanged
||
!
EnableConnectionPool
||
attem
t
==
3
)
if
(!
connectionChanged
||
!
EnableConnectionPool
||
attem
pt
==
MaxCachedConnections
+
1
)
{
{
throw
;
throw
;
}
}
...
@@ -226,7 +229,7 @@ namespace Titanium.Web.Proxy
...
@@ -226,7 +229,7 @@ namespace Titanium.Web.Proxy
tcpConnectionFactory
.
Release
(
serverConnection
,
true
);
tcpConnectionFactory
.
Release
(
serverConnection
,
true
);
serverConnection
=
await
getServerConnection
(
args
,
false
,
serverConnection
=
await
getServerConnection
(
args
,
false
,
clientConnection
.
NegotiatedApplicationProtocol
,
cancellationToken
);
clientConnection
.
NegotiatedApplicationProtocol
,
cancellationToken
);
attemt
++;
attem
p
t
++;
continue
;
continue
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment