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
0ecf3855
Commit
0ecf3855
authored
May 01, 2018
by
justcoding121
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cleanup comments
parent
fd0baeff
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
22 deletions
+37
-22
ProxyServer.cs
Titanium.Web.Proxy/ProxyServer.cs
+37
-22
No files found.
Titanium.Web.Proxy/ProxyServer.cs
View file @
0ecf3855
...
@@ -19,8 +19,9 @@ using Titanium.Web.Proxy.Network.WinAuth.Security;
...
@@ -19,8 +19,9 @@ using Titanium.Web.Proxy.Network.WinAuth.Security;
namespace
Titanium.Web.Proxy
namespace
Titanium.Web.Proxy
{
{
/// <inheritdoc />
/// <summary>
/// <summary>
/// This
object
is the backbone of proxy. One can create as many instances as needed.
/// This
class
is the backbone of proxy. One can create as many instances as needed.
/// However care should be taken to avoid using the same listening ports across multiple instances.
/// However care should be taken to avoid using the same listening ports across multiple instances.
/// </summary>
/// </summary>
public
partial
class
ProxyServer
:
IDisposable
public
partial
class
ProxyServer
:
IDisposable
...
@@ -29,7 +30,6 @@ namespace Titanium.Web.Proxy
...
@@ -29,7 +30,6 @@ namespace Titanium.Web.Proxy
/// HTTP & HTTPS scheme shorthands.
/// HTTP & HTTPS scheme shorthands.
/// </summary>
/// </summary>
internal
static
readonly
string
UriSchemeHttp
=
Uri
.
UriSchemeHttp
;
internal
static
readonly
string
UriSchemeHttp
=
Uri
.
UriSchemeHttp
;
internal
static
readonly
string
UriSchemeHttps
=
Uri
.
UriSchemeHttps
;
internal
static
readonly
string
UriSchemeHttps
=
Uri
.
UriSchemeHttps
;
/// <summary>
/// <summary>
...
@@ -57,6 +57,7 @@ namespace Titanium.Web.Proxy
...
@@ -57,6 +57,7 @@ namespace Titanium.Web.Proxy
/// </summary>
/// </summary>
private
WinHttpWebProxyFinder
systemProxyResolver
;
private
WinHttpWebProxyFinder
systemProxyResolver
;
/// <inheritdoc />
/// <summary>
/// <summary>
/// Initializes a new instance of ProxyServer class with provided parameters.
/// Initializes a new instance of ProxyServer class with provided parameters.
/// </summary>
/// </summary>
...
@@ -108,7 +109,7 @@ namespace Titanium.Web.Proxy
...
@@ -108,7 +109,7 @@ namespace Titanium.Web.Proxy
}
}
/// <summary>
/// <summary>
/// An
object
that creates tcp connection to server.
/// An
factory
that creates tcp connection to server.
/// </summary>
/// </summary>
private
TcpConnectionFactory
tcpConnectionFactory
{
get
;
}
private
TcpConnectionFactory
tcpConnectionFactory
{
get
;
}
...
@@ -128,7 +129,7 @@ namespace Titanium.Web.Proxy
...
@@ -128,7 +129,7 @@ namespace Titanium.Web.Proxy
public
bool
ForwardToUpstreamGateway
{
get
;
set
;
}
public
bool
ForwardToUpstreamGateway
{
get
;
set
;
}
/// <summary>
/// <summary>
/// Enable disable Windows Authentication (NTLM/Kerberos)
/// Enable disable Windows Authentication (NTLM/Kerberos)
.
/// Note: NTLM/Kerberos will always send local credentials of current user
/// Note: NTLM/Kerberos will always send local credentials of current user
/// running the proxy process. This is because a man
/// running the proxy process. This is because a man
/// in middle attack with Windows domain authentication is not currently supported.
/// in middle attack with Windows domain authentication is not currently supported.
...
@@ -144,6 +145,7 @@ namespace Titanium.Web.Proxy
...
@@ -144,6 +145,7 @@ namespace Titanium.Web.Proxy
/// <summary>
/// <summary>
/// Does this proxy uses the HTTP protocol 100 continue behaviour strictly?
/// Does this proxy uses the HTTP protocol 100 continue behaviour strictly?
/// Broken 100 contunue implementations on server/client may cause problems if enabled.
/// Broken 100 contunue implementations on server/client may cause problems if enabled.
/// Defaults to false.
/// </summary>
/// </summary>
public
bool
Enable100ContinueBehaviour
{
get
;
set
;
}
public
bool
Enable100ContinueBehaviour
{
get
;
set
;
}
...
@@ -225,12 +227,12 @@ namespace Titanium.Web.Proxy
...
@@ -225,12 +227,12 @@ namespace Titanium.Web.Proxy
/// <summary>
/// <summary>
/// A callback to authenticate clients.
/// A callback to authenticate clients.
/// Parameters are username and password as provided by client.
/// Parameters are username and password as provided by client.
///
R
eturn true for successful authentication.
///
Should r
eturn true for successful authentication.
/// </summary>
/// </summary>
public
Func
<
string
,
string
,
Task
<
bool
>>
AuthenticateUserFunc
{
get
;
set
;
}
public
Func
<
string
,
string
,
Task
<
bool
>>
AuthenticateUserFunc
{
get
;
set
;
}
/// <summary>
/// <summary>
/// Dispose
Proxy
.
/// Dispose
the Proxy instance
.
/// </summary>
/// </summary>
public
void
Dispose
()
public
void
Dispose
()
{
{
...
@@ -243,37 +245,37 @@ namespace Titanium.Web.Proxy
...
@@ -243,37 +245,37 @@ namespace Titanium.Web.Proxy
}
}
/// <summary>
/// <summary>
///
O
ccurs when client connection count changed.
///
Event o
ccurs when client connection count changed.
/// </summary>
/// </summary>
public
event
EventHandler
ClientConnectionCountChanged
;
public
event
EventHandler
ClientConnectionCountChanged
;
/// <summary>
/// <summary>
///
O
ccurs when server connection count changed.
///
Event o
ccurs when server connection count changed.
/// </summary>
/// </summary>
public
event
EventHandler
ServerConnectionCountChanged
;
public
event
EventHandler
ServerConnectionCountChanged
;
/// <summary>
/// <summary>
///
Verifies the remote SSL certificate used for
authentication.
///
Event to override the default verification logic of remote SSL certificate received during
authentication.
/// </summary>
/// </summary>
public
event
AsyncEventHandler
<
CertificateValidationEventArgs
>
ServerCertificateValidationCallback
;
public
event
AsyncEventHandler
<
CertificateValidationEventArgs
>
ServerCertificateValidationCallback
;
/// <summary>
/// <summary>
///
Callback
to override client certificate selection during mutual SSL authentication.
///
Event
to override client certificate selection during mutual SSL authentication.
/// </summary>
/// </summary>
public
event
AsyncEventHandler
<
CertificateSelectionEventArgs
>
ClientCertificateSelectionCallback
;
public
event
AsyncEventHandler
<
CertificateSelectionEventArgs
>
ClientCertificateSelectionCallback
;
/// <summary>
/// <summary>
/// Intercept request to server.
/// Intercept request
event
to server.
/// </summary>
/// </summary>
public
event
AsyncEventHandler
<
SessionEventArgs
>
BeforeRequest
;
public
event
AsyncEventHandler
<
SessionEventArgs
>
BeforeRequest
;
/// <summary>
/// <summary>
/// Intercept response from server.
/// Intercept response
event
from server.
/// </summary>
/// </summary>
public
event
AsyncEventHandler
<
SessionEventArgs
>
BeforeResponse
;
public
event
AsyncEventHandler
<
SessionEventArgs
>
BeforeResponse
;
/// <summary>
/// <summary>
/// Intercept after response from server.
/// Intercept after response
event
from server.
/// </summary>
/// </summary>
public
event
AsyncEventHandler
<
SessionEventArgs
>
AfterResponse
;
public
event
AsyncEventHandler
<
SessionEventArgs
>
AfterResponse
;
...
@@ -299,7 +301,7 @@ namespace Titanium.Web.Proxy
...
@@ -299,7 +301,7 @@ namespace Titanium.Web.Proxy
/// <summary>
/// <summary>
/// Remove a proxy end point.
/// Remove a proxy end point.
/// Will throw error if the end point does'nt exist
/// Will throw error if the end point does'nt exist
.
/// </summary>
/// </summary>
/// <param name="endPoint">The existing endpoint to remove.</param>
/// <param name="endPoint">The existing endpoint to remove.</param>
public
void
RemoveEndPoint
(
ProxyEndPoint
endPoint
)
public
void
RemoveEndPoint
(
ProxyEndPoint
endPoint
)
...
@@ -320,7 +322,7 @@ namespace Titanium.Web.Proxy
...
@@ -320,7 +322,7 @@ namespace Titanium.Web.Proxy
/// <summary>
/// <summary>
/// Set the given explicit end point as the default proxy server for current machine.
/// Set the given explicit end point as the default proxy server for current machine.
/// </summary>
/// </summary>
/// <param name="endPoint"></param>
/// <param name="endPoint">
The explicit endpoint.
</param>
public
void
SetAsSystemHttpProxy
(
ExplicitProxyEndPoint
endPoint
)
public
void
SetAsSystemHttpProxy
(
ExplicitProxyEndPoint
endPoint
)
{
{
SetAsSystemProxy
(
endPoint
,
ProxyProtocolType
.
Http
);
SetAsSystemProxy
(
endPoint
,
ProxyProtocolType
.
Http
);
...
@@ -329,7 +331,7 @@ namespace Titanium.Web.Proxy
...
@@ -329,7 +331,7 @@ namespace Titanium.Web.Proxy
/// <summary>
/// <summary>
/// Set the given explicit end point as the default proxy server for current machine.
/// Set the given explicit end point as the default proxy server for current machine.
/// </summary>
/// </summary>
/// <param name="endPoint"></param>
/// <param name="endPoint">
The explicit endpoint.
</param>
public
void
SetAsSystemHttpsProxy
(
ExplicitProxyEndPoint
endPoint
)
public
void
SetAsSystemHttpsProxy
(
ExplicitProxyEndPoint
endPoint
)
{
{
SetAsSystemProxy
(
endPoint
,
ProxyProtocolType
.
Https
);
SetAsSystemProxy
(
endPoint
,
ProxyProtocolType
.
Https
);
...
@@ -338,8 +340,8 @@ namespace Titanium.Web.Proxy
...
@@ -338,8 +340,8 @@ namespace Titanium.Web.Proxy
/// <summary>
/// <summary>
/// Set the given explicit end point as the default proxy server for current machine.
/// Set the given explicit end point as the default proxy server for current machine.
/// </summary>
/// </summary>
/// <param name="endPoint"></param>
/// <param name="endPoint">
The explicit endpoint.
</param>
/// <param name="protocolType"></param>
/// <param name="protocolType">
The proxy protocol type.
</param>
public
void
SetAsSystemProxy
(
ExplicitProxyEndPoint
endPoint
,
ProxyProtocolType
protocolType
)
public
void
SetAsSystemProxy
(
ExplicitProxyEndPoint
endPoint
,
ProxyProtocolType
protocolType
)
{
{
if
(
RunTime
.
IsRunningOnMono
)
if
(
RunTime
.
IsRunningOnMono
)
...
@@ -472,7 +474,7 @@ namespace Titanium.Web.Proxy
...
@@ -472,7 +474,7 @@ namespace Titanium.Web.Proxy
}
}
// clear any system proxy settings which is pointing to our own endpoint (causing a cycle)
// clear any system proxy settings which is pointing to our own endpoint (causing a cycle)
// due to
non
gracious proxy shutdown before or something else
// due to
un
gracious proxy shutdown before or something else
if
(
systemProxySettingsManager
!=
null
&&
RunTime
.
IsWindows
)
if
(
systemProxySettingsManager
!=
null
&&
RunTime
.
IsWindows
)
{
{
var
proxyInfo
=
systemProxySettingsManager
.
GetProxyInfoFromRegistry
();
var
proxyInfo
=
systemProxySettingsManager
.
GetProxyInfoFromRegistry
();
...
@@ -602,8 +604,10 @@ namespace Titanium.Web.Proxy
...
@@ -602,8 +604,10 @@ namespace Titanium.Web.Proxy
}
}
/// <summary>
/// <summary>
///
Gets the system up stream proxy.
/// Gets the system up stream proxy.
/// </summary>
/// </summary>
/// <param name="sessionEventArgs">The session.</param>
/// <returns>The external proxy as task result.</returns>
private
Task
<
ExternalProxy
>
GetSystemUpStreamProxy
(
SessionEventArgsBase
sessionEventArgs
)
private
Task
<
ExternalProxy
>
GetSystemUpStreamProxy
(
SessionEventArgsBase
sessionEventArgs
)
{
{
var
proxy
=
systemProxyResolver
.
GetProxy
(
sessionEventArgs
.
WebSession
.
Request
.
RequestUri
);
var
proxy
=
systemProxyResolver
.
GetProxy
(
sessionEventArgs
.
WebSession
.
Request
.
RequestUri
);
...
@@ -645,6 +649,12 @@ namespace Titanium.Web.Proxy
...
@@ -645,6 +649,12 @@ namespace Titanium.Web.Proxy
endPoint
.
Listener
.
BeginAcceptTcpClient
(
OnAcceptConnection
,
endPoint
);
endPoint
.
Listener
.
BeginAcceptTcpClient
(
OnAcceptConnection
,
endPoint
);
}
}
/// <summary>
/// Handle the client.
/// </summary>
/// <param name="tcpClient">The client.</param>
/// <param name="endPoint">The proxy endpoint.</param>
/// <returns>The task.</returns>
private
async
Task
HandleClient
(
TcpClient
tcpClient
,
ProxyEndPoint
endPoint
)
private
async
Task
HandleClient
(
TcpClient
tcpClient
,
ProxyEndPoint
endPoint
)
{
{
tcpClient
.
ReceiveTimeout
=
ConnectionTimeOutSeconds
*
1000
;
tcpClient
.
ReceiveTimeout
=
ConnectionTimeOutSeconds
*
1000
;
...
@@ -663,6 +673,11 @@ namespace Titanium.Web.Proxy
...
@@ -663,6 +673,11 @@ namespace Titanium.Web.Proxy
}
}
}
}
/// <summary>
/// Handle exception.
/// </summary>
/// <param name="clientStream">The client stream.</param>
/// <param name="exception">The exception.</param>
private
void
OnException
(
CustomBufferedStream
clientStream
,
Exception
exception
)
private
void
OnException
(
CustomBufferedStream
clientStream
,
Exception
exception
)
{
{
#if DEBUG
#if DEBUG
...
@@ -687,7 +702,7 @@ namespace Titanium.Web.Proxy
...
@@ -687,7 +702,7 @@ namespace Titanium.Web.Proxy
/// <summary>
/// <summary>
/// Update client connection count.
/// Update client connection count.
/// </summary>
/// </summary>
/// <param name="increment"></param>
/// <param name="increment">
Should we increment/decrement?
</param>
internal
void
UpdateClientConnectionCount
(
bool
increment
)
internal
void
UpdateClientConnectionCount
(
bool
increment
)
{
{
if
(
increment
)
if
(
increment
)
...
@@ -705,7 +720,7 @@ namespace Titanium.Web.Proxy
...
@@ -705,7 +720,7 @@ namespace Titanium.Web.Proxy
/// <summary>
/// <summary>
/// Update server connection count.
/// Update server connection count.
/// </summary>
/// </summary>
/// <param name="increment"></param>
/// <param name="increment">
Should we increment/decrement?
</param>
internal
void
UpdateServerConnectionCount
(
bool
increment
)
internal
void
UpdateServerConnectionCount
(
bool
increment
)
{
{
if
(
increment
)
if
(
increment
)
...
...
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