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
56de40a3
Commit
56de40a3
authored
May 14, 2018
by
justcoding121
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use try finally to release connection
parent
abc21b87
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
50 deletions
+64
-50
ExplicitClientHandler.cs
Titanium.Web.Proxy/ExplicitClientHandler.cs
+39
-29
TransparentClientHandler.cs
Titanium.Web.Proxy/TransparentClientHandler.cs
+25
-21
No files found.
Titanium.Web.Proxy/ExplicitClientHandler.cs
View file @
56de40a3
...
...
@@ -44,7 +44,7 @@ namespace Titanium.Web.Proxy
{
string
connectHostname
=
null
;
TunnelConnectSessionEventArgs
connectArgs
=
null
;
// Client wants to create a secure tcp tunnel (probably its a HTTPS or Websocket request)
if
(
await
HttpHelper
.
IsConnectMethod
(
clientStream
)
==
1
)
...
...
@@ -212,38 +212,43 @@ namespace Titanium.Web.Proxy
var
connection
=
await
getServerConnection
(
connectArgs
,
true
,
null
,
cancellationToken
);
if
(
isClientHello
)
try
{
int
available
=
clientStream
.
Available
;
if
(
available
>
0
)
if
(
isClientHello
)
{
// send the buffered data
var
data
=
BufferPool
.
GetBuffer
(
BufferSize
);
try
{
// clientStream.Available sbould be at most BufferSize because it is using the same buffer size
await
clientStream
.
ReadAsync
(
data
,
0
,
available
,
cancellationToken
);
await
connection
.
StreamWriter
.
WriteAsync
(
data
,
0
,
available
,
true
,
cancellationToken
);
}
finally
int
available
=
clientStream
.
Available
;
if
(
available
>
0
)
{
BufferPool
.
ReturnBuffer
(
data
);
// send the buffered data
var
data
=
BufferPool
.
GetBuffer
(
BufferSize
);
try
{
// clientStream.Available sbould be at most BufferSize because it is using the same buffer size
await
clientStream
.
ReadAsync
(
data
,
0
,
available
,
cancellationToken
);
await
connection
.
StreamWriter
.
WriteAsync
(
data
,
0
,
available
,
true
,
cancellationToken
);
}
finally
{
BufferPool
.
ReturnBuffer
(
data
);
}
}
var
serverHelloInfo
=
await
SslTools
.
PeekServerHello
(
connection
.
Stream
,
BufferPool
,
cancellationToken
);
((
ConnectResponse
)
connectArgs
.
WebSession
.
Response
).
ServerHelloInfo
=
serverHelloInfo
;
}
var
serverHelloInfo
=
await
SslTools
.
PeekServerHello
(
connection
.
Stream
,
BufferPool
,
cancellationToken
);
((
ConnectResponse
)
connectArgs
.
WebSession
.
Response
).
ServerHelloInfo
=
serverHelloInfo
;
await
TcpHelper
.
SendRaw
(
clientStream
,
connection
.
Stream
,
BufferPool
,
BufferSize
,
(
buffer
,
offset
,
count
)
=>
{
connectArgs
.
OnDataSent
(
buffer
,
offset
,
count
);
},
(
buffer
,
offset
,
count
)
=>
{
connectArgs
.
OnDataReceived
(
buffer
,
offset
,
count
);
},
connectArgs
.
CancellationTokenSource
,
ExceptionFunc
);
}
finally
{
await
tcpConnectionFactory
.
Release
(
connection
,
true
);
}
await
TcpHelper
.
SendRaw
(
clientStream
,
connection
.
Stream
,
BufferPool
,
BufferSize
,
(
buffer
,
offset
,
count
)
=>
{
connectArgs
.
OnDataSent
(
buffer
,
offset
,
count
);
},
(
buffer
,
offset
,
count
)
=>
{
connectArgs
.
OnDataReceived
(
buffer
,
offset
,
count
);
},
connectArgs
.
CancellationTokenSource
,
ExceptionFunc
);
await
tcpConnectionFactory
.
Release
(
connection
,
true
);
return
;
}
}
...
...
@@ -276,7 +281,8 @@ namespace Titanium.Web.Proxy
// create new connection
var
connection
=
await
getServerConnection
(
connectArgs
,
true
,
SslExtensions
.
Http2ProtocolAsList
,
cancellationToken
);
try
{
await
connection
.
StreamWriter
.
WriteLineAsync
(
"PRI * HTTP/2.0"
,
cancellationToken
);
await
connection
.
StreamWriter
.
WriteLineAsync
(
cancellationToken
);
await
connection
.
StreamWriter
.
WriteLineAsync
(
"SM"
,
cancellationToken
);
...
...
@@ -288,7 +294,11 @@ namespace Titanium.Web.Proxy
(
buffer
,
offset
,
count
)
=>
{
connectArgs
.
OnDataReceived
(
buffer
,
offset
,
count
);
},
connectArgs
.
CancellationTokenSource
,
clientConnection
.
Id
,
ExceptionFunc
);
#endif
await
tcpConnectionFactory
.
Release
(
connection
,
true
);
}
finally
{
await
tcpConnectionFactory
.
Release
(
connection
,
true
);
}
}
}
calledRequestHandler
=
true
;
...
...
@@ -318,7 +328,7 @@ namespace Titanium.Web.Proxy
}
finally
{
if
(!
calledRequestHandler
if
(!
calledRequestHandler
&&
prefetchConnectionTask
!=
null
)
{
var
connection
=
await
prefetchConnectionTask
;
...
...
Titanium.Web.Proxy/TransparentClientHandler.cs
View file @
56de40a3
...
...
@@ -98,34 +98,38 @@ namespace Titanium.Web.Proxy
null
,
false
,
null
,
true
,
this
,
UpStreamEndPoint
,
UpStreamHttpsProxy
,
cancellationToken
);
var
serverStream
=
connection
.
Stream
;
int
available
=
clientStream
.
Available
;
if
(
available
>
0
)
try
{
// send the buffered data
var
data
=
BufferPool
.
GetBuffer
(
BufferSize
);
var
serverStream
=
connection
.
Stream
;
try
{
// clientStream.Available sbould be at most BufferSize because it is using the same buffer size
await
clientStream
.
ReadAsync
(
data
,
0
,
available
,
cancellationToken
);
await
serverStream
.
WriteAsync
(
data
,
0
,
available
,
cancellationToken
);
await
serverStream
.
FlushAsync
(
cancellationToken
);
}
finally
int
available
=
clientStream
.
Available
;
if
(
available
>
0
)
{
BufferPool
.
ReturnBuffer
(
data
);
// send the buffered data
var
data
=
BufferPool
.
GetBuffer
(
BufferSize
);
try
{
// clientStream.Available sbould be at most BufferSize because it is using the same buffer size
await
clientStream
.
ReadAsync
(
data
,
0
,
available
,
cancellationToken
);
await
serverStream
.
WriteAsync
(
data
,
0
,
available
,
cancellationToken
);
await
serverStream
.
FlushAsync
(
cancellationToken
);
}
finally
{
BufferPool
.
ReturnBuffer
(
data
);
}
}
}
await
TcpHelper
.
SendRaw
(
clientStream
,
serverStream
,
BufferPool
,
BufferSize
,
null
,
null
,
cancellationTokenSource
,
ExceptionFunc
);
await
TcpHelper
.
SendRaw
(
clientStream
,
serverStream
,
BufferPool
,
BufferSize
,
null
,
null
,
cancellationTokenSource
,
ExceptionFunc
);
}
finally
{
await
tcpConnectionFactory
.
Release
(
connection
,
true
);
}
await
tcpConnectionFactory
.
Release
(
connection
,
true
);
return
;
}
}
calledRequestHandler
=
true
;
...
...
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