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
066d4309
Commit
066d4309
authored
Sep 27, 2018
by
justcoding121
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#495 Add Dns Resolution datetime to timeline
parent
87ec92ce
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
39 additions
and
34 deletions
+39
-34
settings.json
.vscode/settings.json
+2
-2
omnisharp.json
omnisharp.json
+1
-0
TcpConnectionFactory.cs
src/Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs
+30
-26
ProxyServer.cs
src/Titanium.Web.Proxy/ProxyServer.cs
+1
-3
RequestHandler.cs
src/Titanium.Web.Proxy/RequestHandler.cs
+3
-1
TransparentClientHandler.cs
src/Titanium.Web.Proxy/TransparentClientHandler.cs
+2
-2
No files found.
.vscode/settings.json
View file @
066d4309
...
...
@@ -15,7 +15,7 @@
"**/*.Basic.csproj/"
:
true
,
"**/*.Docs.csproj/"
:
true
,
"**/*.Proxy.csproj/"
:
true
,
"**/*.
Proxy
.csproj"
:
true
"**/*.
Mono
.csproj"
:
true
},
"search.exclude"
:
{
"**/.build"
:
true
,
...
...
@@ -32,6 +32,6 @@
"**/*.Basic.csproj/"
:
true
,
"**/*.Docs.csproj/"
:
true
,
"**/*.Proxy.csproj/"
:
true
,
"**/*.
Proxy
.csproj"
:
true
"**/*.
Mono
.csproj"
:
true
}
}
\ No newline at end of file
omnisharp.json
View file @
066d4309
{
"fileOptions"
:
{
"excludeSearchPatterns"
:
[
"**/*.sln"
,
"**/*.Docs.csproj"
,
"**/tests/"
,
"**/Titanium.Web.Proxy.Examples.Wpf/"
,
...
...
src/Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs
View file @
066d4309
...
...
@@ -76,10 +76,10 @@ namespace Titanium.Web.Proxy.Network.Tcp
/// <summary>
/// Gets the connection cache key.
/// </summary>
/// <param name="
args
">The session event arguments.</param>
/// <param name="
session
">The session event arguments.</param>
/// <param name="applicationProtocol"></param>
/// <returns></returns>
internal
async
Task
<
string
>
GetConnectionCacheKey
(
ProxyServer
server
,
SessionEventArgsBase
args
,
internal
async
Task
<
string
>
GetConnectionCacheKey
(
ProxyServer
server
,
SessionEventArgsBase
session
,
SslApplicationProtocol
applicationProtocol
)
{
List
<
SslApplicationProtocol
>
applicationProtocols
=
null
;
...
...
@@ -90,19 +90,19 @@ namespace Titanium.Web.Proxy.Network.Tcp
ExternalProxy
customUpStreamProxy
=
null
;
bool
isHttps
=
args
.
IsHttps
;
bool
isHttps
=
session
.
IsHttps
;
if
(
server
.
GetCustomUpStreamProxyFunc
!=
null
)
{
customUpStreamProxy
=
await
server
.
GetCustomUpStreamProxyFunc
(
args
);
customUpStreamProxy
=
await
server
.
GetCustomUpStreamProxyFunc
(
session
);
}
args
.
CustomUpStreamProxyUsed
=
customUpStreamProxy
;
session
.
CustomUpStreamProxyUsed
=
customUpStreamProxy
;
return
GetConnectionCacheKey
(
args
.
WebSession
.
Request
.
RequestUri
.
Host
,
args
.
WebSession
.
Request
.
RequestUri
.
Port
,
session
.
WebSession
.
Request
.
RequestUri
.
Host
,
session
.
WebSession
.
Request
.
RequestUri
.
Port
,
isHttps
,
applicationProtocols
,
server
,
args
.
WebSession
.
UpStreamEndPoint
??
server
.
UpStreamEndPoint
,
server
,
session
.
WebSession
.
UpStreamEndPoint
??
server
.
UpStreamEndPoint
,
customUpStreamProxy
??
(
isHttps
?
server
.
UpStreamHttpsProxy
:
server
.
UpStreamHttpProxy
));
}
...
...
@@ -110,12 +110,12 @@ namespace Titanium.Web.Proxy.Network.Tcp
/// <summary>
/// Create a server connection.
/// </summary>
/// <param name="
args
">The session event arguments.</param>
/// <param name="
session
">The session event arguments.</param>
/// <param name="isConnect">Is this a CONNECT request.</param>
/// <param name="applicationProtocol"></param>
/// <param name="cancellationToken">The cancellation token for this async task.</param>
/// <returns></returns>
internal
Task
<
TcpServerConnection
>
GetServerConnection
(
ProxyServer
server
,
SessionEventArgsBase
args
,
bool
isConnect
,
internal
Task
<
TcpServerConnection
>
GetServerConnection
(
ProxyServer
server
,
SessionEventArgsBase
session
,
bool
isConnect
,
SslApplicationProtocol
applicationProtocol
,
bool
noCache
,
CancellationToken
cancellationToken
)
{
List
<
SslApplicationProtocol
>
applicationProtocols
=
null
;
...
...
@@ -124,36 +124,36 @@ namespace Titanium.Web.Proxy.Network.Tcp
applicationProtocols
=
new
List
<
SslApplicationProtocol
>
{
applicationProtocol
};
}
return
GetServerConnection
(
server
,
args
,
isConnect
,
applicationProtocols
,
noCache
,
cancellationToken
);
return
GetServerConnection
(
server
,
session
,
isConnect
,
applicationProtocols
,
noCache
,
cancellationToken
);
}
/// <summary>
/// Create a server connection.
/// </summary>
/// <param name="
args
">The session event arguments.</param>
/// <param name="
session
">The session event arguments.</param>
/// <param name="isConnect">Is this a CONNECT request.</param>
/// <param name="applicationProtocols"></param>
/// <param name="cancellationToken">The cancellation token for this async task.</param>
/// <returns></returns>
internal
async
Task
<
TcpServerConnection
>
GetServerConnection
(
ProxyServer
server
,
SessionEventArgsBase
args
,
bool
isConnect
,
internal
async
Task
<
TcpServerConnection
>
GetServerConnection
(
ProxyServer
server
,
SessionEventArgsBase
session
,
bool
isConnect
,
List
<
SslApplicationProtocol
>
applicationProtocols
,
bool
noCache
,
CancellationToken
cancellationToken
)
{
ExternalProxy
customUpStreamProxy
=
null
;
bool
isHttps
=
args
.
IsHttps
;
bool
isHttps
=
session
.
IsHttps
;
if
(
server
.
GetCustomUpStreamProxyFunc
!=
null
)
{
customUpStreamProxy
=
await
server
.
GetCustomUpStreamProxyFunc
(
args
);
customUpStreamProxy
=
await
server
.
GetCustomUpStreamProxyFunc
(
session
);
}
args
.
CustomUpStreamProxyUsed
=
customUpStreamProxy
;
session
.
CustomUpStreamProxyUsed
=
customUpStreamProxy
;
return
await
GetServerConnection
(
args
.
WebSession
.
Request
.
RequestUri
.
Host
,
args
.
WebSession
.
Request
.
RequestUri
.
Port
,
args
.
WebSession
.
Request
.
HttpVersion
,
session
.
WebSession
.
Request
.
RequestUri
.
Host
,
session
.
WebSession
.
Request
.
RequestUri
.
Port
,
session
.
WebSession
.
Request
.
HttpVersion
,
isHttps
,
applicationProtocols
,
isConnect
,
server
,
args
.
WebSession
.
UpStreamEndPoint
??
server
.
UpStreamEndPoint
,
server
,
session
,
session
.
WebSession
.
UpStreamEndPoint
??
server
.
UpStreamEndPoint
,
customUpStreamProxy
??
(
isHttps
?
server
.
UpStreamHttpsProxy
:
server
.
UpStreamHttpProxy
),
noCache
,
cancellationToken
);
}
...
...
@@ -174,7 +174,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
/// <returns></returns>
internal
async
Task
<
TcpServerConnection
>
GetServerConnection
(
string
remoteHostName
,
int
remotePort
,
Version
httpVersion
,
bool
isHttps
,
List
<
SslApplicationProtocol
>
applicationProtocols
,
bool
isConnect
,
ProxyServer
proxyServer
,
IPEndPoint
upStreamEndPoint
,
ExternalProxy
externalProxy
,
ProxyServer
proxyServer
,
SessionEventArgsBase
session
,
IPEndPoint
upStreamEndPoint
,
ExternalProxy
externalProxy
,
bool
noCache
,
CancellationToken
cancellationToken
)
{
var
cacheKey
=
GetConnectionCacheKey
(
remoteHostName
,
remotePort
,
...
...
@@ -205,7 +205,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
}
var
connection
=
await
createServerConnection
(
remoteHostName
,
remotePort
,
httpVersion
,
isHttps
,
applicationProtocols
,
isConnect
,
proxyServer
,
upStreamEndPoint
,
externalProxy
,
cancellationToken
);
applicationProtocols
,
isConnect
,
proxyServer
,
session
,
upStreamEndPoint
,
externalProxy
,
cancellationToken
);
connection
.
CacheKey
=
cacheKey
;
...
...
@@ -222,13 +222,14 @@ namespace Titanium.Web.Proxy.Network.Tcp
/// <param name="applicationProtocols">The list of HTTPS application level protocol to negotiate if needed.</param>
/// <param name="isConnect">Is this a CONNECT request.</param>
/// <param name="proxyServer">The current ProxyServer instance.</param>
/// <param name="session">The http session.</param>
/// <param name="upStreamEndPoint">The local upstream endpoint to make request via.</param>
/// <param name="externalProxy">The external proxy to make request via.</param>
/// <param name="cancellationToken">The cancellation token for this async task.</param>
/// <returns></returns>
private
async
Task
<
TcpServerConnection
>
createServerConnection
(
string
remoteHostName
,
int
remotePort
,
Version
httpVersion
,
bool
isHttps
,
List
<
SslApplicationProtocol
>
applicationProtocols
,
bool
isConnect
,
ProxyServer
proxyServer
,
IPEndPoint
upStreamEndPoint
,
ExternalProxy
externalProxy
,
ProxyServer
proxyServer
,
SessionEventArgsBase
session
,
IPEndPoint
upStreamEndPoint
,
ExternalProxy
externalProxy
,
CancellationToken
cancellationToken
)
{
//deny connection to proxy end points to avoid infinite connection loop.
...
...
@@ -288,14 +289,14 @@ namespace Titanium.Web.Proxy.Network.Tcp
var
port
=
useUpstreamProxy
?
externalProxy
.
Port
:
remotePort
;
var
ipHostEntry
=
await
Dns
.
GetHostEntryAsync
(
hostname
);
if
(
ipHostEntry
==
null
||
ipHostEntry
.
AddressList
.
Length
==
0
)
{
throw
new
Exception
(
$"Could not resolve the hostname
{
hostname
}
"
);
}
session
.
TimeLine
[
"Dns Resolved"
]
=
DateTime
.
Now
;
var
ipAddresses
=
ipHostEntry
.
AddressList
.
OrderBy
(
x
=>
rnd
.
Next
()).
ToArray
();
for
(
int
i
=
0
;
i
<
ipAddresses
.
Length
;
i
++)
{
...
...
@@ -308,11 +309,13 @@ namespace Titanium.Web.Proxy.Network.Tcp
{
if
(
i
==
ipAddresses
.
Length
-
1
)
{
throw
new
Exception
(
$"Could not
resolve the hostname
{
hostname
}
"
,
e
);
throw
new
Exception
(
$"Could not
establish connection to
{
hostname
}
"
,
e
);
}
}
}
session
.
TimeLine
[
"Connection Established"
]
=
DateTime
.
Now
;
await
proxyServer
.
InvokeConnectionCreateEvent
(
tcpClient
,
false
);
stream
=
new
CustomBufferedStream
(
tcpClient
.
GetStream
(),
proxyServer
.
BufferPool
,
proxyServer
.
BufferSize
);
...
...
@@ -368,6 +371,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
#if NETCOREAPP2_1
negotiatedApplicationProtocol
=
sslStream
.
NegotiatedApplicationProtocol
;
#endif
session
.
TimeLine
[
"HTTPS Established"
]
=
DateTime
.
Now
;
}
}
catch
(
Exception
)
...
...
src/Titanium.Web.Proxy/ProxyServer.cs
View file @
066d4309
...
...
@@ -94,8 +94,6 @@ namespace Titanium.Web.Proxy
bool
userTrustRootCertificate
=
true
,
bool
machineTrustRootCertificate
=
false
,
bool
trustRootCertificateAsAdmin
=
false
)
{
// default values
ConnectionTimeOutSeconds
=
60
;
if
(
BufferPool
==
null
)
{
...
...
@@ -186,7 +184,7 @@ namespace Titanium.Web.Proxy
/// This will also determine the pool eviction time when connection pool is enabled.
/// Default value is 60 seconds.
/// </summary>
public
int
ConnectionTimeOutSeconds
{
get
;
set
;
}
public
int
ConnectionTimeOutSeconds
{
get
;
set
;
}
=
60
;
/// <summary>
/// Maximum number of concurrent connections per remote host in cache.
...
...
src/Titanium.Web.Proxy/RequestHandler.cs
View file @
066d4309
...
...
@@ -207,7 +207,7 @@ namespace Titanium.Web.Proxy
//for connection pool, retry fails until cache is exhausted.
var
result
=
await
retryPolicy
<
ServerConnectionException
>().
ExecuteAsync
(
async
(
serverConnection
)
=>
{
args
.
TimeLine
[
"
Server Connection Created
"
]
=
DateTime
.
Now
;
args
.
TimeLine
[
"
Connection Ready
"
]
=
DateTime
.
Now
;
// if upgrading to websocket then relay the request without reading the contents
if
(
request
.
UpgradeToWebSocket
)
...
...
@@ -369,6 +369,8 @@ namespace Titanium.Web.Proxy
}
}
args
.
TimeLine
[
"Request Sent"
]
=
DateTime
.
Now
;
// If not expectation failed response was returned by server then parse response
if
(!
request
.
ExpectationFailed
)
{
...
...
src/Titanium.Web.Proxy/TransparentClientHandler.cs
View file @
066d4309
...
...
@@ -69,7 +69,7 @@ namespace Titanium.Web.Proxy
//it could cause floating server connections when client exits
prefetchConnectionTask
=
tcpConnectionFactory
.
GetServerConnection
(
httpsHostName
,
endPoint
.
Port
,
httpVersion
:
null
,
isHttps
:
true
,
applicationProtocols
:
null
,
isConnect
:
false
,
proxyServer
:
this
,
upStreamEndPoint
:
UpStreamEndPoint
,
externalProxy
:
UpStreamHttpsProxy
,
proxyServer
:
this
,
session
:
null
,
upStreamEndPoint
:
UpStreamEndPoint
,
externalProxy
:
UpStreamHttpsProxy
,
noCache
:
false
,
cancellationToken
:
CancellationToken
.
None
);
}
...
...
@@ -102,7 +102,7 @@ namespace Titanium.Web.Proxy
{
var
connection
=
await
tcpConnectionFactory
.
GetServerConnection
(
httpsHostName
,
endPoint
.
Port
,
httpVersion
:
null
,
isHttps
:
false
,
applicationProtocols
:
null
,
isConnect
:
true
,
proxyServer
:
this
,
upStreamEndPoint
:
UpStreamEndPoint
,
isConnect
:
true
,
proxyServer
:
this
,
session
:
null
,
upStreamEndPoint
:
UpStreamEndPoint
,
externalProxy
:
UpStreamHttpsProxy
,
noCache
:
true
,
cancellationToken
:
cancellationToken
);
try
...
...
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