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
2e9e1154
Unverified
Commit
2e9e1154
authored
Nov 22, 2019
by
honfika
Committed by
GitHub
Nov 22, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #678 from ByronAP/master
Adds ability to handle upstream proxy connect failures
parents
0366b348
69aa126c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
0 deletions
+32
-0
ProxyTestController.cs
.../Titanium.Web.Proxy.Examples.Basic/ProxyTestController.cs
+16
-0
TcpConnectionFactory.cs
src/Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs
+10
-0
ProxyServer.cs
src/Titanium.Web.Proxy/ProxyServer.cs
+6
-0
No files found.
examples/Titanium.Web.Proxy.Examples.Basic/ProxyTestController.cs
View file @
2e9e1154
...
@@ -42,6 +42,10 @@ namespace Titanium.Web.Proxy.Examples.Basic
...
@@ -42,6 +42,10 @@ namespace Titanium.Web.Proxy.Examples.Basic
proxyServer
.
ForwardToUpstreamGateway
=
true
;
proxyServer
.
ForwardToUpstreamGateway
=
true
;
proxyServer
.
CertificateManager
.
SaveFakeCertificates
=
true
;
proxyServer
.
CertificateManager
.
SaveFakeCertificates
=
true
;
// this is just to show the functionality, provided implementations use junk value
//proxyServer.GetCustomUpStreamProxyFunc = onGetCustomUpStreamProxyFunc;
//proxyServer.CustomUpStreamProxyFailureFunc = onCustomUpStreamProxyFailureFunc;
// optionally set the Certificate Engine
// optionally set the Certificate Engine
// Under Mono or Non-Windows runtimes only BouncyCastle will be supported
// Under Mono or Non-Windows runtimes only BouncyCastle will be supported
//proxyServer.CertificateManager.CertificateEngine = Network.CertificateEngine.BouncyCastle;
//proxyServer.CertificateManager.CertificateEngine = Network.CertificateEngine.BouncyCastle;
...
@@ -116,6 +120,18 @@ namespace Titanium.Web.Proxy.Examples.Basic
...
@@ -116,6 +120,18 @@ namespace Titanium.Web.Proxy.Examples.Basic
//proxyServer.CertificateManager.RemoveTrustedRootCertificates();
//proxyServer.CertificateManager.RemoveTrustedRootCertificates();
}
}
private
async
Task
<
IExternalProxy
>
onGetCustomUpStreamProxyFunc
(
SessionEventArgsBase
arg
)
{
// this is just to show the functionality, provided values are junk
return
new
ExternalProxy
()
{
BypassLocalhost
=
false
,
HostName
=
"127.0.0.9"
,
Port
=
9090
,
Password
=
"fake"
,
UserName
=
"fake"
,
UseDefaultCredentials
=
false
};
}
private
async
Task
<
IExternalProxy
>
onCustomUpStreamProxyFailureFunc
(
SessionEventArgsBase
arg
)
{
// this is just to show the functionality, provided values are junk
return
new
ExternalProxy
()
{
BypassLocalhost
=
false
,
HostName
=
"127.0.0.10"
,
Port
=
9191
,
Password
=
"fake2"
,
UserName
=
"fake2"
,
UseDefaultCredentials
=
false
};
}
private
async
Task
onBeforeTunnelConnectRequest
(
object
sender
,
TunnelConnectSessionEventArgs
e
)
private
async
Task
onBeforeTunnelConnectRequest
(
object
sender
,
TunnelConnectSessionEventArgs
e
)
{
{
string
hostname
=
e
.
HttpClient
.
Request
.
RequestUri
.
Host
;
string
hostname
=
e
.
HttpClient
.
Request
.
RequestUri
.
Host
;
...
...
src/Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs
View file @
2e9e1154
...
@@ -397,6 +397,16 @@ retry:
...
@@ -397,6 +397,16 @@ retry:
if
(
tcpClient
==
null
)
if
(
tcpClient
==
null
)
{
{
if
(
session
!=
null
&&
proxyServer
.
CustomUpStreamProxyFailureFunc
!=
null
)
{
var
newUpstreamProxy
=
await
proxyServer
.
CustomUpStreamProxyFailureFunc
(
session
);
if
(
newUpstreamProxy
!=
null
)
{
session
.
CustomUpStreamProxyUsed
=
newUpstreamProxy
;
session
.
TimeLine
[
"Retrying Upstream Proxy Connection"
]
=
DateTime
.
Now
;
return
await
createServerConnection
(
remoteHostName
,
remotePort
,
httpVersion
,
isHttps
,
sslProtocol
,
applicationProtocols
,
isConnect
,
proxyServer
,
session
,
upStreamEndPoint
,
externalProxy
,
cacheKey
,
cancellationToken
);
}
}
throw
new
Exception
(
$"Could not establish connection to
{
hostname
}
"
,
lastException
);
throw
new
Exception
(
$"Could not establish connection to
{
hostname
}
"
,
lastException
);
}
}
...
...
src/Titanium.Web.Proxy/ProxyServer.cs
View file @
2e9e1154
...
@@ -283,6 +283,12 @@ namespace Titanium.Web.Proxy
...
@@ -283,6 +283,12 @@ namespace Titanium.Web.Proxy
/// </summary>
/// </summary>
public
Func
<
SessionEventArgsBase
,
Task
<
IExternalProxy
?>>?
GetCustomUpStreamProxyFunc
{
get
;
set
;
}
public
Func
<
SessionEventArgsBase
,
Task
<
IExternalProxy
?>>?
GetCustomUpStreamProxyFunc
{
get
;
set
;
}
/// <summary>
/// A callback to provide a chance for an upstream proxy failure to be handled by a new upstream proxy.
/// User should return the ExternalProxy object with valid credentials or null.
/// </summary>
public
Func
<
SessionEventArgsBase
,
Task
<
IExternalProxy
?>>?
CustomUpStreamProxyFailureFunc
{
get
;
set
;
}
/// <summary>
/// <summary>
/// Callback for error events in this proxy instance.
/// Callback for error events in this proxy instance.
/// </summary>
/// </summary>
...
...
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