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
70d144f3
Commit
70d144f3
authored
Sep 01, 2016
by
ilushka85
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add connect headers to the headers passed into the upstreamproxy decider function
parent
4c75ae15
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
16 deletions
+31
-16
RequestHandler.cs
Titanium.Web.Proxy/RequestHandler.cs
+31
-16
No files found.
Titanium.Web.Proxy/RequestHandler.cs
View file @
70d144f3
...
@@ -25,7 +25,7 @@ namespace Titanium.Web.Proxy
...
@@ -25,7 +25,7 @@ namespace Titanium.Web.Proxy
partial
class
ProxyServer
partial
class
ProxyServer
{
{
private
async
Task
<
bool
>
CheckAuthorization
(
StreamWriter
clientStreamWriter
,
IEnumerable
<
HttpHeader
>
Headers
)
private
async
Task
<
bool
>
CheckAuthorization
(
StreamWriter
clientStreamWriter
,
IEnumerable
<
HttpHeader
>
Headers
)
{
{
if
(
AuthenticateUserFunc
==
null
)
if
(
AuthenticateUserFunc
==
null
)
{
{
...
@@ -86,7 +86,7 @@ namespace Titanium.Web.Proxy
...
@@ -86,7 +86,7 @@ namespace Titanium.Web.Proxy
return
await
AuthenticateUserFunc
(
username
,
password
).
ConfigureAwait
(
false
);
return
await
AuthenticateUserFunc
(
username
,
password
).
ConfigureAwait
(
false
);
}
}
}
}
catch
(
Exception
e
)
catch
(
Exception
e
)
{
{
//Return not authorized
//Return not authorized
await
WriteResponseStatus
(
new
Version
(
1
,
1
),
"407"
,
await
WriteResponseStatus
(
new
Version
(
1
,
1
),
"407"
,
...
@@ -156,20 +156,23 @@ namespace Titanium.Web.Proxy
...
@@ -156,20 +156,23 @@ namespace Titanium.Web.Proxy
var
excluded
=
endPoint
.
ExcludedHttpsHostNameRegex
!=
null
?
var
excluded
=
endPoint
.
ExcludedHttpsHostNameRegex
!=
null
?
endPoint
.
ExcludedHttpsHostNameRegex
.
Any
(
x
=>
Regex
.
IsMatch
(
httpRemoteUri
.
Host
,
x
))
:
false
;
endPoint
.
ExcludedHttpsHostNameRegex
.
Any
(
x
=>
Regex
.
IsMatch
(
httpRemoteUri
.
Host
,
x
))
:
false
;
List
<
HttpHeader
>
connectRequestHeaders
=
null
;
//Client wants to create a secure tcp tunnel (its a HTTPS request)
//Client wants to create a secure tcp tunnel (its a HTTPS request)
if
(
httpVerb
.
ToUpper
()
==
"CONNECT"
&&
!
excluded
&&
httpRemoteUri
.
Port
!=
80
)
if
(
httpVerb
.
ToUpper
()
==
"CONNECT"
&&
!
excluded
&&
httpRemoteUri
.
Port
!=
80
)
{
{
httpRemoteUri
=
new
Uri
(
"https://"
+
httpCmdSplit
[
1
]);
httpRemoteUri
=
new
Uri
(
"https://"
+
httpCmdSplit
[
1
]);
string
tmpLine
=
null
;
string
tmpLine
=
null
;
List
<
HttpHeader
>
h
eaders
=
new
List
<
HttpHeader
>();
connectRequestH
eaders
=
new
List
<
HttpHeader
>();
while
(!
string
.
IsNullOrEmpty
(
tmpLine
=
await
clientStreamReader
.
ReadLineAsync
()))
while
(!
string
.
IsNullOrEmpty
(
tmpLine
=
await
clientStreamReader
.
ReadLineAsync
()))
{
{
var
header
=
tmpLine
.
Split
(
ProxyConstants
.
ColonSplit
,
2
);
var
header
=
tmpLine
.
Split
(
ProxyConstants
.
ColonSplit
,
2
);
var
newHeader
=
new
HttpHeader
(
header
[
0
],
header
[
1
]);
var
newHeader
=
new
HttpHeader
(
header
[
0
],
header
[
1
]);
h
eaders
.
Add
(
newHeader
);
connectRequestH
eaders
.
Add
(
newHeader
);
}
}
if
(
await
CheckAuthorization
(
clientStreamWriter
,
h
eaders
)
==
false
)
if
(
await
CheckAuthorization
(
clientStreamWriter
,
connectRequestH
eaders
)
==
false
)
{
{
Dispose
(
clientStream
,
clientStreamReader
,
clientStreamWriter
,
null
);
Dispose
(
clientStream
,
clientStreamReader
,
clientStreamWriter
,
null
);
return
;
return
;
...
@@ -230,7 +233,7 @@ namespace Titanium.Web.Proxy
...
@@ -230,7 +233,7 @@ namespace Titanium.Web.Proxy
}
}
//Now create the request
//Now create the request
await
HandleHttpSessionRequest
(
client
,
httpCmd
,
clientStream
,
clientStreamReader
,
clientStreamWriter
,
await
HandleHttpSessionRequest
(
client
,
httpCmd
,
clientStream
,
clientStreamReader
,
clientStreamWriter
,
httpRemoteUri
.
Scheme
==
Uri
.
UriSchemeHttps
?
httpRemoteUri
.
Host
:
null
,
null
,
null
);
httpRemoteUri
.
Scheme
==
Uri
.
UriSchemeHttps
?
httpRemoteUri
.
Host
:
null
,
connectRequestHeaders
,
null
,
null
);
}
}
catch
(
Exception
ex
)
catch
(
Exception
ex
)
{
{
...
@@ -291,7 +294,7 @@ namespace Titanium.Web.Proxy
...
@@ -291,7 +294,7 @@ namespace Titanium.Web.Proxy
//Now create the request
//Now create the request
await
HandleHttpSessionRequest
(
tcpClient
,
httpCmd
,
clientStream
,
clientStreamReader
,
clientStreamWriter
,
await
HandleHttpSessionRequest
(
tcpClient
,
httpCmd
,
clientStream
,
clientStreamReader
,
clientStreamWriter
,
endPoint
.
EnableSsl
?
endPoint
.
GenericCertificateName
:
null
);
endPoint
.
EnableSsl
?
endPoint
.
GenericCertificateName
:
null
,
null
);
}
}
/// <summary>
/// <summary>
/// This is the core request handler method for a particular connection from client
/// This is the core request handler method for a particular connection from client
...
@@ -304,7 +307,7 @@ namespace Titanium.Web.Proxy
...
@@ -304,7 +307,7 @@ namespace Titanium.Web.Proxy
/// <param name="httpsHostName"></param>
/// <param name="httpsHostName"></param>
/// <returns></returns>
/// <returns></returns>
private
async
Task
HandleHttpSessionRequest
(
TcpClient
client
,
string
httpCmd
,
Stream
clientStream
,
private
async
Task
HandleHttpSessionRequest
(
TcpClient
client
,
string
httpCmd
,
Stream
clientStream
,
CustomBinaryReader
clientStreamReader
,
StreamWriter
clientStreamWriter
,
string
httpsHostName
,
ExternalProxy
customUpStreamHttpProxy
=
null
,
ExternalProxy
customUpStreamHttpsProxy
=
null
)
CustomBinaryReader
clientStreamReader
,
StreamWriter
clientStreamWriter
,
string
httpsHostName
,
List
<
HttpHeader
>
connectHeaders
,
ExternalProxy
customUpStreamHttpProxy
=
null
,
ExternalProxy
customUpStreamHttpsProxy
=
null
)
{
{
TcpConnection
connection
=
null
;
TcpConnection
connection
=
null
;
...
@@ -386,7 +389,7 @@ namespace Titanium.Web.Proxy
...
@@ -386,7 +389,7 @@ namespace Titanium.Web.Proxy
args
.
ProxyClient
.
ClientStreamReader
=
clientStreamReader
;
args
.
ProxyClient
.
ClientStreamReader
=
clientStreamReader
;
args
.
ProxyClient
.
ClientStreamWriter
=
clientStreamWriter
;
args
.
ProxyClient
.
ClientStreamWriter
=
clientStreamWriter
;
if
(
httpsHostName
==
null
&&
(
await
CheckAuthorization
(
clientStreamWriter
,
args
.
WebSession
.
Request
.
RequestHeaders
.
Values
)
==
false
))
if
(
httpsHostName
==
null
&&
(
await
CheckAuthorization
(
clientStreamWriter
,
args
.
WebSession
.
Request
.
RequestHeaders
.
Values
)
==
false
))
{
{
Dispose
(
clientStream
,
clientStreamReader
,
clientStreamWriter
,
args
);
Dispose
(
clientStream
,
clientStreamReader
,
clientStreamWriter
,
args
);
...
@@ -428,12 +431,24 @@ namespace Titanium.Web.Proxy
...
@@ -428,12 +431,24 @@ namespace Titanium.Web.Proxy
//construct the web request that we are going to issue on behalf of the client.
//construct the web request that we are going to issue on behalf of the client.
if
(
connection
==
null
)
if
(
connection
==
null
)
{
{
if
(
httpsHostName
==
null
)
{
if
(
GetCustomUpStreamHttpProxyFunc
!=
null
)
if
(
GetCustomUpStreamHttpProxyFunc
!=
null
)
{
customUpStreamHttpProxy
=
GetCustomUpStreamHttpProxyFunc
(
args
.
WebSession
.
Request
.
RequestHeaders
.
Values
);
customUpStreamHttpProxy
=
GetCustomUpStreamHttpProxyFunc
(
args
.
WebSession
.
Request
.
RequestHeaders
.
Values
);
}
}
else
{
if
(
GetCustomUpStreamHttpsProxyFunc
!=
null
)
if
(
GetCustomUpStreamHttpsProxyFunc
!=
null
)
customUpStreamHttpsProxy
=
GetCustomUpStreamHttpsProxyFunc
(
args
.
WebSession
.
Request
.
RequestHeaders
.
Values
);
{
foreach
(
var
header
in
args
.
WebSession
.
Request
.
RequestHeaders
.
Values
)
{
connectHeaders
.
Add
(
header
);
}
customUpStreamHttpsProxy
=
GetCustomUpStreamHttpsProxyFunc
(
connectHeaders
);
}
}
connection
=
await
tcpConnectionFactory
.
CreateClient
(
BUFFER_SIZE
,
ConnectionTimeOutSeconds
,
connection
=
await
tcpConnectionFactory
.
CreateClient
(
BUFFER_SIZE
,
ConnectionTimeOutSeconds
,
args
.
WebSession
.
Request
.
RequestUri
.
Host
,
args
.
WebSession
.
Request
.
RequestUri
.
Port
,
httpVersion
,
args
.
WebSession
.
Request
.
RequestUri
.
Host
,
args
.
WebSession
.
Request
.
RequestUri
.
Port
,
httpVersion
,
...
...
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