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
ea42073c
Commit
ea42073c
authored
Nov 17, 2019
by
ByronP
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
change external proxy to use an interface so a custom class can be used
parent
21f81907
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
55 additions
and
18 deletions
+55
-18
SessionEventArgsBase.cs
...Titanium.Web.Proxy/EventArguments/SessionEventArgsBase.cs
+1
-1
WinHttpWebProxyFinder.cs
...tanium.Web.Proxy/Helpers/WinHttp/WinHttpWebProxyFinder.cs
+1
-1
ExternalProxy.cs
src/Titanium.Web.Proxy/Models/ExternalProxy.cs
+1
-1
IExternalProxy.cs
src/Titanium.Web.Proxy/Models/IExternalProxy.cs
+37
-0
TcpConnectionFactory.cs
src/Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs
+6
-6
TcpServerConnection.cs
src/Titanium.Web.Proxy/Network/Tcp/TcpServerConnection.cs
+2
-2
ProxyServer.cs
src/Titanium.Web.Proxy/ProxyServer.cs
+6
-6
NestedProxyTests.cs
...s/Titanium.Web.Proxy.IntegrationTests/NestedProxyTests.cs
+1
-1
No files found.
src/Titanium.Web.Proxy/EventArguments/SessionEventArgsBase.cs
View file @
ea42073c
...
@@ -106,7 +106,7 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -106,7 +106,7 @@ namespace Titanium.Web.Proxy.EventArguments
/// <summary>
/// <summary>
/// Are we using a custom upstream HTTP(S) proxy?
/// Are we using a custom upstream HTTP(S) proxy?
/// </summary>
/// </summary>
public
ExternalProxy
?
CustomUpStreamProxyUsed
{
get
;
internal
set
;
}
public
I
ExternalProxy
?
CustomUpStreamProxyUsed
{
get
;
internal
set
;
}
/// <summary>
/// <summary>
/// Local endpoint via which we make the request.
/// Local endpoint via which we make the request.
...
...
src/Titanium.Web.Proxy/Helpers/WinHttp/WinHttpWebProxyFinder.cs
View file @
ea42073c
...
@@ -95,7 +95,7 @@ namespace Titanium.Web.Proxy.Helpers.WinHttp
...
@@ -95,7 +95,7 @@ namespace Titanium.Web.Proxy.Helpers.WinHttp
return
true
;
return
true
;
}
}
public
ExternalProxy
?
GetProxy
(
Uri
destination
)
public
I
ExternalProxy
?
GetProxy
(
Uri
destination
)
{
{
if
(
GetAutoProxies
(
destination
,
out
var
proxies
))
if
(
GetAutoProxies
(
destination
,
out
var
proxies
))
{
{
...
...
src/Titanium.Web.Proxy/Models/ExternalProxy.cs
View file @
ea42073c
...
@@ -6,7 +6,7 @@ namespace Titanium.Web.Proxy.Models
...
@@ -6,7 +6,7 @@ namespace Titanium.Web.Proxy.Models
/// <summary>
/// <summary>
/// An upstream proxy this proxy uses if any.
/// An upstream proxy this proxy uses if any.
/// </summary>
/// </summary>
public
class
ExternalProxy
public
class
ExternalProxy
:
IExternalProxy
{
{
private
static
readonly
Lazy
<
NetworkCredential
>
defaultCredentials
=
private
static
readonly
Lazy
<
NetworkCredential
>
defaultCredentials
=
new
Lazy
<
NetworkCredential
>(()
=>
CredentialCache
.
DefaultNetworkCredentials
);
new
Lazy
<
NetworkCredential
>(()
=>
CredentialCache
.
DefaultNetworkCredentials
);
...
...
src/Titanium.Web.Proxy/Models/IExternalProxy.cs
0 → 100644
View file @
ea42073c
namespace
Titanium.Web.Proxy.Models
{
public
interface
IExternalProxy
{
/// <summary>
/// Use default windows credentials?
/// </summary>
public
bool
UseDefaultCredentials
{
get
;
set
;
}
/// <summary>
/// Bypass this proxy for connections to localhost?
/// </summary>
public
bool
BypassLocalhost
{
get
;
set
;
}
/// <summary>
/// Username.
/// </summary>
public
string
?
UserName
{
get
;
set
;
}
/// <summary>
/// Password.
/// </summary>
string
?
Password
{
get
;
set
;
}
/// <summary>
/// Host name.
/// </summary>
string
HostName
{
get
;
set
;
}
/// <summary>
/// Port.
/// </summary>
int
Port
{
get
;
set
;
}
string
ToString
();
}
}
src/Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs
View file @
ea42073c
...
@@ -49,7 +49,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
...
@@ -49,7 +49,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
internal
string
GetConnectionCacheKey
(
string
remoteHostName
,
int
remotePort
,
internal
string
GetConnectionCacheKey
(
string
remoteHostName
,
int
remotePort
,
bool
isHttps
,
List
<
SslApplicationProtocol
>?
applicationProtocols
,
bool
isHttps
,
List
<
SslApplicationProtocol
>?
applicationProtocols
,
IPEndPoint
?
upStreamEndPoint
,
ExternalProxy
?
externalProxy
)
IPEndPoint
?
upStreamEndPoint
,
I
ExternalProxy
?
externalProxy
)
{
{
// http version is ignored since its an application level decision b/w HTTP 1.0/1.1
// http version is ignored since its an application level decision b/w HTTP 1.0/1.1
// also when doing connect request MS Edge browser sends http 1.0 but uses 1.1 after server sends 1.1 its response.
// also when doing connect request MS Edge browser sends http 1.0 but uses 1.1 after server sends 1.1 its response.
...
@@ -115,7 +115,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
...
@@ -115,7 +115,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
applicationProtocols
=
new
List
<
SslApplicationProtocol
>
{
applicationProtocol
};
applicationProtocols
=
new
List
<
SslApplicationProtocol
>
{
applicationProtocol
};
}
}
ExternalProxy
?
customUpStreamProxy
=
null
;
I
ExternalProxy
?
customUpStreamProxy
=
null
;
bool
isHttps
=
session
.
IsHttps
;
bool
isHttps
=
session
.
IsHttps
;
if
(
server
.
GetCustomUpStreamProxyFunc
!=
null
)
if
(
server
.
GetCustomUpStreamProxyFunc
!=
null
)
...
@@ -170,7 +170,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
...
@@ -170,7 +170,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
internal
async
Task
<
TcpServerConnection
>
GetServerConnection
(
ProxyServer
server
,
SessionEventArgsBase
session
,
bool
isConnect
,
internal
async
Task
<
TcpServerConnection
>
GetServerConnection
(
ProxyServer
server
,
SessionEventArgsBase
session
,
bool
isConnect
,
List
<
SslApplicationProtocol
>?
applicationProtocols
,
bool
noCache
,
CancellationToken
cancellationToken
)
List
<
SslApplicationProtocol
>?
applicationProtocols
,
bool
noCache
,
CancellationToken
cancellationToken
)
{
{
ExternalProxy
?
customUpStreamProxy
=
null
;
I
ExternalProxy
?
customUpStreamProxy
=
null
;
bool
isHttps
=
session
.
IsHttps
;
bool
isHttps
=
session
.
IsHttps
;
if
(
server
.
GetCustomUpStreamProxyFunc
!=
null
)
if
(
server
.
GetCustomUpStreamProxyFunc
!=
null
)
...
@@ -208,7 +208,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
...
@@ -208,7 +208,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
/// <returns></returns>
/// <returns></returns>
internal
async
Task
<
TcpServerConnection
>
GetServerConnection
(
string
remoteHostName
,
int
remotePort
,
internal
async
Task
<
TcpServerConnection
>
GetServerConnection
(
string
remoteHostName
,
int
remotePort
,
Version
httpVersion
,
bool
isHttps
,
List
<
SslApplicationProtocol
>?
applicationProtocols
,
bool
isConnect
,
Version
httpVersion
,
bool
isHttps
,
List
<
SslApplicationProtocol
>?
applicationProtocols
,
bool
isConnect
,
ProxyServer
proxyServer
,
SessionEventArgsBase
?
session
,
IPEndPoint
?
upStreamEndPoint
,
ExternalProxy
?
externalProxy
,
ProxyServer
proxyServer
,
SessionEventArgsBase
?
session
,
IPEndPoint
?
upStreamEndPoint
,
I
ExternalProxy
?
externalProxy
,
bool
noCache
,
CancellationToken
cancellationToken
)
bool
noCache
,
CancellationToken
cancellationToken
)
{
{
var
sslProtocol
=
session
?.
ProxyClient
.
Connection
.
SslProtocol
??
SslProtocols
.
None
;
var
sslProtocol
=
session
?.
ProxyClient
.
Connection
.
SslProtocol
??
SslProtocols
.
None
;
...
@@ -262,7 +262,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
...
@@ -262,7 +262,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
/// <returns></returns>
/// <returns></returns>
private
async
Task
<
TcpServerConnection
>
createServerConnection
(
string
remoteHostName
,
int
remotePort
,
private
async
Task
<
TcpServerConnection
>
createServerConnection
(
string
remoteHostName
,
int
remotePort
,
Version
httpVersion
,
bool
isHttps
,
SslProtocols
sslProtocol
,
List
<
SslApplicationProtocol
>?
applicationProtocols
,
bool
isConnect
,
Version
httpVersion
,
bool
isHttps
,
SslProtocols
sslProtocol
,
List
<
SslApplicationProtocol
>?
applicationProtocols
,
bool
isConnect
,
ProxyServer
proxyServer
,
SessionEventArgsBase
?
session
,
IPEndPoint
?
upStreamEndPoint
,
ExternalProxy
?
externalProxy
,
string
cacheKey
,
ProxyServer
proxyServer
,
SessionEventArgsBase
?
session
,
IPEndPoint
?
upStreamEndPoint
,
I
ExternalProxy
?
externalProxy
,
string
cacheKey
,
CancellationToken
cancellationToken
)
CancellationToken
cancellationToken
)
{
{
// deny connection to proxy end points to avoid infinite connection loop.
// deny connection to proxy end points to avoid infinite connection loop.
...
@@ -304,7 +304,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
...
@@ -304,7 +304,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
bool
retry
=
true
;
bool
retry
=
true
;
var
enabledSslProtocols
=
sslProtocol
;
var
enabledSslProtocols
=
sslProtocol
;
retry
:
retry
:
try
try
{
{
string
hostname
=
useUpstreamProxy
?
externalProxy
!.
HostName
:
remoteHostName
;
string
hostname
=
useUpstreamProxy
?
externalProxy
!.
HostName
:
remoteHostName
;
...
...
src/Titanium.Web.Proxy/Network/Tcp/TcpServerConnection.cs
View file @
ea42073c
...
@@ -17,7 +17,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
...
@@ -17,7 +17,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
{
{
internal
TcpServerConnection
(
ProxyServer
proxyServer
,
TcpClient
tcpClient
,
CustomBufferedStream
stream
,
internal
TcpServerConnection
(
ProxyServer
proxyServer
,
TcpClient
tcpClient
,
CustomBufferedStream
stream
,
string
hostName
,
int
port
,
bool
isHttps
,
SslApplicationProtocol
negotiatedApplicationProtocol
,
string
hostName
,
int
port
,
bool
isHttps
,
SslApplicationProtocol
negotiatedApplicationProtocol
,
Version
version
,
bool
useUpstreamProxy
,
ExternalProxy
?
upStreamProxy
,
IPEndPoint
?
upStreamEndPoint
,
string
cacheKey
)
Version
version
,
bool
useUpstreamProxy
,
I
ExternalProxy
?
upStreamProxy
,
IPEndPoint
?
upStreamEndPoint
,
string
cacheKey
)
{
{
this
.
tcpClient
=
tcpClient
;
this
.
tcpClient
=
tcpClient
;
LastAccess
=
DateTime
.
Now
;
LastAccess
=
DateTime
.
Now
;
...
@@ -41,7 +41,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
...
@@ -41,7 +41,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
internal
bool
IsClosed
=>
Stream
.
IsClosed
;
internal
bool
IsClosed
=>
Stream
.
IsClosed
;
internal
ExternalProxy
?
UpStreamProxy
{
get
;
set
;
}
internal
I
ExternalProxy
?
UpStreamProxy
{
get
;
set
;
}
internal
string
HostName
{
get
;
set
;
}
internal
string
HostName
{
get
;
set
;
}
...
...
src/Titanium.Web.Proxy/ProxyServer.cs
View file @
ea42073c
...
@@ -61,7 +61,7 @@ namespace Titanium.Web.Proxy
...
@@ -61,7 +61,7 @@ namespace Titanium.Web.Proxy
/// </summary>
/// </summary>
private
WinHttpWebProxyFinder
?
systemProxyResolver
;
private
WinHttpWebProxyFinder
?
systemProxyResolver
;
/// <inheritdoc />
/// <inheritdoc />
/// <summary>
/// <summary>
/// Initializes a new instance of ProxyServer class with provided parameters.
/// Initializes a new instance of ProxyServer class with provided parameters.
...
@@ -145,7 +145,7 @@ namespace Titanium.Web.Proxy
...
@@ -145,7 +145,7 @@ namespace Titanium.Web.Proxy
/// Defaults to false.
/// Defaults to false.
/// </summary>
/// </summary>
public
bool
EnableWinAuth
{
get
;
set
;
}
public
bool
EnableWinAuth
{
get
;
set
;
}
/// <summary>
/// <summary>
/// Enable disable HTTP/2 support.
/// Enable disable HTTP/2 support.
/// Warning: HTTP/2 support is very limited
/// Warning: HTTP/2 support is very limited
...
@@ -253,12 +253,12 @@ namespace Titanium.Web.Proxy
...
@@ -253,12 +253,12 @@ namespace Titanium.Web.Proxy
/// <summary>
/// <summary>
/// External proxy used for Http requests.
/// External proxy used for Http requests.
/// </summary>
/// </summary>
public
ExternalProxy
?
UpStreamHttpProxy
{
get
;
set
;
}
public
I
ExternalProxy
?
UpStreamHttpProxy
{
get
;
set
;
}
/// <summary>
/// <summary>
/// External proxy used for Https requests.
/// External proxy used for Https requests.
/// </summary>
/// </summary>
public
ExternalProxy
?
UpStreamHttpsProxy
{
get
;
set
;
}
public
I
ExternalProxy
?
UpStreamHttpsProxy
{
get
;
set
;
}
/// <summary>
/// <summary>
/// Local adapter/NIC endpoint where proxy makes request via.
/// Local adapter/NIC endpoint where proxy makes request via.
...
@@ -275,7 +275,7 @@ namespace Titanium.Web.Proxy
...
@@ -275,7 +275,7 @@ namespace Titanium.Web.Proxy
/// A callback to provide authentication credentials for up stream proxy this proxy is using for HTTP(S) requests.
/// A callback to provide authentication credentials for up stream proxy this proxy is using for HTTP(S) requests.
/// User should return the ExternalProxy object with valid credentials.
/// User should return the ExternalProxy object with valid credentials.
/// </summary>
/// </summary>
public
Func
<
SessionEventArgsBase
,
Task
<
ExternalProxy
?>>?
GetCustomUpStreamProxyFunc
{
get
;
set
;
}
public
Func
<
SessionEventArgsBase
,
Task
<
I
ExternalProxy
?>>?
GetCustomUpStreamProxyFunc
{
get
;
set
;
}
/// <summary>
/// <summary>
/// Callback for error events in this proxy instance.
/// Callback for error events in this proxy instance.
...
@@ -709,7 +709,7 @@ namespace Titanium.Web.Proxy
...
@@ -709,7 +709,7 @@ namespace Titanium.Web.Proxy
/// </summary>
/// </summary>
/// <param name="sessionEventArgs">The session.</param>
/// <param name="sessionEventArgs">The session.</param>
/// <returns>The external proxy as task result.</returns>
/// <returns>The external proxy as task result.</returns>
private
Task
<
ExternalProxy
?>
getSystemUpStreamProxy
(
SessionEventArgsBase
sessionEventArgs
)
private
Task
<
I
ExternalProxy
?>
getSystemUpStreamProxy
(
SessionEventArgsBase
sessionEventArgs
)
{
{
var
proxy
=
systemProxyResolver
!.
GetProxy
(
sessionEventArgs
.
HttpClient
.
Request
.
RequestUri
);
var
proxy
=
systemProxyResolver
!.
GetProxy
(
sessionEventArgs
.
HttpClient
.
Request
.
RequestUri
);
return
Task
.
FromResult
(
proxy
);
return
Task
.
FromResult
(
proxy
);
...
...
tests/Titanium.Web.Proxy.IntegrationTests/NestedProxyTests.cs
View file @
ea42073c
...
@@ -69,7 +69,7 @@ namespace Titanium.Web.Proxy.IntegrationTests
...
@@ -69,7 +69,7 @@ namespace Titanium.Web.Proxy.IntegrationTests
};
};
var
client
=
testSuite
.
GetClient
(
proxy1
,
true
);
var
client
=
testSuite
.
GetClient
(
proxy1
,
true
);
var
response
=
await
client
.
PostAsync
(
new
Uri
(
server
.
ListeningHttpsUrl
),
var
response
=
await
client
.
PostAsync
(
new
Uri
(
server
.
ListeningHttpsUrl
),
new
StringContent
(
"hello server. I am a client."
));
new
StringContent
(
"hello server. I am a client."
));
...
...
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