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
1651c926
Commit
1651c926
authored
Mar 08, 2018
by
justcoding121
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'develop' into beta
parents
4477f6de
f9c7ba4e
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
266 additions
and
286 deletions
+266
-286
ProxyTestController.cs
.../Titanium.Web.Proxy.Examples.Basic/ProxyTestController.cs
+37
-28
MainWindow.xaml.cs
Examples/Titanium.Web.Proxy.Examples.Wpf/MainWindow.xaml.cs
+2
-2
Firefox.cs
Titanium.Web.Proxy/Helpers/Firefox.cs
+0
-52
HttpHelper.cs
Titanium.Web.Proxy/Helpers/HttpHelper.cs
+43
-1
EndPoint.cs
Titanium.Web.Proxy/Models/EndPoint.cs
+49
-2
ProxyServer.cs
Titanium.Web.Proxy/ProxyServer.cs
+121
-135
RequestHandler.cs
Titanium.Web.Proxy/RequestHandler.cs
+13
-63
WinAuthHandler.cs
Titanium.Web.Proxy/WinAuthHandler.cs
+1
-3
No files found.
Examples/Titanium.Web.Proxy.Examples.Basic/ProxyTestController.cs
View file @
1651c926
...
@@ -14,7 +14,7 @@ namespace Titanium.Web.Proxy.Examples.Basic
...
@@ -14,7 +14,7 @@ namespace Titanium.Web.Proxy.Examples.Basic
public
class
ProxyTestController
public
class
ProxyTestController
{
{
private
readonly
ProxyServer
proxyServer
;
private
readonly
ProxyServer
proxyServer
;
private
ExplicitProxyEndPoint
explicitEndPoint
;
//keep track of request headers
//keep track of request headers
private
readonly
IDictionary
<
Guid
,
HeaderCollection
>
requestHeaderHistory
=
new
ConcurrentDictionary
<
Guid
,
HeaderCollection
>();
private
readonly
IDictionary
<
Guid
,
HeaderCollection
>
requestHeaderHistory
=
new
ConcurrentDictionary
<
Guid
,
HeaderCollection
>();
...
@@ -52,30 +52,14 @@ namespace Titanium.Web.Proxy.Examples.Basic
...
@@ -52,30 +52,14 @@ namespace Titanium.Web.Proxy.Examples.Basic
{
{
proxyServer
.
BeforeRequest
+=
OnRequest
;
proxyServer
.
BeforeRequest
+=
OnRequest
;
proxyServer
.
BeforeResponse
+=
OnResponse
;
proxyServer
.
BeforeResponse
+=
OnResponse
;
proxyServer
.
TunnelConnectRequest
+=
OnTunnelConnectRequest
;
proxyServer
.
TunnelConnectResponse
+=
OnTunnelConnectResponse
;
proxyServer
.
ServerCertificateValidationCallback
+=
OnCertificateValidation
;
proxyServer
.
ServerCertificateValidationCallback
+=
OnCertificateValidation
;
proxyServer
.
ClientCertificateSelectionCallback
+=
OnCertificateSelection
;
proxyServer
.
ClientCertificateSelectionCallback
+=
OnCertificateSelection
;
//proxyServer.EnableWinAuth = true;
//proxyServer.EnableWinAuth = true;
var
explicitEndPoint
=
new
ExplicitProxyEndPoint
(
IPAddress
.
Any
,
8000
,
true
)
explicitEndPoint
=
new
ExplicitProxyEndPoint
(
IPAddress
.
Any
,
8000
,
true
)
{
//Exclude Https addresses you don't want to proxy
//Useful for clients that use certificate pinning
//for example google.com and dropbox.com
ExcludedHttpsHostNameRegex
=
new
List
<
string
>
{
{
"dropbox.com"
},
//Include Https addresses you want to proxy (others will be excluded)
//for example github.com
//IncludedHttpsHostNameRegex = new List<string>
//{
// "github.com"
//},
//You can set only one of the ExcludedHttpsHostNameRegex and IncludedHttpsHostNameRegex properties, otherwise ArgumentException will be thrown
//You can set only one of the ExcludedHttpsHostNameRegex and IncludedHttpsHostNameRegex properties, otherwise ArgumentException will be thrown
//Use self-issued generic certificate on all https requests
//Use self-issued generic certificate on all https requests
...
@@ -84,6 +68,15 @@ namespace Titanium.Web.Proxy.Examples.Basic
...
@@ -84,6 +68,15 @@ namespace Titanium.Web.Proxy.Examples.Basic
//GenericCertificate = new X509Certificate2(Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "genericcert.pfx"), "password")
//GenericCertificate = new X509Certificate2(Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "genericcert.pfx"), "password")
};
};
//Exclude Https addresses you don't want to proxy
//Useful for clients that use certificate pinning
//for example google.com and dropbox.com
explicitEndPoint
.
BeforeTunnelConnect
+=
OnBeforeTunnelConnect
;
explicitEndPoint
.
TunnelConnectRequest
+=
OnTunnelConnectRequest
;
explicitEndPoint
.
TunnelConnectResponse
+=
OnTunnelConnectResponse
;
//An explicit endpoint is where the client knows about the existence of a proxy
//An explicit endpoint is where the client knows about the existence of a proxy
//So client sends request in a proxy friendly manner
//So client sends request in a proxy friendly manner
proxyServer
.
AddEndPoint
(
explicitEndPoint
);
proxyServer
.
AddEndPoint
(
explicitEndPoint
);
...
@@ -120,8 +113,10 @@ namespace Titanium.Web.Proxy.Examples.Basic
...
@@ -120,8 +113,10 @@ namespace Titanium.Web.Proxy.Examples.Basic
public
void
Stop
()
public
void
Stop
()
{
{
proxyServer
.
TunnelConnectRequest
-=
OnTunnelConnectRequest
;
explicitEndPoint
.
BeforeTunnelConnect
-=
OnBeforeTunnelConnect
;
proxyServer
.
TunnelConnectResponse
-=
OnTunnelConnectResponse
;
explicitEndPoint
.
TunnelConnectRequest
-=
OnTunnelConnectRequest
;
explicitEndPoint
.
TunnelConnectResponse
-=
OnTunnelConnectResponse
;
proxyServer
.
BeforeRequest
-=
OnRequest
;
proxyServer
.
BeforeRequest
-=
OnRequest
;
proxyServer
.
BeforeResponse
-=
OnResponse
;
proxyServer
.
BeforeResponse
-=
OnResponse
;
proxyServer
.
ServerCertificateValidationCallback
-=
OnCertificateValidation
;
proxyServer
.
ServerCertificateValidationCallback
-=
OnCertificateValidation
;
...
@@ -133,6 +128,20 @@ namespace Titanium.Web.Proxy.Examples.Basic
...
@@ -133,6 +128,20 @@ namespace Titanium.Web.Proxy.Examples.Basic
//proxyServer.CertificateManager.RemoveTrustedRootCertificates();
//proxyServer.CertificateManager.RemoveTrustedRootCertificates();
}
}
private
async
Task
<
bool
>
OnBeforeTunnelConnect
(
string
hostname
)
{
if
(
hostname
.
Contains
(
"amazon.com"
)
||
hostname
.
Contains
(
"paypal.com"
))
{
//exclude bing.com and google.com from being decrypted
//instead it will be relayed via a secure TCP tunnel
return
await
Task
.
FromResult
(
true
);
}
else
{
return
await
Task
.
FromResult
(
false
);
}
}
private
async
Task
OnTunnelConnectRequest
(
object
sender
,
TunnelConnectSessionEventArgs
e
)
private
async
Task
OnTunnelConnectRequest
(
object
sender
,
TunnelConnectSessionEventArgs
e
)
{
{
Console
.
WriteLine
(
"Tunnel to: "
+
e
.
WebSession
.
Request
.
Host
);
Console
.
WriteLine
(
"Tunnel to: "
+
e
.
WebSession
.
Request
.
Host
);
...
@@ -172,7 +181,7 @@ namespace Titanium.Web.Proxy.Examples.Basic
...
@@ -172,7 +181,7 @@ namespace Titanium.Web.Proxy.Examples.Basic
//To cancel a request with a custom HTML content
//To cancel a request with a custom HTML content
//Filter URL
//Filter URL
if
(
e
.
WebSession
.
Request
.
RequestUri
.
AbsoluteUri
.
Contains
(
"
google
.com"
))
if
(
e
.
WebSession
.
Request
.
RequestUri
.
AbsoluteUri
.
Contains
(
"
yahoo
.com"
))
{
{
await
e
.
Ok
(
"<!DOCTYPE html>"
+
await
e
.
Ok
(
"<!DOCTYPE html>"
+
"<html><body><h1>"
+
"<html><body><h1>"
+
...
...
Examples/Titanium.Web.Proxy.Examples.Wpf/MainWindow.xaml.cs
View file @
1651c926
...
@@ -109,8 +109,8 @@ namespace Titanium.Web.Proxy.Examples.Wpf
...
@@ -109,8 +109,8 @@ namespace Titanium.Web.Proxy.Examples.Wpf
proxyServer
.
BeforeRequest
+=
ProxyServer_BeforeRequest
;
proxyServer
.
BeforeRequest
+=
ProxyServer_BeforeRequest
;
proxyServer
.
BeforeResponse
+=
ProxyServer_BeforeResponse
;
proxyServer
.
BeforeResponse
+=
ProxyServer_BeforeResponse
;
proxyServer
.
TunnelConnectRequest
+=
ProxyServer_TunnelConnectRequest
;
explicitEndPoint
.
TunnelConnectRequest
+=
ProxyServer_TunnelConnectRequest
;
proxyServer
.
TunnelConnectResponse
+=
ProxyServer_TunnelConnectResponse
;
explicitEndPoint
.
TunnelConnectResponse
+=
ProxyServer_TunnelConnectResponse
;
proxyServer
.
ClientConnectionCountChanged
+=
delegate
{
Dispatcher
.
Invoke
(()
=>
{
ClientConnectionCount
=
proxyServer
.
ClientConnectionCount
;
});
};
proxyServer
.
ClientConnectionCountChanged
+=
delegate
{
Dispatcher
.
Invoke
(()
=>
{
ClientConnectionCount
=
proxyServer
.
ClientConnectionCount
;
});
};
proxyServer
.
ServerConnectionCountChanged
+=
delegate
{
Dispatcher
.
Invoke
(()
=>
{
ServerConnectionCount
=
proxyServer
.
ServerConnectionCount
;
});
};
proxyServer
.
ServerConnectionCountChanged
+=
delegate
{
Dispatcher
.
Invoke
(()
=>
{
ServerConnectionCount
=
proxyServer
.
ServerConnectionCount
;
});
};
proxyServer
.
Start
();
proxyServer
.
Start
();
...
...
Titanium.Web.Proxy/Helpers/Firefox.cs
deleted
100644 → 0
View file @
4477f6de
using
System
;
using
System.IO
;
namespace
Titanium.Web.Proxy.Helpers
{
/// <summary>
/// A helper class to set proxy settings for firefox
/// </summary>
internal
class
FireFoxProxySettingsManager
{
/// <summary>
/// Add Firefox settings.
/// </summary>
internal
void
UseSystemProxy
()
{
try
{
var
myProfileDirectory
=
new
DirectoryInfo
(
Environment
.
GetFolderPath
(
Environment
.
SpecialFolder
.
ApplicationData
)
+
"\\Mozilla\\Firefox\\Profiles\\"
)
.
GetDirectories
(
"*.default"
);
string
myFfPrefFile
=
myProfileDirectory
[
0
].
FullName
+
"\\prefs.js"
;
if
(!
File
.
Exists
(
myFfPrefFile
))
{
return
;
}
// We have a pref file so let''s make sure it has the proxy setting
var
myReader
=
new
StreamReader
(
myFfPrefFile
);
string
myPrefContents
=
myReader
.
ReadToEnd
();
myReader
.
Close
();
for
(
int
i
=
0
;
i
<=
4
;
i
++)
{
string
searchStr
=
$"user_pref(\"network.proxy.type\",
{
i
}
);"
;
if
(
myPrefContents
.
Contains
(
searchStr
))
{
// Add the proxy enable line and write it back to the file
myPrefContents
=
myPrefContents
.
Replace
(
searchStr
,
"user_pref(\"network.proxy.type\", 5);"
);
}
}
File
.
Delete
(
myFfPrefFile
);
File
.
WriteAllText
(
myFfPrefFile
,
myPrefContents
);
}
catch
(
Exception
)
{
// Only exception should be a read/write error because the user opened up FireFox so they can be ignored.
}
}
}
}
Titanium.Web.Proxy/Helpers/HttpHelper.cs
View file @
1651c926
using
System
;
using
StreamExtended.Network
;
using
System
;
using
System.Text
;
using
System.Text
;
using
System.Threading.Tasks
;
using
Titanium.Web.Proxy.Extensions
;
using
Titanium.Web.Proxy.Extensions
;
using
Titanium.Web.Proxy.Http
;
using
Titanium.Web.Proxy.Http
;
using
Titanium.Web.Proxy.Shared
;
using
Titanium.Web.Proxy.Shared
;
...
@@ -113,5 +115,45 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -113,5 +115,45 @@ namespace Titanium.Web.Proxy.Helpers
//return as it is
//return as it is
return
hostname
;
return
hostname
;
}
}
/// <summary>
/// Determines whether is connect method.
/// </summary>
/// <param name="clientStream">The client stream.</param>
/// <returns>1: when CONNECT, 0: when valid HTTP method, -1: otherwise</returns>
internal
static
async
Task
<
int
>
IsConnectMethod
(
CustomBufferedStream
clientStream
)
{
bool
isConnect
=
true
;
int
legthToCheck
=
10
;
for
(
int
i
=
0
;
i
<
legthToCheck
;
i
++)
{
int
b
=
await
clientStream
.
PeekByteAsync
(
i
);
if
(
b
==
-
1
)
{
return
-
1
;
}
if
(
b
==
' '
&&
i
>
2
)
{
// at least 3 letters and a space
return
isConnect
?
1
:
0
;
}
char
ch
=
(
char
)
b
;
if
(!
char
.
IsLetter
(
ch
))
{
// non letter or too short
return
-
1
;
}
if
(
i
>
6
||
ch
!=
"CONNECT"
[
i
])
{
isConnect
=
false
;
}
}
// only letters
return
isConnect
?
1
:
0
;
}
}
}
}
}
Titanium.Web.Proxy/Models/EndPoint.cs
View file @
1651c926
...
@@ -5,6 +5,9 @@ using System.Net;
...
@@ -5,6 +5,9 @@ using System.Net;
using
System.Net.Sockets
;
using
System.Net.Sockets
;
using
System.Security.Cryptography.X509Certificates
;
using
System.Security.Cryptography.X509Certificates
;
using
System.Text.RegularExpressions
;
using
System.Text.RegularExpressions
;
using
System.Threading.Tasks
;
using
Titanium.Web.Proxy.EventArguments
;
using
Titanium.Web.Proxy.Extensions
;
namespace
Titanium.Web.Proxy.Models
namespace
Titanium.Web.Proxy.Models
{
{
...
@@ -67,9 +70,15 @@ namespace Titanium.Web.Proxy.Models
...
@@ -67,9 +70,15 @@ namespace Titanium.Web.Proxy.Models
internal
bool
IsSystemHttpsProxy
{
get
;
set
;
}
internal
bool
IsSystemHttpsProxy
{
get
;
set
;
}
/// <summary>
/// Generic certificate to use for SSL decryption.
/// </summary>
public
X509Certificate2
GenericCertificate
{
get
;
set
;
}
/// <summary>
/// <summary>
/// List of host names to exclude using Regular Expressions.
/// List of host names to exclude using Regular Expressions.
/// </summary>
/// </summary>
[
Obsolete
(
"ExcludedHttpsHostNameRegex is deprecated, please use BeforeTunnelConnect event instead."
)]
public
IEnumerable
<
string
>
ExcludedHttpsHostNameRegex
public
IEnumerable
<
string
>
ExcludedHttpsHostNameRegex
{
{
get
{
return
ExcludedHttpsHostNameRegexList
?.
Select
(
x
=>
x
.
ToString
()).
ToList
();
}
get
{
return
ExcludedHttpsHostNameRegexList
?.
Select
(
x
=>
x
.
ToString
()).
ToList
();
}
...
@@ -87,6 +96,7 @@ namespace Titanium.Web.Proxy.Models
...
@@ -87,6 +96,7 @@ namespace Titanium.Web.Proxy.Models
/// <summary>
/// <summary>
/// List of host names to exclude using Regular Expressions.
/// List of host names to exclude using Regular Expressions.
/// </summary>
/// </summary>
[
Obsolete
(
"IncludedHttpsHostNameRegex is deprecated, please use BeforeTunnelConnect event instead."
)]
public
IEnumerable
<
string
>
IncludedHttpsHostNameRegex
public
IEnumerable
<
string
>
IncludedHttpsHostNameRegex
{
{
get
{
return
IncludedHttpsHostNameRegexList
?.
Select
(
x
=>
x
.
ToString
()).
ToList
();
}
get
{
return
IncludedHttpsHostNameRegexList
?.
Select
(
x
=>
x
.
ToString
()).
ToList
();
}
...
@@ -102,10 +112,22 @@ namespace Titanium.Web.Proxy.Models
...
@@ -102,10 +112,22 @@ namespace Titanium.Web.Proxy.Models
}
}
/// <summary>
/// <summary>
/// Generic certificate to use for SSL decryption.
/// Return true if this HTTP connect request should'nt be decrypted and instead be relayed
/// Valid only for explicit endpoints
/// </summary>
/// </summary>
public
X509Certificate2
GenericCertificate
{
get
;
set
;
}
public
Func
<
string
,
Task
<
bool
>>
BeforeTunnelConnect
;
/// <summary>
/// Intercept tunnel connect request
/// Valid only for explicit endpoints
/// </summary>
public
event
AsyncEventHandler
<
TunnelConnectSessionEventArgs
>
TunnelConnectRequest
;
/// <summary>
/// Intercept tunnel connect response
/// Valid only for explicit endpoints
/// </summary>
public
event
AsyncEventHandler
<
TunnelConnectSessionEventArgs
>
TunnelConnectResponse
;
/// <summary>
/// <summary>
/// Constructor.
/// Constructor.
/// </summary>
/// </summary>
...
@@ -115,6 +137,31 @@ namespace Titanium.Web.Proxy.Models
...
@@ -115,6 +137,31 @@ namespace Titanium.Web.Proxy.Models
public
ExplicitProxyEndPoint
(
IPAddress
ipAddress
,
int
port
,
bool
enableSsl
)
:
base
(
ipAddress
,
port
,
enableSsl
)
public
ExplicitProxyEndPoint
(
IPAddress
ipAddress
,
int
port
,
bool
enableSsl
)
:
base
(
ipAddress
,
port
,
enableSsl
)
{
{
}
}
internal
async
Task
InvokeTunnectConnectRequest
(
ProxyServer
proxyServer
,
TunnelConnectSessionEventArgs
connectArgs
,
Action
<
Exception
>
exceptionFunc
)
{
if
(
TunnelConnectRequest
!=
null
)
{
await
TunnelConnectRequest
.
InvokeAsync
(
proxyServer
,
connectArgs
,
exceptionFunc
);
}
}
internal
async
Task
InvokeTunnectConnectResponse
(
ProxyServer
proxyServer
,
TunnelConnectSessionEventArgs
connectArgs
,
Action
<
Exception
>
exceptionFunc
)
{
if
(
TunnelConnectResponse
!=
null
)
{
await
TunnelConnectResponse
.
InvokeAsync
(
proxyServer
,
connectArgs
,
exceptionFunc
);
}
}
internal
async
Task
InvokeTunnectConnectResponse
(
ProxyServer
proxyServer
,
TunnelConnectSessionEventArgs
connectArgs
,
Action
<
Exception
>
exceptionFunc
,
bool
isClientHello
)
{
if
(
TunnelConnectResponse
!=
null
)
{
connectArgs
.
IsHttpsConnect
=
isClientHello
;
await
TunnelConnectResponse
.
InvokeAsync
(
proxyServer
,
connectArgs
,
exceptionFunc
);
}
}
}
}
/// <summary>
/// <summary>
...
...
Titanium.Web.Proxy/ProxyServer.cs
View file @
1651c926
This diff is collapsed.
Click to expand it.
Titanium.Web.Proxy/RequestHandler.cs
View file @
1651c926
...
@@ -50,7 +50,7 @@ namespace Titanium.Web.Proxy
...
@@ -50,7 +50,7 @@ namespace Titanium.Web.Proxy
ConnectRequest
connectRequest
=
null
;
ConnectRequest
connectRequest
=
null
;
//Client wants to create a secure tcp tunnel (probably its a HTTPS or Websocket request)
//Client wants to create a secure tcp tunnel (probably its a HTTPS or Websocket request)
if
(
await
IsConnectMethod
(
clientStream
)
==
1
)
if
(
await
HttpHelper
.
IsConnectMethod
(
clientStream
)
==
1
)
{
{
//read the first line HTTP command
//read the first line HTTP command
string
httpCmd
=
await
clientStreamReader
.
ReadLineAsync
();
string
httpCmd
=
await
clientStreamReader
.
ReadLineAsync
();
...
@@ -77,6 +77,11 @@ namespace Titanium.Web.Proxy
...
@@ -77,6 +77,11 @@ namespace Titanium.Web.Proxy
excluded
=
!
endPoint
.
IncludedHttpsHostNameRegexList
.
Any
(
x
=>
x
.
IsMatch
(
connectHostname
));
excluded
=
!
endPoint
.
IncludedHttpsHostNameRegexList
.
Any
(
x
=>
x
.
IsMatch
(
connectHostname
));
}
}
if
(
endPoint
.
BeforeTunnelConnect
!=
null
)
{
excluded
=
await
endPoint
.
BeforeTunnelConnect
(
connectHostname
);
}
connectRequest
=
new
ConnectRequest
connectRequest
=
new
ConnectRequest
{
{
RequestUri
=
httpRemoteUri
,
RequestUri
=
httpRemoteUri
,
...
@@ -90,18 +95,12 @@ namespace Titanium.Web.Proxy
...
@@ -90,18 +95,12 @@ namespace Titanium.Web.Proxy
connectArgs
.
ProxyClient
.
TcpClient
=
tcpClient
;
connectArgs
.
ProxyClient
.
TcpClient
=
tcpClient
;
connectArgs
.
ProxyClient
.
ClientStream
=
clientStream
;
connectArgs
.
ProxyClient
.
ClientStream
=
clientStream
;
if
(
TunnelConnectRequest
!=
null
)
await
endPoint
.
InvokeTunnectConnectRequest
(
this
,
connectArgs
,
ExceptionFunc
);
{
await
TunnelConnectRequest
.
InvokeAsync
(
this
,
connectArgs
,
ExceptionFunc
);
}
if
(
await
CheckAuthorization
(
clientStreamWriter
,
connectArgs
)
==
false
)
if
(
await
CheckAuthorization
(
clientStreamWriter
,
connectArgs
)
==
false
)
{
{
if
(
TunnelConnectResponse
!=
null
)
await
endPoint
.
InvokeTunnectConnectResponse
(
this
,
connectArgs
,
ExceptionFunc
);
{
await
TunnelConnectResponse
.
InvokeAsync
(
this
,
connectArgs
,
ExceptionFunc
);
}
return
;
return
;
}
}
...
@@ -119,11 +118,7 @@ namespace Titanium.Web.Proxy
...
@@ -119,11 +118,7 @@ namespace Titanium.Web.Proxy
connectRequest
.
ClientHelloInfo
=
clientHelloInfo
;
connectRequest
.
ClientHelloInfo
=
clientHelloInfo
;
}
}
if
(
TunnelConnectResponse
!=
null
)
await
endPoint
.
InvokeTunnectConnectResponse
(
this
,
connectArgs
,
ExceptionFunc
,
isClientHello
);
{
connectArgs
.
IsHttpsConnect
=
isClientHello
;
await
TunnelConnectResponse
.
InvokeAsync
(
this
,
connectArgs
,
ExceptionFunc
);
}
if
(!
excluded
&&
isClientHello
)
if
(!
excluded
&&
isClientHello
)
{
{
...
@@ -155,7 +150,7 @@ namespace Titanium.Web.Proxy
...
@@ -155,7 +150,7 @@ namespace Titanium.Web.Proxy
return
;
return
;
}
}
if
(
await
IsConnectMethod
(
clientStream
)
==
-
1
)
if
(
await
HttpHelper
.
IsConnectMethod
(
clientStream
)
==
-
1
)
{
{
// It can be for example some Google (Cloude Messaging for Chrome) magic
// It can be for example some Google (Cloude Messaging for Chrome) magic
excluded
=
true
;
excluded
=
true
;
...
@@ -228,45 +223,6 @@ namespace Titanium.Web.Proxy
...
@@ -228,45 +223,6 @@ namespace Titanium.Web.Proxy
}
}
}
}
/// <summary>
/// Determines whether is connect method.
/// </summary>
/// <param name="clientStream">The client stream.</param>
/// <returns>1: when CONNECT, 0: when valid HTTP method, -1: otherwise</returns>
private
async
Task
<
int
>
IsConnectMethod
(
CustomBufferedStream
clientStream
)
{
bool
isConnect
=
true
;
int
legthToCheck
=
10
;
for
(
int
i
=
0
;
i
<
legthToCheck
;
i
++)
{
int
b
=
await
clientStream
.
PeekByteAsync
(
i
);
if
(
b
==
-
1
)
{
return
-
1
;
}
if
(
b
==
' '
&&
i
>
2
)
{
// at least 3 letters and a space
return
isConnect
?
1
:
0
;
}
char
ch
=
(
char
)
b
;
if
(!
char
.
IsLetter
(
ch
))
{
// non letter or too short
return
-
1
;
}
if
(
i
>
6
||
ch
!=
"CONNECT"
[
i
])
{
isConnect
=
false
;
}
}
// only letters
return
isConnect
?
1
:
0
;
}
/// <summary>
/// <summary>
/// This is called when this proxy acts as a reverse proxy (like a real http server)
/// This is called when this proxy acts as a reverse proxy (like a real http server)
...
@@ -640,15 +596,9 @@ namespace Titanium.Web.Proxy
...
@@ -640,15 +596,9 @@ namespace Titanium.Web.Proxy
/// <param name="requestHeaders"></param>
/// <param name="requestHeaders"></param>
private
void
PrepareRequestHeaders
(
HeaderCollection
requestHeaders
)
private
void
PrepareRequestHeaders
(
HeaderCollection
requestHeaders
)
{
{
foreach
(
var
header
in
requestHeaders
)
if
(
requestHeaders
.
HeaderExists
(
KnownHeaders
.
AcceptEncoding
))
{
switch
(
header
.
Name
.
ToLower
())
{
{
//these are the only encoding this proxy can read
requestHeaders
.
SetOrAddHeaderValue
(
KnownHeaders
.
AcceptEncoding
,
"gzip,deflate"
);
case
KnownHeaders
.
AcceptEncoding
:
header
.
Value
=
"gzip,deflate"
;
break
;
}
}
}
requestHeaders
.
FixProxyHeaders
();
requestHeaders
.
FixProxyHeaders
();
...
...
Titanium.Web.Proxy/WinAuthHandler.cs
View file @
1651c926
...
@@ -38,7 +38,7 @@ namespace Titanium.Web.Proxy
...
@@ -38,7 +38,7 @@ namespace Titanium.Web.Proxy
/// User to server to authenticate requests.
/// User to server to authenticate requests.
/// To disable this set ProxyServer.EnableWinAuth to false
/// To disable this set ProxyServer.EnableWinAuth to false
/// </summary>
/// </summary>
internal
async
Task
<
bool
>
Handle401UnAuthorized
(
SessionEventArgs
args
)
internal
async
Task
Handle401UnAuthorized
(
SessionEventArgs
args
)
{
{
string
headerName
=
null
;
string
headerName
=
null
;
HttpHeader
authHeader
=
null
;
HttpHeader
authHeader
=
null
;
...
@@ -137,8 +137,6 @@ namespace Titanium.Web.Proxy
...
@@ -137,8 +137,6 @@ namespace Titanium.Web.Proxy
//and server cookies
//and server cookies
await
HandleHttpSessionRequestInternal
(
args
.
WebSession
.
ServerConnection
,
args
);
await
HandleHttpSessionRequestInternal
(
args
.
WebSession
.
ServerConnection
,
args
);
}
}
return
false
;
}
}
}
}
}
}
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