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
d05aa8c4
Commit
d05aa8c4
authored
Jun 28, 2017
by
Jehonathan Thomas
Committed by
GitHub
Jun 28, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #291 from honfika/develop
Fix for #289
parents
e651e429
1e8cf7e2
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
64 additions
and
42 deletions
+64
-42
MainWindow.xaml.cs
Examples/Titanium.Web.Proxy.Examples.Wpf/MainWindow.xaml.cs
+9
-0
SessionEventArgs.cs
Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs
+1
-1
HttpWebClient.cs
Titanium.Web.Proxy/Http/HttpWebClient.cs
+2
-3
Request.cs
Titanium.Web.Proxy/Http/Request.cs
+11
-1
TcpConnection.cs
Titanium.Web.Proxy/Network/Tcp/TcpConnection.cs
+2
-2
TcpConnectionFactory.cs
Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs
+32
-29
RequestHandler.cs
Titanium.Web.Proxy/RequestHandler.cs
+7
-6
No files found.
Examples/Titanium.Web.Proxy.Examples.Wpf/MainWindow.xaml.cs
View file @
d05aa8c4
...
@@ -76,7 +76,16 @@ namespace Titanium.Web.Proxy.Examples.Wpf
...
@@ -76,7 +76,16 @@ namespace Titanium.Web.Proxy.Examples.Wpf
{
{
//IncludedHttpsHostNameRegex = new string[0],
//IncludedHttpsHostNameRegex = new string[0],
};
};
proxyServer
.
AddEndPoint
(
explicitEndPoint
);
proxyServer
.
AddEndPoint
(
explicitEndPoint
);
//proxyServer.UpStreamHttpProxy = new ExternalProxy
//{
// HostName = "158.69.115.45",
// Port = 3128,
// UserName = "Titanium",
// Password = "Titanium",
//};
proxyServer
.
BeforeRequest
+=
ProxyServer_BeforeRequest
;
proxyServer
.
BeforeRequest
+=
ProxyServer_BeforeRequest
;
proxyServer
.
BeforeResponse
+=
ProxyServer_BeforeResponse
;
proxyServer
.
BeforeResponse
+=
ProxyServer_BeforeResponse
;
proxyServer
.
TunnelConnectRequest
+=
ProxyServer_TunnelConnectRequest
;
proxyServer
.
TunnelConnectRequest
+=
ProxyServer_TunnelConnectRequest
;
...
...
Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs
View file @
d05aa8c4
...
@@ -69,7 +69,7 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -69,7 +69,7 @@ namespace Titanium.Web.Proxy.EventArguments
/// <summary>
/// <summary>
/// Does this session uses SSL
/// Does this session uses SSL
/// </summary>
/// </summary>
public
bool
IsHttps
=>
WebSession
.
Request
.
RequestUri
.
Scheme
==
ProxyServer
.
UriScheme
Https
;
public
bool
IsHttps
=>
WebSession
.
Request
.
Is
Https
;
/// <summary>
/// <summary>
/// Client End Point.
/// Client End Point.
...
...
Titanium.Web.Proxy/Http/HttpWebClient.cs
View file @
d05aa8c4
...
@@ -49,8 +49,7 @@ namespace Titanium.Web.Proxy.Http
...
@@ -49,8 +49,7 @@ namespace Titanium.Web.Proxy.Http
/// <summary>
/// <summary>
/// Is Https?
/// Is Https?
/// </summary>
/// </summary>
public
bool
IsHttps
=>
Request
.
RequestUri
.
Scheme
==
ProxyServer
.
UriSchemeHttps
;
public
bool
IsHttps
=>
Request
.
IsHttps
;
internal
HttpWebClient
()
internal
HttpWebClient
()
{
{
...
@@ -81,7 +80,7 @@ namespace Titanium.Web.Proxy.Http
...
@@ -81,7 +80,7 @@ namespace Titanium.Web.Proxy.Http
var
requestLines
=
new
StringBuilder
();
var
requestLines
=
new
StringBuilder
();
//prepare the request & headers
//prepare the request & headers
requestLines
.
AppendLine
(
$"
{
Request
.
Method
}
{
Request
.
RequestUri
.
PathAndQuery
}
HTTP/
{
Request
.
HttpVersion
.
Major
}
.
{
Request
.
HttpVersion
.
Minor
}
"
);
requestLines
.
AppendLine
(
$"
{
Request
.
Method
}
{
Request
.
OriginalRequestUrl
}
HTTP/
{
Request
.
HttpVersion
.
Major
}
.
{
Request
.
HttpVersion
.
Minor
}
"
);
//Send Authentication to Upstream proxy if needed
//Send Authentication to Upstream proxy if needed
...
...
Titanium.Web.Proxy/Http/Request.cs
View file @
d05aa8c4
...
@@ -23,6 +23,16 @@ namespace Titanium.Web.Proxy.Http
...
@@ -23,6 +23,16 @@ namespace Titanium.Web.Proxy.Http
/// </summary>
/// </summary>
public
Uri
RequestUri
{
get
;
set
;
}
public
Uri
RequestUri
{
get
;
set
;
}
/// <summary>
/// Is Https?
/// </summary>
public
bool
IsHttps
=>
RequestUri
.
Scheme
==
ProxyServer
.
UriSchemeHttps
;
/// <summary>
/// The original request Url.
/// </summary>
public
string
OriginalRequestUrl
{
get
;
set
;
}
/// <summary>
/// <summary>
/// Request Http Version
/// Request Http Version
/// </summary>
/// </summary>
...
@@ -219,7 +229,7 @@ namespace Titanium.Web.Proxy.Http
...
@@ -219,7 +229,7 @@ namespace Titanium.Web.Proxy.Http
get
get
{
{
var
sb
=
new
StringBuilder
();
var
sb
=
new
StringBuilder
();
sb
.
AppendLine
(
$"
{
Method
}
{
RequestUri
.
PathAndQuery
}
HTTP/
{
HttpVersion
.
Major
}
.
{
HttpVersion
.
Minor
}
"
);
sb
.
AppendLine
(
$"
{
Method
}
{
OriginalRequestUrl
}
HTTP/
{
HttpVersion
.
Major
}
.
{
HttpVersion
.
Minor
}
"
);
foreach
(
var
header
in
RequestHeaders
)
foreach
(
var
header
in
RequestHeaders
)
{
{
sb
.
AppendLine
(
header
.
ToString
());
sb
.
AppendLine
(
header
.
ToString
());
...
...
Titanium.Web.Proxy/Network/Tcp/TcpConnection.cs
View file @
d05aa8c4
...
@@ -16,7 +16,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
...
@@ -16,7 +16,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
internal
ExternalProxy
UpStreamHttpsProxy
{
get
;
set
;
}
internal
ExternalProxy
UpStreamHttpsProxy
{
get
;
set
;
}
internal
ExternalProxy
UpStreamProxy
=>
UseProxy
?
IsHttps
?
UpStreamHttpsProxy
:
UpStreamHttpProxy
:
null
;
internal
ExternalProxy
UpStreamProxy
=>
Use
Upstream
Proxy
?
IsHttps
?
UpStreamHttpsProxy
:
UpStreamHttpProxy
:
null
;
internal
string
HostName
{
get
;
set
;
}
internal
string
HostName
{
get
;
set
;
}
...
@@ -24,7 +24,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
...
@@ -24,7 +24,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
internal
bool
IsHttps
{
get
;
set
;
}
internal
bool
IsHttps
{
get
;
set
;
}
internal
bool
UseProxy
{
get
;
set
;
}
internal
bool
Use
Upstream
Proxy
{
get
;
set
;
}
/// <summary>
/// <summary>
/// Http version
/// Http version
...
...
Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs
View file @
d05aa8c4
...
@@ -32,18 +32,18 @@ namespace Titanium.Web.Proxy.Network.Tcp
...
@@ -32,18 +32,18 @@ namespace Titanium.Web.Proxy.Network.Tcp
internal
async
Task
<
TcpConnection
>
CreateClient
(
ProxyServer
server
,
string
remoteHostName
,
int
remotePort
,
Version
httpVersion
,
bool
isHttps
,
internal
async
Task
<
TcpConnection
>
CreateClient
(
ProxyServer
server
,
string
remoteHostName
,
int
remotePort
,
Version
httpVersion
,
bool
isHttps
,
ExternalProxy
externalHttpProxy
,
ExternalProxy
externalHttpsProxy
)
ExternalProxy
externalHttpProxy
,
ExternalProxy
externalHttpsProxy
)
{
{
bool
useProxy
=
false
;
bool
use
Upstream
Proxy
=
false
;
var
externalProxy
=
isHttps
?
externalHttpsProxy
:
externalHttpProxy
;
var
externalProxy
=
isHttps
?
externalHttpsProxy
:
externalHttpProxy
;
//check if external proxy is set for HTTP/HTTPS
//check if external proxy is set for HTTP/HTTPS
if
(
externalProxy
!=
null
&&
!(
externalProxy
.
HostName
==
remoteHostName
&&
externalProxy
.
Port
==
remotePort
))
if
(
externalProxy
!=
null
&&
!(
externalProxy
.
HostName
==
remoteHostName
&&
externalProxy
.
Port
==
remotePort
))
{
{
useProxy
=
true
;
use
Upstream
Proxy
=
true
;
//check if we need to ByPass
//check if we need to ByPass
if
(
externalProxy
.
BypassLocalhost
&&
NetworkHelper
.
IsLocalIpAddress
(
remoteHostName
))
if
(
externalProxy
.
BypassLocalhost
&&
NetworkHelper
.
IsLocalIpAddress
(
remoteHostName
))
{
{
useProxy
=
false
;
use
Upstream
Proxy
=
false
;
}
}
}
}
...
@@ -53,7 +53,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
...
@@ -53,7 +53,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
try
try
{
{
//If this proxy uses another external proxy then create a tunnel request for HTTP/HTTPS connections
//If this proxy uses another external proxy then create a tunnel request for HTTP/HTTPS connections
if
(
useProxy
)
if
(
use
Upstream
Proxy
)
{
{
#if NET45
#if NET45
client
=
new
TcpClient
(
server
.
UpStreamEndPoint
);
client
=
new
TcpClient
(
server
.
UpStreamEndPoint
);
...
@@ -63,36 +63,39 @@ namespace Titanium.Web.Proxy.Network.Tcp
...
@@ -63,36 +63,39 @@ namespace Titanium.Web.Proxy.Network.Tcp
await
client
.
ConnectAsync
(
externalProxy
.
HostName
,
externalProxy
.
Port
);
await
client
.
ConnectAsync
(
externalProxy
.
HostName
,
externalProxy
.
Port
);
stream
=
new
CustomBufferedStream
(
client
.
GetStream
(),
server
.
BufferSize
);
stream
=
new
CustomBufferedStream
(
client
.
GetStream
(),
server
.
BufferSize
);
using
(
var
writer
=
new
StreamWriter
(
stream
,
Encoding
.
ASCII
,
server
.
BufferSize
,
true
)
if
(
isHttps
)
{
{
NewLine
=
ProxyConstants
.
NewLine
using
(
var
writer
=
new
StreamWriter
(
stream
,
Encoding
.
ASCII
,
server
.
BufferSize
,
true
)
})
{
await
writer
.
WriteLineAsync
(
$"CONNECT
{
remoteHostName
}
:
{
remotePort
}
HTTP/
{
httpVersion
}
"
);
await
writer
.
WriteLineAsync
(
$"Host:
{
remoteHostName
}
:
{
remotePort
}
"
);
await
writer
.
WriteLineAsync
(
"Connection: Keep-Alive"
);
if
(!
string
.
IsNullOrEmpty
(
externalProxy
.
UserName
)
&&
externalProxy
.
Password
!=
null
)
{
{
await
writer
.
WriteLineAsync
(
"Proxy-Connection: keep-alive"
);
NewLine
=
ProxyConstants
.
NewLine
await
writer
.
WriteLineAsync
(
"Proxy-Authorization"
+
": Basic "
+
})
Convert
.
ToBase64String
(
Encoding
.
UTF8
.
GetBytes
(
{
externalProxy
.
UserName
+
":"
+
externalProxy
.
Password
)));
await
writer
.
WriteLineAsync
(
$"CONNECT
{
remoteHostName
}
:
{
remotePort
}
HTTP/
{
httpVersion
}
"
);
}
await
writer
.
WriteLineAsync
(
$"Host:
{
remoteHostName
}
:
{
remotePort
}
"
);
await
writer
.
WriteLineAsync
();
await
writer
.
WriteLineAsync
(
"Connection: Keep-Alive"
);
await
writer
.
FlushAsync
();
}
using
(
var
reader
=
new
CustomBinaryReader
(
stream
,
server
.
BufferSize
))
if
(!
string
.
IsNullOrEmpty
(
externalProxy
.
UserName
)
&&
externalProxy
.
Password
!=
null
)
{
{
string
result
=
await
reader
.
ReadLineAsync
();
await
writer
.
WriteLineAsync
(
"Proxy-Connection: keep-alive"
);
await
writer
.
WriteLineAsync
(
"Proxy-Authorization"
+
": Basic "
+
Convert
.
ToBase64String
(
Encoding
.
UTF8
.
GetBytes
(
externalProxy
.
UserName
+
":"
+
externalProxy
.
Password
)));
}
await
writer
.
WriteLineAsync
();
await
writer
.
FlushAsync
();
}
if
(!
new
[]
{
"200 OK"
,
"connection established"
}.
Any
(
s
=>
result
.
ContainsIgnoreCase
(
s
)
))
using
(
var
reader
=
new
CustomBinaryReader
(
stream
,
server
.
BufferSize
))
{
{
throw
new
Exception
(
"Upstream proxy failed to create a secure tunnel"
);
string
result
=
await
reader
.
ReadLineAsync
();
}
await
reader
.
ReadAndIgnoreAllLinesAsync
();
if
(!
new
[]
{
"200 OK"
,
"connection established"
}.
Any
(
s
=>
result
.
ContainsIgnoreCase
(
s
)))
{
throw
new
Exception
(
"Upstream proxy failed to create a secure tunnel"
);
}
await
reader
.
ReadAndIgnoreAllLinesAsync
();
}
}
}
}
}
else
else
...
@@ -133,7 +136,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
...
@@ -133,7 +136,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
HostName
=
remoteHostName
,
HostName
=
remoteHostName
,
Port
=
remotePort
,
Port
=
remotePort
,
IsHttps
=
isHttps
,
IsHttps
=
isHttps
,
Use
Proxy
=
use
Proxy
,
Use
UpstreamProxy
=
useUpstream
Proxy
,
TcpClient
=
client
,
TcpClient
=
client
,
StreamReader
=
new
CustomBinaryReader
(
stream
,
server
.
BufferSize
),
StreamReader
=
new
CustomBinaryReader
(
stream
,
server
.
BufferSize
),
Stream
=
stream
,
Stream
=
stream
,
...
...
Titanium.Web.Proxy/RequestHandler.cs
View file @
d05aa8c4
...
@@ -85,6 +85,7 @@ namespace Titanium.Web.Proxy
...
@@ -85,6 +85,7 @@ namespace Titanium.Web.Proxy
connectRequest
=
new
ConnectRequest
connectRequest
=
new
ConnectRequest
{
{
RequestUri
=
httpRemoteUri
,
RequestUri
=
httpRemoteUri
,
OriginalRequestUrl
=
httpUrl
,
HttpVersion
=
version
,
HttpVersion
=
version
,
Method
=
httpMethod
,
Method
=
httpMethod
,
};
};
...
@@ -303,6 +304,7 @@ namespace Titanium.Web.Proxy
...
@@ -303,6 +304,7 @@ namespace Titanium.Web.Proxy
:
string
.
Concat
(
"https://"
,
args
.
WebSession
.
Request
.
Host
??
httpsConnectHostname
,
httpUrl
));
:
string
.
Concat
(
"https://"
,
args
.
WebSession
.
Request
.
Host
??
httpsConnectHostname
,
httpUrl
));
args
.
WebSession
.
Request
.
RequestUri
=
httpRemoteUri
;
args
.
WebSession
.
Request
.
RequestUri
=
httpRemoteUri
;
args
.
WebSession
.
Request
.
OriginalRequestUrl
=
httpUrl
;
args
.
WebSession
.
Request
.
Method
=
httpMethod
;
args
.
WebSession
.
Request
.
Method
=
httpMethod
;
args
.
WebSession
.
Request
.
HttpVersion
=
version
;
args
.
WebSession
.
Request
.
HttpVersion
=
version
;
...
@@ -318,7 +320,6 @@ namespace Titanium.Web.Proxy
...
@@ -318,7 +320,6 @@ namespace Titanium.Web.Proxy
}
}
PrepareRequestHeaders
(
args
.
WebSession
.
Request
.
RequestHeaders
);
PrepareRequestHeaders
(
args
.
WebSession
.
Request
.
RequestHeaders
);
args
.
WebSession
.
Request
.
Host
=
args
.
WebSession
.
Request
.
RequestUri
.
Authority
;
#if NET45
#if NET45
//if win auth is enabled
//if win auth is enabled
...
@@ -572,18 +573,18 @@ namespace Titanium.Web.Proxy
...
@@ -572,18 +573,18 @@ namespace Titanium.Web.Proxy
ExternalProxy
customUpStreamHttpProxy
=
null
;
ExternalProxy
customUpStreamHttpProxy
=
null
;
ExternalProxy
customUpStreamHttpsProxy
=
null
;
ExternalProxy
customUpStreamHttpsProxy
=
null
;
if
(
args
.
WebSession
.
Request
.
RequestUri
.
Scheme
==
UriSchemeHttp
)
if
(
args
.
WebSession
.
Request
.
IsHttps
)
{
{
if
(
GetCustomUpStreamHttpProxyFunc
!=
null
)
if
(
GetCustomUpStreamHttp
s
ProxyFunc
!=
null
)
{
{
customUpStreamHttp
Proxy
=
await
GetCustomUpStreamHttp
ProxyFunc
(
args
);
customUpStreamHttp
sProxy
=
await
GetCustomUpStreamHttps
ProxyFunc
(
args
);
}
}
}
}
else
else
{
{
if
(
GetCustomUpStreamHttp
s
ProxyFunc
!=
null
)
if
(
GetCustomUpStreamHttpProxyFunc
!=
null
)
{
{
customUpStreamHttp
sProxy
=
await
GetCustomUpStreamHttps
ProxyFunc
(
args
);
customUpStreamHttp
Proxy
=
await
GetCustomUpStreamHttp
ProxyFunc
(
args
);
}
}
}
}
...
...
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