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
88d643e8
Commit
88d643e8
authored
Sep 04, 2015
by
titanium007
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve code brevity
parent
a9898583
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
128 deletions
+35
-128
Titanium.Web.Proxy.sln
Titanium.Web.Proxy.sln
+0
-3
RequestHandler.cs
Titanium.Web.Proxy/RequestHandler.cs
+34
-111
ResponseHandler.cs
Titanium.Web.Proxy/ResponseHandler.cs
+1
-14
No files found.
Titanium.Web.Proxy.sln
View file @
88d643e8
...
...
@@ -56,7 +56,4 @@ Global
GlobalSection(ExtensibilityGlobals) = postSolution
EnterpriseLibraryConfigurationToolBinariesPath = .1.505.2\lib\NET35
EndGlobalSection
GlobalSection(Performance) = preSolution
HasPerformanceSessions = true
EndGlobalSection
EndGlobal
Titanium.Web.Proxy/RequestHandler.cs
View file @
88d643e8
...
...
@@ -99,17 +99,7 @@ namespace Titanium.Web.Proxy
{
TcpHelper
.
SendRaw
(
tunnelHostName
,
tunnelPort
,
clientStreamReader
.
BaseStream
);
if
(
clientStreamReader
!=
null
)
clientStreamReader
.
Dispose
();
if
(
clientStreamWriter
!=
null
)
clientStreamWriter
.
Dispose
();
if
(
clientStream
!=
null
)
clientStream
.
Dispose
();
if
(
client
!=
null
)
client
.
Close
();
Dispose
(
client
,
clientStream
,
clientStreamReader
,
clientStreamWriter
,
null
);
return
;
}
...
...
@@ -159,17 +149,7 @@ namespace Titanium.Web.Proxy
//Hostname was a previously failed request due to certificate pinning, just relay (tunnel the request)
TcpHelper
.
SendRaw
(
tunnelHostName
,
tunnelPort
,
clientStreamReader
.
BaseStream
);
if
(
clientStreamReader
!=
null
)
clientStreamReader
.
Dispose
();
if
(
clientStreamWriter
!=
null
)
clientStreamWriter
.
Dispose
();
if
(
clientStream
!=
null
)
clientStream
.
Dispose
();
if
(
client
!=
null
)
client
.
Close
();
Dispose
(
client
,
clientStream
,
clientStreamReader
,
clientStreamWriter
,
null
);
return
;
}
...
...
@@ -198,17 +178,7 @@ namespace Titanium.Web.Proxy
}
catch
{
if
(
clientStreamReader
!=
null
)
clientStreamReader
.
Dispose
();
if
(
clientStreamWriter
!=
null
)
clientStreamWriter
.
Dispose
();
if
(
clientStream
!=
null
)
clientStream
.
Dispose
();
if
(
client
!=
null
)
client
.
Close
();
Dispose
(
client
,
clientStream
,
clientStreamReader
,
clientStreamWriter
,
null
);
}
...
...
@@ -219,17 +189,7 @@ namespace Titanium.Web.Proxy
if
(
httpCmd
==
null
)
{
if
(
clientStreamReader
!=
null
)
clientStreamReader
.
Dispose
();
if
(
clientStreamWriter
!=
null
)
clientStreamWriter
.
Dispose
();
if
(
clientStream
!=
null
)
clientStream
.
Dispose
();
if
(
client
!=
null
)
client
.
Close
();
Dispose
(
client
,
clientStream
,
clientStreamReader
,
clientStreamWriter
,
null
);
return
;
}
...
...
@@ -249,20 +209,7 @@ namespace Titanium.Web.Proxy
{
TcpHelper
.
SendRaw
(
httpCmd
,
tunnelHostName
,
requestLines
,
args
.
IsSSLRequest
,
clientStreamReader
.
BaseStream
);
if
(
args
!=
null
)
args
.
Dispose
();
if
(
clientStreamReader
!=
null
)
clientStreamReader
.
Dispose
();
if
(
clientStreamWriter
!=
null
)
clientStreamWriter
.
Dispose
();
if
(
clientStream
!=
null
)
clientStream
.
Dispose
();
if
(
client
!=
null
)
client
.
Close
();
Dispose
(
client
,
clientStream
,
clientStreamReader
,
clientStreamWriter
,
args
);
return
;
}
...
...
@@ -305,20 +252,7 @@ namespace Titanium.Web.Proxy
TcpHelper
.
SendRaw
(
httpCmd
,
tunnelHostName
,
requestLines
,
args
.
IsSSLRequest
,
clientStreamReader
.
BaseStream
);
if
(
args
!=
null
)
args
.
Dispose
();
if
(
clientStreamReader
!=
null
)
clientStreamReader
.
Dispose
();
if
(
clientStreamWriter
!=
null
)
clientStreamWriter
.
Dispose
();
if
(
clientStream
!=
null
)
clientStream
.
Dispose
();
if
(
client
!=
null
)
client
.
Close
();
Dispose
(
client
,
clientStream
,
clientStreamReader
,
clientStreamWriter
,
args
);
return
;
}
...
...
@@ -351,20 +285,7 @@ namespace Titanium.Web.Proxy
string
tmpLine
;
if
(
args
.
CancelRequest
)
{
if
(
args
!=
null
)
args
.
Dispose
();
if
(
clientStreamReader
!=
null
)
clientStreamReader
.
Dispose
();
if
(
clientStreamWriter
!=
null
)
clientStreamWriter
.
Dispose
();
if
(
clientStream
!=
null
)
clientStream
.
Dispose
();
if
(
client
!=
null
)
client
.
Close
();
Dispose
(
client
,
clientStream
,
clientStreamReader
,
clientStreamWriter
,
args
);
return
;
}
...
...
@@ -390,16 +311,10 @@ namespace Titanium.Web.Proxy
{
SendClientRequestBody
(
args
);
//Http request body sent, now wait asynchronously for response
args
.
ProxyRequest
.
BeginGetResponse
(
new
AsyncCallback
(
HandleHttpSessionResponse
),
args
);
}
else
{
//otherwise wait for response asynchronously
//Http request body sent, now wait asynchronously for response
args
.
ProxyRequest
.
BeginGetResponse
(
new
AsyncCallback
(
HandleHttpSessionResponse
),
args
);
}
}
...
...
@@ -420,6 +335,13 @@ namespace Titanium.Web.Proxy
}
catch
{
Dispose
(
client
,
clientStream
,
clientStreamReader
,
clientStreamWriter
,
args
);
}
}
private
static
void
Dispose
(
TcpClient
client
,
Stream
clientStream
,
CustomBinaryReader
clientStreamReader
,
StreamWriter
clientStreamWriter
,
SessionEventArgs
args
)
{
if
(
args
!=
null
)
args
.
Dispose
();
...
...
@@ -435,11 +357,6 @@ namespace Titanium.Web.Proxy
if
(
client
!=
null
)
client
.
Close
();
}
}
private
static
void
SetClientRequestHeaders
(
List
<
string
>
requestLines
,
HttpWebRequest
webRequest
)
{
...
...
@@ -508,6 +425,7 @@ namespace Titanium.Web.Proxy
case
"user-agent"
:
webRequest
.
UserAgent
=
header
[
1
];
break
;
//revisit this, transfer-encoding is not a request header according to spec
//But how to identify if client is sending chunked body for PUT/POST?
case
"transfer-encoding"
:
...
...
@@ -537,7 +455,6 @@ namespace Titanium.Web.Proxy
private
static
void
SendClientRequestBody
(
SessionEventArgs
args
)
{
// End the operation
Stream
postStream
=
args
.
ProxyRequest
.
GetRequestStream
();
...
...
@@ -574,12 +491,15 @@ namespace Titanium.Web.Proxy
}
postStream
.
Close
();
postStream
.
Dispose
();
}
catch
{
if
(
postStream
!=
null
)
{
postStream
.
Close
();
postStream
.
Dispose
();
}
throw
;
}
...
...
@@ -649,7 +569,10 @@ namespace Titanium.Web.Proxy
catch
{
if
(
postStream
!=
null
)
{
postStream
.
Close
();
postStream
.
Dispose
();
}
throw
;
}
...
...
Titanium.Web.Proxy/ResponseHandler.cs
View file @
88d643e8
...
...
@@ -97,24 +97,11 @@ namespace Titanium.Web.Proxy
}
}
catch
{
if
(
args
.
ClientStreamReader
!=
null
)
args
.
ClientStreamReader
.
Dispose
();
if
(
args
.
ClientStreamWriter
!=
null
)
args
.
ClientStreamWriter
.
Dispose
();
if
(
args
.
ClientStream
!=
null
)
args
.
ClientStream
.
Dispose
();
if
(
args
.
Client
!=
null
)
args
.
Client
.
Close
();
Dispose
(
args
.
Client
,
args
.
ClientStream
,
args
.
ClientStreamReader
,
args
.
ClientStreamWriter
,
args
);
}
finally
{
if
(
args
!=
null
)
...
...
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