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
989b6cad
Commit
989b6cad
authored
Mar 01, 2018
by
Honfika
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
do not change headers in transparent mode
parent
f11b6b60
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
33 additions
and
19 deletions
+33
-19
SessionEventArgs.cs
Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs
+3
-1
HttpResponseWriter.cs
Titanium.Web.Proxy/Helpers/HttpResponseWriter.cs
+0
-1
HttpWebClient.cs
Titanium.Web.Proxy/Http/HttpWebClient.cs
+4
-4
ProxyAuthorizationHandler.cs
Titanium.Web.Proxy/ProxyAuthorizationHandler.cs
+1
-0
RequestHandler.cs
Titanium.Web.Proxy/RequestHandler.cs
+20
-12
ResponseHandler.cs
Titanium.Web.Proxy/ResponseHandler.cs
+5
-1
No files found.
Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs
View file @
989b6cad
...
@@ -96,7 +96,9 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -96,7 +96,9 @@ namespace Titanium.Web.Proxy.EventArguments
/// </summary>
/// </summary>
public
event
EventHandler
<
MultipartRequestPartSentEventArgs
>
MultipartRequestPartSent
;
public
event
EventHandler
<
MultipartRequestPartSentEventArgs
>
MultipartRequestPartSent
;
public
ProxyEndPoint
LocalEndPoint
;
public
ProxyEndPoint
LocalEndPoint
{
get
;
}
public
bool
IsTransparent
=>
LocalEndPoint
is
TransparentProxyEndPoint
;
/// <summary>
/// <summary>
/// Constructor to initialize the proxy
/// Constructor to initialize the proxy
...
...
Titanium.Web.Proxy/Helpers/HttpResponseWriter.cs
View file @
989b6cad
...
@@ -20,7 +20,6 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -20,7 +20,6 @@ namespace Titanium.Web.Proxy.Helpers
public
async
Task
WriteResponseAsync
(
Response
response
,
bool
flush
=
true
)
public
async
Task
WriteResponseAsync
(
Response
response
,
bool
flush
=
true
)
{
{
await
WriteResponseStatusAsync
(
response
.
HttpVersion
,
response
.
StatusCode
,
response
.
StatusDescription
);
await
WriteResponseStatusAsync
(
response
.
HttpVersion
,
response
.
StatusCode
,
response
.
StatusDescription
);
response
.
Headers
.
FixProxyHeaders
();
await
WriteHeadersAsync
(
response
.
Headers
,
flush
);
await
WriteHeadersAsync
(
response
.
Headers
,
flush
);
}
}
...
...
Titanium.Web.Proxy/Http/HttpWebClient.cs
View file @
989b6cad
...
@@ -79,7 +79,7 @@ namespace Titanium.Web.Proxy.Http
...
@@ -79,7 +79,7 @@ namespace Titanium.Web.Proxy.Http
/// Prepare and send the http(s) request
/// Prepare and send the http(s) request
/// </summary>
/// </summary>
/// <returns></returns>
/// <returns></returns>
internal
async
Task
SendRequest
(
bool
enable100ContinueBehaviour
)
internal
async
Task
SendRequest
(
bool
enable100ContinueBehaviour
,
bool
isTransparent
)
{
{
var
upstreamProxy
=
ServerConnection
.
UpStreamProxy
;
var
upstreamProxy
=
ServerConnection
.
UpStreamProxy
;
...
@@ -89,12 +89,12 @@ namespace Titanium.Web.Proxy.Http
...
@@ -89,12 +89,12 @@ namespace Titanium.Web.Proxy.Http
//prepare the request & headers
//prepare the request & headers
await
writer
.
WriteLineAsync
(
Request
.
CreateRequestLine
(
Request
.
Method
,
await
writer
.
WriteLineAsync
(
Request
.
CreateRequestLine
(
Request
.
Method
,
useUpstreamProxy
?
Request
.
OriginalUrl
:
Request
.
RequestUri
.
PathAndQuery
,
useUpstreamProxy
||
isTransparent
?
Request
.
OriginalUrl
:
Request
.
RequestUri
.
PathAndQuery
,
Request
.
HttpVersion
));
Request
.
HttpVersion
));
//Send Authentication to Upstream proxy if needed
//Send Authentication to Upstream proxy if needed
if
(
upstreamProxy
!=
null
if
(
!
isTransparent
&&
upstreamProxy
!=
null
&&
ServerConnection
.
IsHttps
==
false
&&
ServerConnection
.
IsHttps
==
false
&&
!
string
.
IsNullOrEmpty
(
upstreamProxy
.
UserName
)
&&
!
string
.
IsNullOrEmpty
(
upstreamProxy
.
UserName
)
&&
upstreamProxy
.
Password
!=
null
)
&&
upstreamProxy
.
Password
!=
null
)
...
@@ -106,7 +106,7 @@ namespace Titanium.Web.Proxy.Http
...
@@ -106,7 +106,7 @@ namespace Titanium.Web.Proxy.Http
//write request headers
//write request headers
foreach
(
var
header
in
Request
.
Headers
)
foreach
(
var
header
in
Request
.
Headers
)
{
{
if
(
header
.
Name
!=
KnownHeaders
.
ProxyAuthorization
)
if
(
isTransparent
||
header
.
Name
!=
KnownHeaders
.
ProxyAuthorization
)
{
{
await
header
.
WriteToStreamAsync
(
writer
);
await
header
.
WriteToStreamAsync
(
writer
);
}
}
...
...
Titanium.Web.Proxy/ProxyAuthorizationHandler.cs
View file @
989b6cad
...
@@ -76,6 +76,7 @@ namespace Titanium.Web.Proxy
...
@@ -76,6 +76,7 @@ namespace Titanium.Web.Proxy
response
.
Headers
.
AddHeader
(
KnownHeaders
.
ProxyAuthenticate
,
$"Basic realm=\"
{
ProxyRealm
}
\""
);
response
.
Headers
.
AddHeader
(
KnownHeaders
.
ProxyAuthenticate
,
$"Basic realm=\"
{
ProxyRealm
}
\""
);
response
.
Headers
.
AddHeader
(
KnownHeaders
.
ProxyConnection
,
KnownHeaders
.
ProxyConnectionClose
);
response
.
Headers
.
AddHeader
(
KnownHeaders
.
ProxyConnection
,
KnownHeaders
.
ProxyConnectionClose
);
response
.
Headers
.
FixProxyHeaders
();
await
clientStreamWriter
.
WriteResponseAsync
(
response
);
await
clientStreamWriter
.
WriteResponseAsync
(
response
);
return
response
;
return
response
;
}
}
...
...
Titanium.Web.Proxy/RequestHandler.cs
View file @
989b6cad
...
@@ -106,8 +106,11 @@ namespace Titanium.Web.Proxy
...
@@ -106,8 +106,11 @@ namespace Titanium.Web.Proxy
}
}
//write back successfull CONNECT response
//write back successfull CONNECT response
connectArgs
.
WebSession
.
Response
=
ConnectResponse
.
CreateSuccessfullConnectResponse
(
version
);
var
response
=
ConnectResponse
.
CreateSuccessfullConnectResponse
(
version
);
await
clientStreamWriter
.
WriteResponseAsync
(
connectArgs
.
WebSession
.
Response
);
response
.
Headers
.
FixProxyHeaders
();
connectArgs
.
WebSession
.
Response
=
response
;
await
clientStreamWriter
.
WriteResponseAsync
(
response
);
var
clientHelloInfo
=
await
SslTools
.
PeekClientHello
(
clientStream
);
var
clientHelloInfo
=
await
SslTools
.
PeekClientHello
(
clientStream
);
bool
isClientHello
=
clientHelloInfo
!=
null
;
bool
isClientHello
=
clientHelloInfo
!=
null
;
...
@@ -401,14 +404,14 @@ namespace Titanium.Web.Proxy
...
@@ -401,14 +404,14 @@ namespace Titanium.Web.Proxy
args
.
ProxyClient
.
ClientStreamWriter
=
clientStreamWriter
;
args
.
ProxyClient
.
ClientStreamWriter
=
clientStreamWriter
;
//proxy authorization check
//proxy authorization check
if
(
httpsConnectHostname
==
null
&&
await
CheckAuthorization
(
clientStreamWriter
,
args
)
==
false
)
if
(
!
args
.
IsTransparent
&&
httpsConnectHostname
==
null
&&
await
CheckAuthorization
(
clientStreamWriter
,
args
)
==
false
)
{
{
break
;
break
;
}
}
PrepareRequestHeaders
(
args
.
WebSession
.
Request
.
Headers
);
if
(!
isTransparentEndPoint
)
if
(!
isTransparentEndPoint
)
{
{
PrepareRequestHeaders
(
args
.
WebSession
.
Request
.
Headers
);
args
.
WebSession
.
Request
.
Host
=
args
.
WebSession
.
Request
.
RequestUri
.
Authority
;
args
.
WebSession
.
Request
.
Host
=
args
.
WebSession
.
Request
.
RequestUri
.
Authority
;
}
}
...
@@ -447,6 +450,8 @@ namespace Titanium.Web.Proxy
...
@@ -447,6 +450,8 @@ namespace Titanium.Web.Proxy
connection
=
await
GetServerConnection
(
args
,
false
);
connection
=
await
GetServerConnection
(
args
,
false
);
}
}
var
response
=
args
.
WebSession
.
Response
;
//if upgrading to websocket then relay the requet without reading the contents
//if upgrading to websocket then relay the requet without reading the contents
if
(
args
.
WebSession
.
Request
.
UpgradeToWebSocket
)
if
(
args
.
WebSession
.
Request
.
UpgradeToWebSocket
)
{
{
...
@@ -457,13 +462,16 @@ namespace Titanium.Web.Proxy
...
@@ -457,13 +462,16 @@ namespace Titanium.Web.Proxy
string
httpStatus
=
await
connection
.
StreamReader
.
ReadLineAsync
();
string
httpStatus
=
await
connection
.
StreamReader
.
ReadLineAsync
();
Response
.
ParseResponseLine
(
httpStatus
,
out
var
responseVersion
,
out
int
responseStatusCode
,
out
string
responseStatusDescription
);
Response
.
ParseResponseLine
(
httpStatus
,
out
var
responseVersion
,
out
int
responseStatusCode
,
out
string
responseStatusDescription
);
args
.
WebSession
.
R
esponse
.
HttpVersion
=
responseVersion
;
r
esponse
.
HttpVersion
=
responseVersion
;
args
.
WebSession
.
R
esponse
.
StatusCode
=
responseStatusCode
;
r
esponse
.
StatusCode
=
responseStatusCode
;
args
.
WebSession
.
R
esponse
.
StatusDescription
=
responseStatusDescription
;
r
esponse
.
StatusDescription
=
responseStatusDescription
;
await
HeaderParser
.
ReadHeaders
(
connection
.
StreamReader
,
args
.
WebSession
.
R
esponse
.
Headers
);
await
HeaderParser
.
ReadHeaders
(
connection
.
StreamReader
,
r
esponse
.
Headers
);
await
clientStreamWriter
.
WriteResponseAsync
(
args
.
WebSession
.
Response
);
if
(!
args
.
IsTransparent
)
{
await
clientStreamWriter
.
WriteResponseAsync
(
response
);
}
//If user requested call back then do it
//If user requested call back then do it
if
(
BeforeResponse
!=
null
&&
!
args
.
WebSession
.
Response
.
ResponseLocked
)
if
(
BeforeResponse
!=
null
&&
!
args
.
WebSession
.
Response
.
ResponseLocked
)
...
@@ -483,7 +491,7 @@ namespace Titanium.Web.Proxy
...
@@ -483,7 +491,7 @@ namespace Titanium.Web.Proxy
await
HandleHttpSessionRequestInternal
(
connection
,
args
);
await
HandleHttpSessionRequestInternal
(
connection
,
args
);
//if connection is closing exit
//if connection is closing exit
if
(
args
.
WebSession
.
R
esponse
.
KeepAlive
==
false
)
if
(
r
esponse
.
KeepAlive
==
false
)
{
{
break
;
break
;
}
}
...
@@ -522,7 +530,7 @@ namespace Titanium.Web.Proxy
...
@@ -522,7 +530,7 @@ namespace Titanium.Web.Proxy
if
(
request
.
ExpectContinue
)
if
(
request
.
ExpectContinue
)
{
{
args
.
WebSession
.
SetConnection
(
connection
);
args
.
WebSession
.
SetConnection
(
connection
);
await
args
.
WebSession
.
SendRequest
(
Enable100ContinueBehaviour
);
await
args
.
WebSession
.
SendRequest
(
Enable100ContinueBehaviour
,
args
.
IsTransparent
);
}
}
//If 100 continue was the response inform that to the client
//If 100 continue was the response inform that to the client
...
@@ -546,7 +554,7 @@ namespace Titanium.Web.Proxy
...
@@ -546,7 +554,7 @@ namespace Titanium.Web.Proxy
if
(!
request
.
ExpectContinue
)
if
(!
request
.
ExpectContinue
)
{
{
args
.
WebSession
.
SetConnection
(
connection
);
args
.
WebSession
.
SetConnection
(
connection
);
await
args
.
WebSession
.
SendRequest
(
Enable100ContinueBehaviour
);
await
args
.
WebSession
.
SendRequest
(
Enable100ContinueBehaviour
,
args
.
IsTransparent
);
}
}
//check if content-length is > 0
//check if content-length is > 0
...
...
Titanium.Web.Proxy/ResponseHandler.cs
View file @
989b6cad
...
@@ -70,7 +70,11 @@ namespace Titanium.Web.Proxy
...
@@ -70,7 +70,11 @@ namespace Titanium.Web.Proxy
//Write back response status to client
//Write back response status to client
await
clientStreamWriter
.
WriteResponseStatusAsync
(
response
.
HttpVersion
,
response
.
StatusCode
,
response
.
StatusDescription
);
await
clientStreamWriter
.
WriteResponseStatusAsync
(
response
.
HttpVersion
,
response
.
StatusCode
,
response
.
StatusDescription
);
if
(!
args
.
IsTransparent
)
{
response
.
Headers
.
FixProxyHeaders
();
response
.
Headers
.
FixProxyHeaders
();
}
if
(
response
.
IsBodyRead
)
if
(
response
.
IsBodyRead
)
{
{
bool
isChunked
=
response
.
IsChunked
;
bool
isChunked
=
response
.
IsChunked
;
...
...
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