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
d49448ea
Commit
d49448ea
authored
Jun 28, 2017
by
Honfika
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix for #289
parent
70e1a0dd
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
57 additions
and
35 deletions
+57
-35
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
TcpConnectionFactory.cs
Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs
+27
-24
RequestHandler.cs
Titanium.Web.Proxy/RequestHandler.cs
+7
-6
No files found.
Examples/Titanium.Web.Proxy.Examples.Wpf/MainWindow.xaml.cs
View file @
d49448ea
...
@@ -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 @
d49448ea
...
@@ -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 @
d49448ea
...
@@ -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 @
d49448ea
...
@@ -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/TcpConnectionFactory.cs
View file @
d49448ea
...
@@ -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
...
...
Titanium.Web.Proxy/RequestHandler.cs
View file @
d49448ea
...
@@ -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