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
a005cba2
Commit
a005cba2
authored
May 09, 2018
by
justcoding121
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add max cached connections property
parent
8add4e7e
Show 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 @
a005cba2
...
...
@@ -129,7 +129,7 @@ namespace Titanium.Web.Proxy
{
connectRequest
.
RequestUri
=
new
Uri
(
"https://"
+
httpUrl
);
bool
http2Supp
ro
ted
=
false
;
bool
http2Supp
or
ted
=
false
;
var
alpn
=
clientHelloInfo
.
GetAlpn
();
if
(
alpn
!=
null
&&
alpn
.
Contains
(
SslApplicationProtocol
.
Http2
))
...
...
@@ -139,8 +139,12 @@ namespace Titanium.Web.Proxy
var
connection
=
await
getServerConnection
(
connectArgs
,
true
,
SslExtensions
.
Http2ProtocolAsList
,
cancellationToken
);
http2Supproted
=
connection
.
NegotiatedApplicationProtocol
==
SslApplicationProtocol
.
Http2
;
tcpConnectionFactory
.
Release
(
connection
,
true
);
http2Supported
=
connection
.
NegotiatedApplicationProtocol
==
SslApplicationProtocol
.
Http2
;
//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
;
...
...
@@ -156,7 +160,7 @@ namespace Titanium.Web.Proxy
// Successfully managed to authenticate the client using the fake certificate
var
options
=
new
SslServerAuthenticationOptions
();
if
(
http2Supp
ro
ted
)
if
(
http2Supp
or
ted
)
{
options
.
ApplicationProtocols
=
clientHelloInfo
.
GetAlpn
();
if
(
options
.
ApplicationProtocols
==
null
||
options
.
ApplicationProtocols
.
Count
==
0
)
...
...
@@ -202,7 +206,7 @@ namespace Titanium.Web.Proxy
{
// create new connection
var
connection
=
await
getServerConnection
(
connectArgs
,
true
,
clientConnection
.
NegotiatedApplicationProtoco
l
,
cancellationToken
);
nul
l
,
cancellationToken
);
if
(
isClientHello
)
{
...
...
Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs
View file @
a005cba2
...
...
@@ -127,6 +127,13 @@ namespace Titanium.Web.Proxy.Network.Tcp
{
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
);
break
;
}
...
...
Titanium.Web.Proxy/ProxyServer.cs
View file @
a005cba2
...
...
@@ -165,6 +165,14 @@ namespace Titanium.Web.Proxy
/// </summary>
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>
/// Total number of active client connections.
/// </summary>
...
...
Titanium.Web.Proxy/RequestHandler.cs
View file @
a005cba2
...
...
@@ -196,13 +196,16 @@ namespace Titanium.Web.Proxy
connectionChanged
=
true
;
}
//for connection pool retry attempt until we get a good connection
int
attemt
=
0
;
while
(
attemt
<
3
)
//for connection pool retry fails until cache is exhausted
//In future once connection pool becomes stable
//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
{
// 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
)
{
await
handleWebSocketUpgrade
(
httpCmd
,
args
,
request
,
...
...
@@ -217,7 +220,7 @@ namespace Titanium.Web.Proxy
//connection pool retry
catch
(
ServerConnectionException
)
{
if
(!
connectionChanged
||
!
EnableConnectionPool
||
attem
t
==
3
)
if
(!
connectionChanged
||
!
EnableConnectionPool
||
attem
pt
==
MaxCachedConnections
+
1
)
{
throw
;
}
...
...
@@ -226,7 +229,7 @@ namespace Titanium.Web.Proxy
tcpConnectionFactory
.
Release
(
serverConnection
,
true
);
serverConnection
=
await
getServerConnection
(
args
,
false
,
clientConnection
.
NegotiatedApplicationProtocol
,
cancellationToken
);
attemt
++;
attem
p
t
++;
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