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
15fd8948
Commit
15fd8948
authored
Jul 15, 2016
by
justcoding121
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update comments
parent
49b75027
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
16 deletions
+12
-16
HttpWebClient.cs
Titanium.Web.Proxy/Http/HttpWebClient.cs
+4
-0
RequestHandler.cs
Titanium.Web.Proxy/RequestHandler.cs
+8
-16
No files found.
Titanium.Web.Proxy/Http/HttpWebClient.cs
View file @
15fd8948
...
@@ -170,6 +170,7 @@ namespace Titanium.Web.Proxy.Http
...
@@ -170,6 +170,7 @@ namespace Titanium.Web.Proxy.Http
}
}
//Read the Response headers
//Read the Response headers
//Read the response headers in to unique and non-unique header collections
string
tmpLine
;
string
tmpLine
;
while
(!
string
.
IsNullOrEmpty
(
tmpLine
=
await
ServerConnection
.
StreamReader
.
ReadLineAsync
()))
while
(!
string
.
IsNullOrEmpty
(
tmpLine
=
await
ServerConnection
.
StreamReader
.
ReadLineAsync
()))
{
{
...
@@ -177,10 +178,12 @@ namespace Titanium.Web.Proxy.Http
...
@@ -177,10 +178,12 @@ namespace Titanium.Web.Proxy.Http
var
newHeader
=
new
HttpHeader
(
header
[
0
],
header
[
1
]);
var
newHeader
=
new
HttpHeader
(
header
[
0
],
header
[
1
]);
//if header exist in non-unique header collection add it there
if
(
Response
.
NonUniqueResponseHeaders
.
ContainsKey
(
newHeader
.
Name
))
if
(
Response
.
NonUniqueResponseHeaders
.
ContainsKey
(
newHeader
.
Name
))
{
{
Response
.
NonUniqueResponseHeaders
[
newHeader
.
Name
].
Add
(
newHeader
);
Response
.
NonUniqueResponseHeaders
[
newHeader
.
Name
].
Add
(
newHeader
);
}
}
//if header is alread in unique header collection then move both to non-unique collection
else
if
(
Response
.
ResponseHeaders
.
ContainsKey
(
newHeader
.
Name
))
else
if
(
Response
.
ResponseHeaders
.
ContainsKey
(
newHeader
.
Name
))
{
{
var
existing
=
Response
.
ResponseHeaders
[
newHeader
.
Name
];
var
existing
=
Response
.
ResponseHeaders
[
newHeader
.
Name
];
...
@@ -193,6 +196,7 @@ namespace Titanium.Web.Proxy.Http
...
@@ -193,6 +196,7 @@ namespace Titanium.Web.Proxy.Http
Response
.
NonUniqueResponseHeaders
.
Add
(
newHeader
.
Name
,
nonUniqueHeaders
);
Response
.
NonUniqueResponseHeaders
.
Add
(
newHeader
.
Name
,
nonUniqueHeaders
);
Response
.
ResponseHeaders
.
Remove
(
newHeader
.
Name
);
Response
.
ResponseHeaders
.
Remove
(
newHeader
.
Name
);
}
}
//add to unique header collection
else
else
{
{
Response
.
ResponseHeaders
.
Add
(
newHeader
.
Name
,
newHeader
);
Response
.
ResponseHeaders
.
Add
(
newHeader
.
Name
,
newHeader
);
...
...
Titanium.Web.Proxy/RequestHandler.cs
View file @
15fd8948
...
@@ -19,11 +19,12 @@ using Titanium.Web.Proxy.Extensions;
...
@@ -19,11 +19,12 @@ using Titanium.Web.Proxy.Extensions;
namespace
Titanium.Web.Proxy
namespace
Titanium.Web.Proxy
{
{
/// <summary>
/// <summary>
/// Handle the reques
r
/// Handle the reques
t
/// </summary>
/// </summary>
partial
class
ProxyServer
partial
class
ProxyServer
{
{
//This is called when client is aware of proxy
//This is called when client is aware of proxy
//So for HTTPS requests client would send CONNECT header to negotiate a secure tcp tunnel via proxy
private
async
void
HandleClient
(
ExplicitProxyEndPoint
endPoint
,
TcpClient
client
)
private
async
void
HandleClient
(
ExplicitProxyEndPoint
endPoint
,
TcpClient
client
)
{
{
Stream
clientStream
=
client
.
GetStream
();
Stream
clientStream
=
client
.
GetStream
();
...
@@ -142,8 +143,8 @@ namespace Titanium.Web.Proxy
...
@@ -142,8 +143,8 @@ namespace Titanium.Web.Proxy
}
}
}
}
//This is called when
requests are routed through router to this endpoint
//This is called when
this proxy acts as a reverse proxy (like a real http server)
//
For ssl requests
//
So for HTTPS requests we would start SSL negotiation right away without expecting a CONNECT request from client
private
async
void
HandleClient
(
TransparentProxyEndPoint
endPoint
,
TcpClient
tcpClient
)
private
async
void
HandleClient
(
TransparentProxyEndPoint
endPoint
,
TcpClient
tcpClient
)
{
{
Stream
clientStream
=
tcpClient
.
GetStream
();
Stream
clientStream
=
tcpClient
.
GetStream
();
...
@@ -244,17 +245,7 @@ namespace Titanium.Web.Proxy
...
@@ -244,17 +245,7 @@ namespace Titanium.Web.Proxy
}
}
}
}
#if DEBUG
//Read the request headers in to unique and non-unique header collections
//Just ignore local requests while Debugging
//Its annoying
if
(
httpCmd
.
Contains
(
"localhost"
))
{
Dispose
(
client
,
clientStream
,
clientStreamReader
,
clientStreamWriter
,
null
);
break
;
}
#endif
//Read the request headers
string
tmpLine
;
string
tmpLine
;
while
(!
string
.
IsNullOrEmpty
(
tmpLine
=
await
clientStreamReader
.
ReadLineAsync
()))
while
(!
string
.
IsNullOrEmpty
(
tmpLine
=
await
clientStreamReader
.
ReadLineAsync
()))
{
{
...
@@ -262,10 +253,12 @@ namespace Titanium.Web.Proxy
...
@@ -262,10 +253,12 @@ namespace Titanium.Web.Proxy
var
newHeader
=
new
HttpHeader
(
header
[
0
],
header
[
1
]);
var
newHeader
=
new
HttpHeader
(
header
[
0
],
header
[
1
]);
//if header exist in non-unique header collection add it there
if
(
args
.
WebSession
.
Request
.
NonUniqueRequestHeaders
.
ContainsKey
(
newHeader
.
Name
))
if
(
args
.
WebSession
.
Request
.
NonUniqueRequestHeaders
.
ContainsKey
(
newHeader
.
Name
))
{
{
args
.
WebSession
.
Request
.
NonUniqueRequestHeaders
[
newHeader
.
Name
].
Add
(
newHeader
);
args
.
WebSession
.
Request
.
NonUniqueRequestHeaders
[
newHeader
.
Name
].
Add
(
newHeader
);
}
}
//if header is alread in unique header collection then move both to non-unique collection
else
if
(
args
.
WebSession
.
Request
.
RequestHeaders
.
ContainsKey
(
newHeader
.
Name
))
else
if
(
args
.
WebSession
.
Request
.
RequestHeaders
.
ContainsKey
(
newHeader
.
Name
))
{
{
var
existing
=
args
.
WebSession
.
Request
.
RequestHeaders
[
newHeader
.
Name
];
var
existing
=
args
.
WebSession
.
Request
.
RequestHeaders
[
newHeader
.
Name
];
...
@@ -278,6 +271,7 @@ namespace Titanium.Web.Proxy
...
@@ -278,6 +271,7 @@ namespace Titanium.Web.Proxy
args
.
WebSession
.
Request
.
NonUniqueRequestHeaders
.
Add
(
newHeader
.
Name
,
nonUniqueHeaders
);
args
.
WebSession
.
Request
.
NonUniqueRequestHeaders
.
Add
(
newHeader
.
Name
,
nonUniqueHeaders
);
args
.
WebSession
.
Request
.
RequestHeaders
.
Remove
(
newHeader
.
Name
);
args
.
WebSession
.
Request
.
RequestHeaders
.
Remove
(
newHeader
.
Name
);
}
}
//add to unique header collection
else
else
{
{
args
.
WebSession
.
Request
.
RequestHeaders
.
Add
(
newHeader
.
Name
,
newHeader
);
args
.
WebSession
.
Request
.
RequestHeaders
.
Add
(
newHeader
.
Name
,
newHeader
);
...
@@ -406,8 +400,6 @@ namespace Titanium.Web.Proxy
...
@@ -406,8 +400,6 @@ namespace Titanium.Web.Proxy
break
;
break
;
}
}
// read the next request
// read the next request
httpCmd
=
await
clientStreamReader
.
ReadLineAsync
();
httpCmd
=
await
clientStreamReader
.
ReadLineAsync
();
...
...
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