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
5333dee9
Commit
5333dee9
authored
May 11, 2017
by
justcoding121
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
order by public, private, protected for methods
parent
648a5d28
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
63 additions
and
59 deletions
+63
-59
ProxyServer.cs
Titanium.Web.Proxy/ProxyServer.cs
+63
-59
No files found.
Titanium.Web.Proxy/ProxyServer.cs
View file @
5333dee9
...
@@ -454,46 +454,6 @@ namespace Titanium.Web.Proxy
...
@@ -454,46 +454,6 @@ namespace Titanium.Web.Proxy
proxyRunning
=
true
;
proxyRunning
=
true
;
}
}
private
void
CreateCertificateCacheManager
(
string
rootCertificateName
,
string
rootCertificateIssuerName
)
{
certificateManager
=
new
CertificateManager
(
CertificateEngine
,
rootCertificateIssuerName
,
rootCertificateName
,
ExceptionFunc
);
}
private
void
EnsureRootCertificate
()
{
if
(!
certValidated
.
HasValue
)
{
certValidated
=
certificateManager
.
CreateTrustedRootCertificate
();
if
(
TrustRootCertificate
)
{
certificateManager
.
TrustRootCertificate
(
ExceptionFunc
);
}
}
}
/// <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>
/// <summary>
/// Stop this proxy server
/// Stop this proxy server
...
@@ -527,6 +487,19 @@ namespace Titanium.Web.Proxy
...
@@ -527,6 +487,19 @@ namespace Titanium.Web.Proxy
proxyRunning
=
false
;
proxyRunning
=
false
;
}
}
/// <summary>
/// Dispose Proxy.
/// </summary>
public
void
Dispose
()
{
if
(
proxyRunning
)
{
Stop
();
}
certificateManager
?.
Dispose
();
}
/// <summary>
/// <summary>
/// Listen on the given end point on local machine
/// Listen on the given end point on local machine
/// </summary>
/// </summary>
...
@@ -541,16 +514,7 @@ namespace Titanium.Web.Proxy
...
@@ -541,16 +514,7 @@ namespace Titanium.Web.Proxy
endPoint
.
Listener
.
BeginAcceptTcpClient
(
OnAcceptConnection
,
endPoint
);
endPoint
.
Listener
.
BeginAcceptTcpClient
(
OnAcceptConnection
,
endPoint
);
}
}
/// <summary>
/// Quit listening on the given end point
/// </summary>
/// <param name="endPoint"></param>
private
void
QuitListen
(
ProxyEndPoint
endPoint
)
{
endPoint
.
Listener
.
Stop
();
endPoint
.
Listener
.
Server
.
Close
();
endPoint
.
Listener
.
Server
.
Dispose
();
}
/// <summary>
/// <summary>
/// Verifiy if its safe to set this end point as System proxy
/// Verifiy if its safe to set this end point as System proxy
...
@@ -570,6 +534,48 @@ namespace Titanium.Web.Proxy
...
@@ -570,6 +534,48 @@ namespace Titanium.Web.Proxy
}
}
}
}
/// <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
);
}
private
void
CreateCertificateCacheManager
(
string
rootCertificateName
,
string
rootCertificateIssuerName
)
{
certificateManager
=
new
CertificateManager
(
CertificateEngine
,
rootCertificateIssuerName
,
rootCertificateName
,
ExceptionFunc
);
}
private
void
EnsureRootCertificate
()
{
if
(!
certValidated
.
HasValue
)
{
certValidated
=
certificateManager
.
CreateTrustedRootCertificate
();
if
(
TrustRootCertificate
)
{
certificateManager
.
TrustRootCertificate
(
ExceptionFunc
);
}
}
}
/// <summary>
/// <summary>
/// When a connection is received from client act
/// When a connection is received from client act
/// </summary>
/// </summary>
...
@@ -641,18 +647,16 @@ namespace Titanium.Web.Proxy
...
@@ -641,18 +647,16 @@ namespace Titanium.Web.Proxy
}
}
/// <summary>
/// <summary>
///
Dispose Proxy.
///
Quit listening on the given end point
/// </summary>
/// </summary>
public
void
Dispose
()
/// <param name="endPoint"></param>
private
void
QuitListen
(
ProxyEndPoint
endPoint
)
{
{
if
(
proxyRunning
)
endPoint
.
Listener
.
Stop
();
{
endPoint
.
Listener
.
Server
.
Close
();
Stop
();
endPoint
.
Listener
.
Server
.
Dispose
();
}
certificateManager
?.
Dispose
();
}
}
/// <summary>
/// <summary>
/// Invocator for BeforeRequest event.
/// Invocator for BeforeRequest event.
/// </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