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
55312330
Commit
55312330
authored
Oct 22, 2016
by
Hakan Arıcı
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
* PAC/WAPD script handling implementation
* Various code refactorings
parent
a9d1011b
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
681 additions
and
659 deletions
+681
-659
SessionEventArgs.cs
Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs
+447
-448
Tcp.cs
Titanium.Web.Proxy/Helpers/Tcp.cs
+192
-195
TcpConnection.cs
Titanium.Web.Proxy/Network/TcpConnection.cs
+1
-1
TcpConnectionFactory.cs
Titanium.Web.Proxy/Network/TcpConnectionFactory.cs
+5
-8
ProxyServer.cs
Titanium.Web.Proxy/ProxyServer.cs
+34
-1
RequestHandler.cs
Titanium.Web.Proxy/RequestHandler.cs
+2
-6
No files found.
Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs
View file @
55312330
This diff is collapsed.
Click to expand it.
Titanium.Web.Proxy/Helpers/Tcp.cs
View file @
55312330
This diff is collapsed.
Click to expand it.
Titanium.Web.Proxy/Network/TcpConnection.cs
View file @
55312330
...
@@ -16,7 +16,7 @@ namespace Titanium.Web.Proxy.Network
...
@@ -16,7 +16,7 @@ namespace Titanium.Web.Proxy.Network
internal
ExternalProxy
UpStreamHttpsProxy
{
get
;
set
;
}
internal
ExternalProxy
UpStreamHttpsProxy
{
get
;
set
;
}
internal
string
HostName
{
get
;
set
;
}
internal
string
HostName
{
get
;
set
;
}
internal
int
p
ort
{
get
;
set
;
}
internal
int
P
ort
{
get
;
set
;
}
internal
bool
IsHttps
{
get
;
set
;
}
internal
bool
IsHttps
{
get
;
set
;
}
...
...
Titanium.Web.Proxy/Network/TcpConnectionFactory.cs
View file @
55312330
...
@@ -49,7 +49,7 @@ namespace Titanium.Web.Proxy.Network
...
@@ -49,7 +49,7 @@ namespace Titanium.Web.Proxy.Network
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
)
if
(
externalHttpsProxy
!=
null
&&
externalHttpsProxy
.
HostName
!=
remoteHostName
)
{
{
client
=
new
TcpClient
(
externalHttpsProxy
.
HostName
,
externalHttpsProxy
.
Port
);
client
=
new
TcpClient
(
externalHttpsProxy
.
HostName
,
externalHttpsProxy
.
Port
);
stream
=
client
.
GetStream
();
stream
=
client
.
GetStream
();
...
@@ -100,17 +100,14 @@ namespace Titanium.Web.Proxy.Network
...
@@ -100,17 +100,14 @@ namespace Titanium.Web.Proxy.Network
}
}
catch
catch
{
{
if
(
sslStream
!=
null
)
sslStream
?.
Dispose
();
{
sslStream
.
Dispose
();
}
throw
;
throw
;
}
}
}
}
else
else
{
{
if
(
externalHttpProxy
!=
null
)
if
(
externalHttpProxy
!=
null
&&
externalHttpProxy
.
HostName
!=
remoteHostName
)
{
{
client
=
new
TcpClient
(
externalHttpProxy
.
HostName
,
externalHttpProxy
.
Port
);
client
=
new
TcpClient
(
externalHttpProxy
.
HostName
,
externalHttpProxy
.
Port
);
stream
=
client
.
GetStream
();
stream
=
client
.
GetStream
();
...
@@ -133,7 +130,7 @@ namespace Titanium.Web.Proxy.Network
...
@@ -133,7 +130,7 @@ namespace Titanium.Web.Proxy.Network
UpStreamHttpProxy
=
externalHttpProxy
,
UpStreamHttpProxy
=
externalHttpProxy
,
UpStreamHttpsProxy
=
externalHttpsProxy
,
UpStreamHttpsProxy
=
externalHttpsProxy
,
HostName
=
remoteHostName
,
HostName
=
remoteHostName
,
p
ort
=
remotePort
,
P
ort
=
remotePort
,
IsHttps
=
isHttps
,
IsHttps
=
isHttps
,
TcpClient
=
client
,
TcpClient
=
client
,
StreamReader
=
new
CustomBinaryReader
(
stream
),
StreamReader
=
new
CustomBinaryReader
(
stream
),
...
...
Titanium.Web.Proxy/ProxyServer.cs
View file @
55312330
...
@@ -186,6 +186,11 @@ namespace Titanium.Web.Proxy
...
@@ -186,6 +186,11 @@ namespace Titanium.Web.Proxy
/// </summary>
/// </summary>
public
bool
ProxyRunning
=>
proxyRunning
;
public
bool
ProxyRunning
=>
proxyRunning
;
/// <summary>
/// Gets or sets a value indicating whether requests will be chained to upstream gateway.
/// </summary>
public
bool
ForwardToUpstreamGateway
{
get
;
set
;
}
/// <summary>
/// <summary>
/// Constructor
/// Constructor
/// </summary>
/// </summary>
...
@@ -348,6 +353,12 @@ namespace Titanium.Web.Proxy
...
@@ -348,6 +353,12 @@ namespace Titanium.Web.Proxy
certificateCacheManager
.
TrustRootCertificate
();
certificateCacheManager
.
TrustRootCertificate
();
}
}
if
(
ForwardToUpstreamGateway
&&
GetCustomUpStreamHttpProxyFunc
==
null
&&
GetCustomUpStreamHttpsProxyFunc
==
null
)
{
GetCustomUpStreamHttpProxyFunc
=
GetSystemUpStreamProxy
;
GetCustomUpStreamHttpsProxyFunc
=
GetSystemUpStreamProxy
;
}
foreach
(
var
endPoint
in
ProxyEndPoints
)
foreach
(
var
endPoint
in
ProxyEndPoints
)
{
{
Listen
(
endPoint
);
Listen
(
endPoint
);
...
@@ -358,7 +369,29 @@ namespace Titanium.Web.Proxy
...
@@ -358,7 +369,29 @@ namespace Titanium.Web.Proxy
proxyRunning
=
true
;
proxyRunning
=
true
;
}
}
/// <summary>
/// <summary>
/// Gets the system up stream proxy.
/// </summary>
/// <param name="sessionEventArgs">The <see cref="SessionEventArgs"/> instance containing the event data.</param>
/// <returns><see cref="ExternalProxy"/> instance containing valid proxy configuration from PAC/WAPD scripts if any exists.</returns>
private
Task
<
ExternalProxy
>
GetSystemUpStreamProxy
(
SessionEventArgs
sessionEventArgs
)
{
// Use built-in WebProxy class to handle PAC/WAPD scripts.
var
systemProxyResolver
=
new
WebProxy
();
var
systemProxyUri
=
systemProxyResolver
.
GetProxy
(
sessionEventArgs
.
WebSession
.
Request
.
RequestUri
);
// TODO: Apply authorization
var
systemProxy
=
new
ExternalProxy
{
HostName
=
systemProxyUri
.
Host
,
Port
=
systemProxyUri
.
Port
};
return
Task
.
FromResult
(
systemProxy
);
}
/// <summary>
/// Stop this proxy server
/// Stop this proxy server
/// </summary>
/// </summary>
public
void
Stop
()
public
void
Stop
()
...
...
Titanium.Web.Proxy/RequestHandler.cs
View file @
55312330
...
@@ -165,7 +165,6 @@ namespace Titanium.Web.Proxy
...
@@ -165,7 +165,6 @@ namespace Titanium.Web.Proxy
//write back successfull CONNECT response
//write back successfull CONNECT response
await
WriteConnectResponse
(
clientStreamWriter
,
version
);
await
WriteConnectResponse
(
clientStreamWriter
,
version
);
await
TcpHelper
.
SendRaw
(
BUFFER_SIZE
,
ConnectionTimeOutSeconds
,
httpRemoteUri
.
Host
,
httpRemoteUri
.
Port
,
await
TcpHelper
.
SendRaw
(
BUFFER_SIZE
,
ConnectionTimeOutSeconds
,
httpRemoteUri
.
Host
,
httpRemoteUri
.
Port
,
httpCmd
,
version
,
null
,
httpCmd
,
version
,
null
,
false
,
SupportedSslProtocols
,
false
,
SupportedSslProtocols
,
...
@@ -274,10 +273,8 @@ namespace Titanium.Web.Proxy
...
@@ -274,10 +273,8 @@ namespace Titanium.Web.Proxy
customUpStreamHttpProxy
??
UpStreamHttpProxy
,
customUpStreamHttpsProxy
??
UpStreamHttpsProxy
,
args
.
ProxyClient
.
ClientStream
);
customUpStreamHttpProxy
??
UpStreamHttpProxy
,
customUpStreamHttpsProxy
??
UpStreamHttpsProxy
,
args
.
ProxyClient
.
ClientStream
);
}
}
args
.
WebSession
.
Request
.
RequestLocked
=
true
;
args
.
WebSession
.
Request
.
RequestLocked
=
true
;
//If request was cancelled by user then dispose the client
//If request was cancelled by user then dispose the client
if
(
args
.
WebSession
.
Request
.
CancelRequest
)
if
(
args
.
WebSession
.
Request
.
CancelRequest
)
{
{
...
@@ -362,10 +359,10 @@ namespace Titanium.Web.Proxy
...
@@ -362,10 +359,10 @@ namespace Titanium.Web.Proxy
return
;
return
;
}
}
if
(
CloseConnection
&&
connection
!=
null
)
if
(
CloseConnection
)
{
{
//dispose
//dispose
connection
.
Dispose
();
connection
?
.
Dispose
();
}
}
}
}
...
@@ -472,7 +469,6 @@ namespace Titanium.Web.Proxy
...
@@ -472,7 +469,6 @@ namespace Titanium.Web.Proxy
break
;
break
;
}
}
PrepareRequestHeaders
(
args
.
WebSession
.
Request
.
RequestHeaders
,
args
.
WebSession
);
PrepareRequestHeaders
(
args
.
WebSession
.
Request
.
RequestHeaders
,
args
.
WebSession
);
args
.
WebSession
.
Request
.
Host
=
args
.
WebSession
.
Request
.
RequestUri
.
Authority
;
args
.
WebSession
.
Request
.
Host
=
args
.
WebSession
.
Request
.
RequestUri
.
Authority
;
...
...
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