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
56270351
Commit
56270351
authored
Jun 17, 2016
by
titanium007
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update comments
parent
3042d211
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
29 deletions
+26
-29
HttpWebClient.cs
Titanium.Web.Proxy/Http/HttpWebClient.cs
+4
-0
RequestHandler.cs
Titanium.Web.Proxy/RequestHandler.cs
+14
-26
ResponseHandler.cs
Titanium.Web.Proxy/ResponseHandler.cs
+8
-3
No files found.
Titanium.Web.Proxy/Http/HttpWebClient.cs
View file @
56270351
...
...
@@ -133,18 +133,22 @@ namespace Titanium.Web.Proxy.Http
if
(
this
.
Response
.
ResponseStatusCode
.
Equals
(
"100"
)
&&
this
.
Response
.
ResponseStatusDescription
.
ToLower
().
Equals
(
"continue"
))
{
//Read the next line after 100-continue
this
.
Response
.
Is100Continue
=
true
;
this
.
Response
.
ResponseStatusCode
=
null
;
await
ServerConnection
.
StreamReader
.
ReadLineAsync
();
//now receive response
await
ReceiveResponse
();
return
;
}
else
if
(
this
.
Response
.
ResponseStatusCode
.
Equals
(
"417"
)
&&
this
.
Response
.
ResponseStatusDescription
.
ToLower
().
Equals
(
"expectation failed"
))
{
//read next line after expectation failed response
this
.
Response
.
ExpectationFailed
=
true
;
this
.
Response
.
ResponseStatusCode
=
null
;
await
ServerConnection
.
StreamReader
.
ReadLineAsync
();
//now receive response
await
ReceiveResponse
();
return
;
}
...
...
Titanium.Web.Proxy/RequestHandler.cs
View file @
56270351
...
...
@@ -64,8 +64,8 @@ namespace Titanium.Web.Proxy
version
=
new
Version
(
1
,
0
);
}
}
var
excluded
=
endPoint
.
ExcludedHttpsHostNameRegex
!=
null
?
//filter out excluded host names
var
excluded
=
endPoint
.
ExcludedHttpsHostNameRegex
!=
null
?
endPoint
.
ExcludedHttpsHostNameRegex
.
Any
(
x
=>
Regex
.
IsMatch
(
httpRemoteUri
.
Host
,
x
))
:
false
;
//Client wants to create a secure tcp tunnel (its a HTTPS request)
...
...
@@ -82,8 +82,8 @@ namespace Titanium.Web.Proxy
{
//create the Tcp Connection to server and then release it to connection cache
//Just doing what CONNECT request is asking as to do
var
tunnelClient
=
await
TcpConnectionManager
.
GetClient
(
httpRemoteUri
.
Host
,
httpRemoteUri
.
Port
,
true
,
version
);
await
TcpConnectionManager
.
ReleaseClient
(
tunnelClient
);
var
tunnelClient
=
await
TcpConnectionManager
.
GetClient
(
httpRemoteUri
.
Host
,
httpRemoteUri
.
Port
,
true
,
version
);
await
TcpConnectionManager
.
ReleaseClient
(
tunnelClient
);
sslStream
=
new
SslStream
(
clientStream
,
true
);
var
certificate
=
await
CertManager
.
CreateCertificate
(
httpRemoteUri
.
Host
,
false
);
...
...
@@ -148,12 +148,8 @@ namespace Titanium.Web.Proxy
if
(
endPoint
.
EnableSsl
)
{
var
sslStream
=
new
SslStream
(
clientStream
,
true
);
//if(endPoint.UseServerNameIndication)
//{
// //implement in future once SNI supported by SSL stream
// certificate = CertManager.CreateCertificate(hostName);
//}
//else
//implement in future once SNI supported by SSL stream, for now use the same certificate
certificate
=
await
CertManager
.
CreateCertificate
(
endPoint
.
GenericCertificateName
,
false
);
try
...
...
@@ -182,6 +178,7 @@ namespace Titanium.Web.Proxy
clientStreamReader
=
new
CustomBinaryReader
(
clientStream
);
}
//now read the request line
var
httpCmd
=
await
clientStreamReader
.
ReadLineAsync
();
//Now create the request
...
...
@@ -411,6 +408,7 @@ namespace Titanium.Web.Proxy
{
switch
(
requestHeaders
[
i
].
Name
.
ToLower
())
{
//these are the only encoding this proxy can read
case
"accept-encoding"
:
requestHeaders
[
i
].
Value
=
"gzip,deflate,zlib"
;
break
;
...
...
@@ -457,28 +455,18 @@ namespace Titanium.Web.Proxy
// End the operation
var
postStream
=
args
.
WebSession
.
ServerConnection
.
Stream
;
//send the request body bytes to server
if
(
args
.
WebSession
.
Request
.
ContentLength
>
0
)
{
try
{
await
args
.
ProxyClient
.
ClientStreamReader
.
CopyBytesToStream
(
postStream
,
args
.
WebSession
.
Request
.
ContentLength
);
}
catch
{
throw
;
}
await
args
.
ProxyClient
.
ClientStreamReader
.
CopyBytesToStream
(
postStream
,
args
.
WebSession
.
Request
.
ContentLength
);
}
//Need to revist, find any potential bugs
//send the request body bytes to server in chunks
else
if
(
args
.
WebSession
.
Request
.
IsChunked
)
{
try
{
await
args
.
ProxyClient
.
ClientStreamReader
.
CopyBytesToStreamChunked
(
postStream
);
}
catch
{
throw
;
}
await
args
.
ProxyClient
.
ClientStreamReader
.
CopyBytesToStreamChunked
(
postStream
);
}
}
...
...
Titanium.Web.Proxy/ResponseHandler.cs
View file @
56270351
...
...
@@ -83,8 +83,13 @@ namespace Titanium.Web.Proxy
{
await
WriteResponseHeaders
(
args
.
ProxyClient
.
ClientStreamWriter
,
args
.
WebSession
.
Response
.
ResponseHeaders
);
if
(
args
.
WebSession
.
Response
.
IsChunked
||
args
.
WebSession
.
Response
.
ContentLength
>
0
||
(
args
.
WebSession
.
Response
.
HttpVersion
.
Major
==
1
&&
args
.
WebSession
.
Response
.
HttpVersion
.
Minor
==
0
))
//Write body only if response is chunked or content length >0
//Is none are true then check if connection:close header exist, if so write response until server or client terminates the connection
if
(
args
.
WebSession
.
Response
.
IsChunked
||
args
.
WebSession
.
Response
.
ContentLength
>
0
||
!
args
.
WebSession
.
Response
.
ResponseKeepAlive
)
await
args
.
WebSession
.
ServerConnection
.
StreamReader
.
WriteResponseBody
(
args
.
ProxyClient
.
ClientStream
,
args
.
WebSession
.
Response
.
IsChunked
,
args
.
WebSession
.
Response
.
ContentLength
);
//write response if connection:keep-alive header exist and when version is http/1.0
//Because in Http 1.0 server can return a response without content-length (expectation being client would read until end of stream)
else
if
(
args
.
WebSession
.
Response
.
ResponseKeepAlive
&&
args
.
WebSession
.
Response
.
HttpVersion
.
Minor
==
0
)
await
args
.
WebSession
.
ServerConnection
.
StreamReader
.
WriteResponseBody
(
args
.
ProxyClient
.
ClientStream
,
args
.
WebSession
.
Response
.
IsChunked
,
args
.
WebSession
.
Response
.
ContentLength
);
}
...
...
@@ -172,7 +177,7 @@ namespace Titanium.Web.Proxy
headers
.
RemoveAll
(
x
=>
x
.
Name
.
ToLower
()
==
"proxy-connection"
);
}
/// <summary>
/// Handle dispose of a client/server session
/// </summary>
...
...
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