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
4477f6de
Unverified
Commit
4477f6de
authored
Mar 01, 2018
by
honfika
Committed by
GitHub
Mar 01, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #377 from justcoding121/develop
Beta
parents
63ce4b3d
80de6eac
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
40 additions
and
20 deletions
+40
-20
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
+27
-13
ResponseHandler.cs
Titanium.Web.Proxy/ResponseHandler.cs
+5
-1
No files found.
Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs
View file @
4477f6de
...
...
@@ -96,7 +96,9 @@ namespace Titanium.Web.Proxy.EventArguments
/// </summary>
public
event
EventHandler
<
MultipartRequestPartSentEventArgs
>
MultipartRequestPartSent
;
public
ProxyEndPoint
LocalEndPoint
;
public
ProxyEndPoint
LocalEndPoint
{
get
;
}
public
bool
IsTransparent
=>
LocalEndPoint
is
TransparentProxyEndPoint
;
/// <summary>
/// Constructor to initialize the proxy
...
...
Titanium.Web.Proxy/Helpers/HttpResponseWriter.cs
View file @
4477f6de
...
...
@@ -20,7 +20,6 @@ namespace Titanium.Web.Proxy.Helpers
public
async
Task
WriteResponseAsync
(
Response
response
,
bool
flush
=
true
)
{
await
WriteResponseStatusAsync
(
response
.
HttpVersion
,
response
.
StatusCode
,
response
.
StatusDescription
);
response
.
Headers
.
FixProxyHeaders
();
await
WriteHeadersAsync
(
response
.
Headers
,
flush
);
}
...
...
Titanium.Web.Proxy/Http/HttpWebClient.cs
View file @
4477f6de
...
...
@@ -79,7 +79,7 @@ namespace Titanium.Web.Proxy.Http
/// Prepare and send the http(s) request
/// </summary>
/// <returns></returns>
internal
async
Task
SendRequest
(
bool
enable100ContinueBehaviour
)
internal
async
Task
SendRequest
(
bool
enable100ContinueBehaviour
,
bool
isTransparent
)
{
var
upstreamProxy
=
ServerConnection
.
UpStreamProxy
;
...
...
@@ -89,12 +89,12 @@ namespace Titanium.Web.Proxy.Http
//prepare the request & headers
await
writer
.
WriteLineAsync
(
Request
.
CreateRequestLine
(
Request
.
Method
,
useUpstreamProxy
?
Request
.
OriginalUrl
:
Request
.
RequestUri
.
PathAndQuery
,
useUpstreamProxy
||
isTransparent
?
Request
.
OriginalUrl
:
Request
.
RequestUri
.
PathAndQuery
,
Request
.
HttpVersion
));
//Send Authentication to Upstream proxy if needed
if
(
upstreamProxy
!=
null
if
(
!
isTransparent
&&
upstreamProxy
!=
null
&&
ServerConnection
.
IsHttps
==
false
&&
!
string
.
IsNullOrEmpty
(
upstreamProxy
.
UserName
)
&&
upstreamProxy
.
Password
!=
null
)
...
...
@@ -106,7 +106,7 @@ namespace Titanium.Web.Proxy.Http
//write request headers
foreach
(
var
header
in
Request
.
Headers
)
{
if
(
header
.
Name
!=
KnownHeaders
.
ProxyAuthorization
)
if
(
isTransparent
||
header
.
Name
!=
KnownHeaders
.
ProxyAuthorization
)
{
await
header
.
WriteToStreamAsync
(
writer
);
}
...
...
Titanium.Web.Proxy/ProxyAuthorizationHandler.cs
View file @
4477f6de
...
...
@@ -76,6 +76,7 @@ namespace Titanium.Web.Proxy
response
.
Headers
.
AddHeader
(
KnownHeaders
.
ProxyAuthenticate
,
$"Basic realm=\"
{
ProxyRealm
}
\""
);
response
.
Headers
.
AddHeader
(
KnownHeaders
.
ProxyConnection
,
KnownHeaders
.
ProxyConnectionClose
);
response
.
Headers
.
FixProxyHeaders
();
await
clientStreamWriter
.
WriteResponseAsync
(
response
);
return
response
;
}
...
...
Titanium.Web.Proxy/RequestHandler.cs
View file @
4477f6de
...
...
@@ -106,8 +106,11 @@ namespace Titanium.Web.Proxy
}
//write back successfull CONNECT response
connectArgs
.
WebSession
.
Response
=
ConnectResponse
.
CreateSuccessfullConnectResponse
(
version
);
await
clientStreamWriter
.
WriteResponseAsync
(
connectArgs
.
WebSession
.
Response
);
var
response
=
ConnectResponse
.
CreateSuccessfullConnectResponse
(
version
);
response
.
Headers
.
FixProxyHeaders
();
connectArgs
.
WebSession
.
Response
=
response
;
await
clientStreamWriter
.
WriteResponseAsync
(
response
);
var
clientHelloInfo
=
await
SslTools
.
PeekClientHello
(
clientStream
);
bool
isClientHello
=
clientHelloInfo
!=
null
;
...
...
@@ -401,14 +404,14 @@ namespace Titanium.Web.Proxy
args
.
ProxyClient
.
ClientStreamWriter
=
clientStreamWriter
;
//proxy authorization check
if
(
httpsConnectHostname
==
null
&&
await
CheckAuthorization
(
clientStreamWriter
,
args
)
==
false
)
if
(
!
args
.
IsTransparent
&&
httpsConnectHostname
==
null
&&
await
CheckAuthorization
(
clientStreamWriter
,
args
)
==
false
)
{
break
;
}
PrepareRequestHeaders
(
args
.
WebSession
.
Request
.
Headers
);
if
(!
isTransparentEndPoint
)
{
PrepareRequestHeaders
(
args
.
WebSession
.
Request
.
Headers
);
args
.
WebSession
.
Request
.
Host
=
args
.
WebSession
.
Request
.
RequestUri
.
Authority
;
}
...
...
@@ -426,12 +429,20 @@ namespace Titanium.Web.Proxy
await
BeforeRequest
.
InvokeAsync
(
this
,
args
,
ExceptionFunc
);
}
var
response
=
args
.
WebSession
.
Response
;
if
(
args
.
WebSession
.
Request
.
CancelRequest
)
{
await
HandleHttpSessionResponse
(
args
);
if
(!
response
.
KeepAlive
)
{
break
;
}
continue
;
}
//create a new connection if hostname/upstream end point changes
if
(
connection
!=
null
&&
(!
connection
.
HostName
.
Equals
(
args
.
WebSession
.
Request
.
RequestUri
.
Host
,
StringComparison
.
OrdinalIgnoreCase
)
...
...
@@ -457,13 +468,16 @@ namespace Titanium.Web.Proxy
string
httpStatus
=
await
connection
.
StreamReader
.
ReadLineAsync
();
Response
.
ParseResponseLine
(
httpStatus
,
out
var
responseVersion
,
out
int
responseStatusCode
,
out
string
responseStatusDescription
);
args
.
WebSession
.
R
esponse
.
HttpVersion
=
responseVersion
;
args
.
WebSession
.
R
esponse
.
StatusCode
=
responseStatusCode
;
args
.
WebSession
.
R
esponse
.
StatusDescription
=
responseStatusDescription
;
r
esponse
.
HttpVersion
=
responseVersion
;
r
esponse
.
StatusCode
=
responseStatusCode
;
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
(
BeforeResponse
!=
null
&&
!
args
.
WebSession
.
Response
.
ResponseLocked
)
...
...
@@ -483,7 +497,7 @@ namespace Titanium.Web.Proxy
await
HandleHttpSessionRequestInternal
(
connection
,
args
);
//if connection is closing exit
if
(
args
.
WebSession
.
Response
.
KeepAlive
==
fals
e
)
if
(
!
response
.
KeepAliv
e
)
{
break
;
}
...
...
@@ -522,7 +536,7 @@ namespace Titanium.Web.Proxy
if
(
request
.
ExpectContinue
)
{
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
...
...
@@ -546,7 +560,7 @@ namespace Titanium.Web.Proxy
if
(!
request
.
ExpectContinue
)
{
args
.
WebSession
.
SetConnection
(
connection
);
await
args
.
WebSession
.
SendRequest
(
Enable100ContinueBehaviour
);
await
args
.
WebSession
.
SendRequest
(
Enable100ContinueBehaviour
,
args
.
IsTransparent
);
}
//check if content-length is > 0
...
...
Titanium.Web.Proxy/ResponseHandler.cs
View file @
4477f6de
...
...
@@ -70,7 +70,11 @@ namespace Titanium.Web.Proxy
//Write back response status to client
await
clientStreamWriter
.
WriteResponseStatusAsync
(
response
.
HttpVersion
,
response
.
StatusCode
,
response
.
StatusDescription
);
if
(!
args
.
IsTransparent
)
{
response
.
Headers
.
FixProxyHeaders
();
}
if
(
response
.
IsBodyRead
)
{
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