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
71d16e3d
Commit
71d16e3d
authored
Dec 03, 2016
by
Jehonathan
Committed by
GitHub
Dec 03, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #155 from svstoichkov/release
Bind proxy requests to specific network adapter
parents
9f9a16af
3095d1ed
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
27 additions
and
9 deletions
+27
-9
Tcp.cs
Titanium.Web.Proxy/Helpers/Tcp.cs
+3
-1
TcpConnectionFactory.cs
Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs
+18
-7
ProxyServer.cs
Titanium.Web.Proxy/ProxyServer.cs
+5
-0
RequestHandler.cs
Titanium.Web.Proxy/RequestHandler.cs
+1
-1
No files found.
Titanium.Web.Proxy/Helpers/Tcp.cs
View file @
71d16e3d
...
...
@@ -15,6 +15,8 @@ using Titanium.Web.Proxy.Shared;
namespace
Titanium.Web.Proxy.Helpers
{
using
System.Net
;
internal
enum
IpVersion
{
Ipv4
=
1
,
...
...
@@ -173,7 +175,7 @@ namespace Titanium.Web.Proxy.Helpers
remoteHostName
,
remotePort
,
httpVersion
,
isHttps
,
supportedProtocols
,
remoteCertificateValidationCallback
,
localCertificateSelectionCallback
,
null
,
null
,
clientStream
);
null
,
null
,
clientStream
,
new
IPEndPoint
(
IPAddress
.
Any
,
0
)
);
try
{
...
...
Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs
View file @
71d16e3d
...
...
@@ -12,6 +12,8 @@ using Titanium.Web.Proxy.Shared;
namespace
Titanium.Web.Proxy.Network.Tcp
{
using
System.Net
;
/// <summary>
/// A class that manages Tcp Connection to server used by this proxy server
/// </summary>
...
...
@@ -40,7 +42,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
bool
isHttps
,
SslProtocols
supportedSslProtocols
,
RemoteCertificateValidationCallback
remoteCertificateValidationCallback
,
LocalCertificateSelectionCallback
localCertificateSelectionCallback
,
ExternalProxy
externalHttpProxy
,
ExternalProxy
externalHttpsProxy
,
Stream
clientStream
)
Stream
clientStream
,
EndPoint
localEndPoint
)
{
TcpClient
client
;
Stream
stream
;
...
...
@@ -52,7 +54,9 @@ namespace Titanium.Web.Proxy.Network.Tcp
//If this proxy uses another external proxy then create a tunnel request for HTTPS connections
if
(
externalHttpsProxy
!=
null
&&
externalHttpsProxy
.
HostName
!=
remoteHostName
)
{
client
=
new
TcpClient
(
externalHttpsProxy
.
HostName
,
externalHttpsProxy
.
Port
);
client
=
new
TcpClient
();
client
.
Client
.
Bind
(
localEndPoint
);
client
.
Client
.
Connect
(
externalHttpsProxy
.
HostName
,
externalHttpsProxy
.
Port
);
stream
=
client
.
GetStream
();
using
(
var
writer
=
new
StreamWriter
(
stream
,
Encoding
.
ASCII
,
bufferSize
,
true
)
{
NewLine
=
ProxyConstants
.
NewLine
})
...
...
@@ -76,7 +80,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
var
result
=
await
reader
.
ReadLineAsync
();
if
(!
new
string
[]
{
"200 OK"
,
"connection established"
}.
Any
(
s
=>
result
.
ToLower
().
Contains
(
s
.
ToLower
())))
if
(!
new
string
[]
{
"200 OK"
,
"connection established"
}.
Any
(
s
=>
result
.
ToLower
().
Contains
(
s
.
ToLower
())))
{
throw
new
Exception
(
"Upstream proxy failed to create a secure tunnel"
);
}
...
...
@@ -86,7 +90,9 @@ namespace Titanium.Web.Proxy.Network.Tcp
}
else
{
client
=
new
TcpClient
(
remoteHostName
,
remotePort
);
client
=
new
TcpClient
();
client
.
Client
.
Bind
(
localEndPoint
);
client
.
Client
.
Connect
(
remoteHostName
,
remotePort
);
stream
=
client
.
GetStream
();
}
...
...
@@ -110,12 +116,16 @@ namespace Titanium.Web.Proxy.Network.Tcp
{
if
(
externalHttpProxy
!=
null
&&
externalHttpProxy
.
HostName
!=
remoteHostName
)
{
client
=
new
TcpClient
(
externalHttpProxy
.
HostName
,
externalHttpProxy
.
Port
);
client
=
new
TcpClient
();
client
.
Client
.
Bind
(
localEndPoint
);
client
.
Client
.
Connect
(
externalHttpProxy
.
HostName
,
externalHttpProxy
.
Port
);
stream
=
client
.
GetStream
();
}
else
{
client
=
new
TcpClient
(
remoteHostName
,
remotePort
);
client
=
new
TcpClient
();
client
.
Client
.
Bind
(
localEndPoint
);
client
.
Client
.
Connect
(
remoteHostName
,
remotePort
);
stream
=
client
.
GetStream
();
}
}
...
...
@@ -126,6 +136,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
stream
.
ReadTimeout
=
connectionTimeOutSeconds
*
1000
;
stream
.
WriteTimeout
=
connectionTimeOutSeconds
*
1000
;
return
new
TcpConnection
()
{
UpStreamHttpProxy
=
externalHttpProxy
,
...
...
@@ -140,4 +151,4 @@ namespace Titanium.Web.Proxy.Network.Tcp
};
}
}
}
}
\ No newline at end of file
Titanium.Web.Proxy/ProxyServer.cs
View file @
71d16e3d
...
...
@@ -117,6 +117,11 @@ namespace Titanium.Web.Proxy
/// </summary>
public
ExternalProxy
UpStreamHttpsProxy
{
get
;
set
;
}
/// <summary>
/// Local adapter endpoint
/// </summary>
public
EndPoint
LocalEndPoint
{
get
;
set
;
}
=
new
IPEndPoint
(
IPAddress
.
Any
,
0
);
/// <summary>
/// Verifies the remote Secure Sockets Layer (SSL) certificate used for authentication
/// </summary>
...
...
Titanium.Web.Proxy/RequestHandler.cs
View file @
71d16e3d
...
...
@@ -251,7 +251,7 @@ namespace Titanium.Web.Proxy
args
.
IsHttps
,
SupportedSslProtocols
,
new
RemoteCertificateValidationCallback
(
ValidateServerCertificate
),
new
LocalCertificateSelectionCallback
(
SelectClientCertificate
),
customUpStreamHttpProxy
??
UpStreamHttpProxy
,
customUpStreamHttpsProxy
??
UpStreamHttpsProxy
,
args
.
ProxyClient
.
ClientStream
);
customUpStreamHttpProxy
??
UpStreamHttpProxy
,
customUpStreamHttpsProxy
??
UpStreamHttpsProxy
,
args
.
ProxyClient
.
ClientStream
,
LocalEndPoint
);
}
args
.
WebSession
.
Request
.
RequestLocked
=
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