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
d49e55ad
Commit
d49e55ad
authored
May 15, 2017
by
justcoding121
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix server connection reuse
parent
0786662d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
34 deletions
+55
-34
RequestHandler.cs
Titanium.Web.Proxy/RequestHandler.cs
+47
-33
ResponseHandler.cs
Titanium.Web.Proxy/ResponseHandler.cs
+8
-1
No files found.
Titanium.Web.Proxy/RequestHandler.cs
View file @
d49e55ad
...
@@ -141,10 +141,10 @@ namespace Titanium.Web.Proxy
...
@@ -141,10 +141,10 @@ namespace Titanium.Web.Proxy
//write back successfull CONNECT response
//write back successfull CONNECT response
await
WriteConnectResponse
(
clientStreamWriter
,
version
);
await
WriteConnectResponse
(
clientStreamWriter
,
version
);
await
TcpHelper
.
SendRaw
(
this
,
await
TcpHelper
.
SendRaw
(
this
,
httpRemoteUri
.
Host
,
httpRemoteUri
.
Port
,
httpRemoteUri
.
Host
,
httpRemoteUri
.
Port
,
null
,
version
,
null
,
null
,
version
,
null
,
false
,
false
,
clientStream
,
tcpConnectionFactory
);
clientStream
,
tcpConnectionFactory
);
Dispose
(
clientStream
,
clientStreamReader
,
clientStreamWriter
,
null
);
Dispose
(
clientStream
,
clientStreamReader
,
clientStreamWriter
,
null
);
...
@@ -217,40 +217,45 @@ namespace Titanium.Web.Proxy
...
@@ -217,40 +217,45 @@ namespace Titanium.Web.Proxy
endPoint
.
EnableSsl
?
endPoint
.
GenericCertificateName
:
null
,
endPoint
,
null
);
endPoint
.
EnableSsl
?
endPoint
.
GenericCertificateName
:
null
,
endPoint
,
null
);
}
}
private
async
Task
<
bool
>
HandleHttpSessionRequestInternal
(
TcpConnection
connection
,
SessionEventArgs
args
,
private
async
Task
<
TcpConnection
>
GetServerConnection
(
ExternalProxy
customUpStreamHttpProxy
,
ExternalProxy
customUpStreamHttpsProxy
,
bool
closeConnection
)
SessionEventArgs
args
,
ExternalProxy
customUpStreamHttpProxy
,
ExternalProxy
customUpStreamHttpsProxy
,
bool
closeConnection
)
{
{
try
if
(
args
.
WebSession
.
Request
.
RequestUri
.
Scheme
==
"http"
)
{
{
if
(
connection
=
=
null
)
if
(
GetCustomUpStreamHttpProxyFunc
!
=
null
)
{
{
if
(
args
.
WebSession
.
Request
.
RequestUri
.
Scheme
==
"http"
)
customUpStreamHttpProxy
=
await
GetCustomUpStreamHttpProxyFunc
(
args
);
{
}
if
(
GetCustomUpStreamHttpProxyFunc
!=
null
)
}
{
else
customUpStreamHttpProxy
=
await
GetCustomUpStreamHttpProxyFunc
(
args
);
{
}
if
(
GetCustomUpStreamHttpsProxyFunc
!=
null
)
}
{
else
customUpStreamHttpsProxy
=
await
GetCustomUpStreamHttpsProxyFunc
(
args
);
{
}
if
(
GetCustomUpStreamHttpsProxyFunc
!=
null
)
}
{
customUpStreamHttpsProxy
=
await
GetCustomUpStreamHttpsProxyFunc
(
args
);
}
}
args
.
CustomUpStreamHttpProxyUsed
=
customUpStreamHttpProxy
;
args
.
CustomUpStreamHttpProxyUsed
=
customUpStreamHttpProxy
;
args
.
CustomUpStreamHttpsProxyUsed
=
customUpStreamHttpsProxy
;
args
.
CustomUpStreamHttpsProxyUsed
=
customUpStreamHttpsProxy
;
return
await
tcpConnectionFactory
.
CreateClient
(
this
,
args
.
WebSession
.
Request
.
RequestUri
.
Host
,
args
.
WebSession
.
Request
.
RequestUri
.
Port
,
args
.
WebSession
.
Request
.
HttpVersion
,
args
.
IsHttps
,
customUpStreamHttpProxy
??
UpStreamHttpProxy
,
customUpStreamHttpsProxy
??
UpStreamHttpsProxy
,
args
.
ProxyClient
.
ClientStream
);
}
connection
=
await
tcpConnectionFactory
.
CreateClient
(
this
,
args
.
WebSession
.
Request
.
RequestUri
.
Host
,
args
.
WebSession
.
Request
.
RequestUri
.
Port
,
args
.
WebSession
.
Request
.
HttpVersion
,
args
.
IsHttps
,
customUpStreamHttpProxy
??
UpStreamHttpProxy
,
customUpStreamHttpsProxy
??
UpStreamHttpsProxy
,
args
.
ProxyClient
.
ClientStream
);
}
private
async
Task
<
bool
>
HandleHttpSessionRequestInternal
(
TcpConnection
connection
,
SessionEventArgs
args
,
bool
closeConnection
)
{
try
{
args
.
WebSession
.
Request
.
RequestLocked
=
true
;
args
.
WebSession
.
Request
.
RequestLocked
=
true
;
//If request was cancelled by user then dispose the client
//If request was cancelled by user then dispose the client
...
@@ -389,6 +394,8 @@ namespace Titanium.Web.Proxy
...
@@ -389,6 +394,8 @@ namespace Titanium.Web.Proxy
CustomBinaryReader
clientStreamReader
,
StreamWriter
clientStreamWriter
,
string
httpsHostName
,
CustomBinaryReader
clientStreamReader
,
StreamWriter
clientStreamWriter
,
string
httpsHostName
,
ProxyEndPoint
endPoint
,
List
<
HttpHeader
>
connectHeaders
,
ExternalProxy
customUpStreamHttpProxy
=
null
,
ExternalProxy
customUpStreamHttpsProxy
=
null
)
ProxyEndPoint
endPoint
,
List
<
HttpHeader
>
connectHeaders
,
ExternalProxy
customUpStreamHttpProxy
=
null
,
ExternalProxy
customUpStreamHttpsProxy
=
null
)
{
{
TcpConnection
connection
=
null
;
//Loop through each subsequest request on this particular client connection
//Loop through each subsequest request on this particular client connection
//(assuming HTTP connection is kept alive by client)
//(assuming HTTP connection is kept alive by client)
while
(
true
)
while
(
true
)
...
@@ -455,7 +462,7 @@ namespace Titanium.Web.Proxy
...
@@ -455,7 +462,7 @@ namespace Titanium.Web.Proxy
args
.
WebSession
.
Request
.
HttpVersion
=
httpVersion
;
args
.
WebSession
.
Request
.
HttpVersion
=
httpVersion
;
args
.
ProxyClient
.
ClientStream
=
clientStream
;
args
.
ProxyClient
.
ClientStream
=
clientStream
;
args
.
ProxyClient
.
ClientStreamReader
=
clientStreamReader
;
args
.
ProxyClient
.
ClientStreamReader
=
clientStreamReader
;
args
.
ProxyClient
.
ClientStreamWriter
=
clientStreamWriter
;
args
.
ProxyClient
.
ClientStreamWriter
=
clientStreamWriter
;
if
(
httpsHostName
==
null
&&
await
CheckAuthorization
(
clientStreamWriter
,
args
.
WebSession
.
Request
.
RequestHeaders
.
Values
)
==
false
)
if
(
httpsHostName
==
null
&&
await
CheckAuthorization
(
clientStreamWriter
,
args
.
WebSession
.
Request
.
RequestHeaders
.
Values
)
==
false
)
{
{
...
@@ -487,7 +494,7 @@ namespace Titanium.Web.Proxy
...
@@ -487,7 +494,7 @@ namespace Titanium.Web.Proxy
//if upgrading to websocket then relay the requet without reading the contents
//if upgrading to websocket then relay the requet without reading the contents
if
(
args
.
WebSession
.
Request
.
UpgradeToWebSocket
)
if
(
args
.
WebSession
.
Request
.
UpgradeToWebSocket
)
{
{
await
TcpHelper
.
SendRaw
(
this
,
await
TcpHelper
.
SendRaw
(
this
,
httpRemoteUri
.
Host
,
httpRemoteUri
.
Port
,
httpRemoteUri
.
Host
,
httpRemoteUri
.
Port
,
httpCmd
,
httpVersion
,
args
.
WebSession
.
Request
.
RequestHeaders
,
args
.
IsHttps
,
httpCmd
,
httpVersion
,
args
.
WebSession
.
Request
.
RequestHeaders
,
args
.
IsHttps
,
clientStream
,
tcpConnectionFactory
);
clientStream
,
tcpConnectionFactory
);
...
@@ -500,8 +507,13 @@ namespace Titanium.Web.Proxy
...
@@ -500,8 +507,13 @@ namespace Titanium.Web.Proxy
break
;
break
;
}
}
if
(
connection
==
null
)
{
connection
=
await
GetServerConnection
(
args
,
customUpStreamHttpProxy
,
customUpStreamHttpsProxy
,
false
);
}
//construct the web request that we are going to issue on behalf of the client.
//construct the web request that we are going to issue on behalf of the client.
var
result
=
await
HandleHttpSessionRequestInternal
(
null
,
args
,
customUpStreamHttpProxy
,
customUpStreamHttpsProxy
,
false
);
var
result
=
await
HandleHttpSessionRequestInternal
(
connection
,
args
,
false
);
if
(
result
==
false
)
if
(
result
==
false
)
{
{
...
@@ -545,6 +557,8 @@ namespace Titanium.Web.Proxy
...
@@ -545,6 +557,8 @@ namespace Titanium.Web.Proxy
}
}
}
}
connection
?.
Dispose
();
}
}
/// <summary>
/// <summary>
...
...
Titanium.Web.Proxy/ResponseHandler.cs
View file @
d49e55ad
...
@@ -53,7 +53,14 @@ namespace Titanium.Web.Proxy
...
@@ -53,7 +53,14 @@ namespace Titanium.Web.Proxy
if
(
args
.
ReRequest
)
if
(
args
.
ReRequest
)
{
{
await
HandleHttpSessionRequestInternal
(
null
,
args
,
null
,
null
,
true
);
if
(
args
.
WebSession
.
ServerConnection
!=
null
)
{
args
.
WebSession
.
ServerConnection
.
Dispose
();
ServerConnectionCount
--;
}
var
connection
=
await
GetServerConnection
(
args
,
null
,
null
,
true
);
await
HandleHttpSessionRequestInternal
(
null
,
args
,
true
);
return
true
;
return
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