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
8e254c99
Commit
8e254c99
authored
May 09, 2017
by
Jehonathan Thomas
Committed by
GitHub
May 09, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #209 from danielherken/develop
Added option to bypass external proxy for localhost connections
parents
d0fc544f
2253c149
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
8 deletions
+56
-8
Network.cs
Titanium.Web.Proxy/Helpers/Network.cs
+44
-6
ExternalProxy.cs
Titanium.Web.Proxy/Models/ExternalProxy.cs
+5
-0
TcpConnectionFactory.cs
Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs
+7
-2
No files found.
Titanium.Web.Proxy/Helpers/Network.cs
View file @
8e254c99
using
System.Linq
;
using
System.Linq
;
using
System.Net
;
using
System.Net
;
using
System.Net.Sockets
;
namespace
Titanium.Web.Proxy.Helpers
namespace
Titanium.Web.Proxy.Helpers
{
{
internal
class
NetworkHelper
internal
class
NetworkHelper
...
@@ -31,12 +32,49 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -31,12 +32,49 @@ namespace Titanium.Web.Proxy.Helpers
/// </summary>
/// </summary>
/// <param name="address"></param>
/// <param name="address"></param>
/// <returns></returns>
/// <returns></returns>
internal
static
bool
IsLocalIpAddress
(
IPAddress
address
)
internal
static
bool
IsLocalIpAddress
(
IPAddress
address
)
{
// get local IP addresses
var
localIPs
=
Dns
.
GetHostAddresses
(
Dns
.
GetHostName
());
// test if any host IP equals to any local IP or to localhost
return
IPAddress
.
IsLoopback
(
address
)
||
localIPs
.
Contains
(
address
);
}
internal
static
bool
IsLocalIpAddress
(
string
hostName
)
{
{
// get local IP addresses
bool
isLocalhost
=
false
;
var
localIPs
=
Dns
.
GetHostAddresses
(
Dns
.
GetHostName
());
// test if any host IP equals to any local IP or to localhost
IPHostEntry
localhost
=
Dns
.
GetHostEntry
(
"127.0.0.1"
);
return
IPAddress
.
IsLoopback
(
address
)
||
localIPs
.
Contains
(
address
);
if
(
hostName
==
localhost
.
HostName
)
{
IPHostEntry
hostEntry
=
Dns
.
GetHostEntry
(
hostName
);
isLocalhost
=
hostEntry
.
AddressList
.
Any
(
IPAddress
.
IsLoopback
);
}
if
(!
isLocalhost
)
{
localhost
=
Dns
.
GetHostEntry
(
Dns
.
GetHostName
());
IPAddress
ipAddress
=
null
;
if
(
IPAddress
.
TryParse
(
hostName
,
out
ipAddress
))
isLocalhost
=
localhost
.
AddressList
.
Any
(
x
=>
x
.
Equals
(
ipAddress
));
if
(!
isLocalhost
)
{
try
{
var
hostEntry
=
Dns
.
GetHostEntry
(
hostName
);
isLocalhost
=
localhost
.
AddressList
.
Any
(
x
=>
hostEntry
.
AddressList
.
Any
(
x
.
Equals
));
}
catch
(
SocketException
)
{
}
}
}
return
isLocalhost
;
}
}
}
}
}
}
Titanium.Web.Proxy/Models/ExternalProxy.cs
View file @
8e254c99
...
@@ -18,6 +18,11 @@ namespace Titanium.Web.Proxy.Models
...
@@ -18,6 +18,11 @@ namespace Titanium.Web.Proxy.Models
/// </summary>
/// </summary>
public
bool
UseDefaultCredentials
{
get
;
set
;
}
public
bool
UseDefaultCredentials
{
get
;
set
;
}
/// <summary>
/// Bypass this proxy for connections to localhost?
/// </summary>
public
bool
BypassForLocalhost
{
get
;
set
;
}
/// <summary>
/// <summary>
/// Username.
/// Username.
/// </summary>
/// </summary>
...
...
Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs
View file @
8e254c99
...
@@ -46,12 +46,17 @@ namespace Titanium.Web.Proxy.Network.Tcp
...
@@ -46,12 +46,17 @@ namespace Titanium.Web.Proxy.Network.Tcp
TcpClient
client
;
TcpClient
client
;
Stream
stream
;
Stream
stream
;
bool
isLocalhost
=
(
externalHttpsProxy
==
null
&&
externalHttpProxy
==
null
)
?
false
:
NetworkHelper
.
IsLocalIpAddress
(
remoteHostName
);
bool
useHttpsProxy
=
externalHttpsProxy
!=
null
&&
externalHttpsProxy
.
HostName
!=
remoteHostName
&&
(
externalHttpsProxy
.
BypassForLocalhost
&&
!
isLocalhost
);
bool
useHttpProxy
=
externalHttpProxy
!=
null
&&
externalHttpProxy
.
HostName
!=
remoteHostName
&&
(
externalHttpProxy
.
BypassForLocalhost
&&
!
isLocalhost
);
if
(
isHttps
)
if
(
isHttps
)
{
{
SslStream
sslStream
=
null
;
SslStream
sslStream
=
null
;
//If this proxy uses another external proxy then create a tunnel request for HTTPS connections
//If this proxy uses another external proxy then create a tunnel request for HTTPS connections
if
(
externalHttpsProxy
!=
null
&&
externalHttpsProxy
.
HostName
!=
remoteHostName
)
if
(
useHttpsProxy
)
{
{
client
=
new
TcpClient
();
client
=
new
TcpClient
();
client
.
Client
.
Bind
(
upStreamEndPoint
);
client
.
Client
.
Bind
(
upStreamEndPoint
);
...
@@ -113,7 +118,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
...
@@ -113,7 +118,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
}
}
else
else
{
{
if
(
externalHttpProxy
!=
null
&&
externalHttpProxy
.
HostName
!=
remoteHostName
)
if
(
useHttpProxy
)
{
{
client
=
new
TcpClient
();
client
=
new
TcpClient
();
client
.
Client
.
Bind
(
upStreamEndPoint
);
client
.
Client
.
Bind
(
upStreamEndPoint
);
...
...
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