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
9e41d558
Commit
9e41d558
authored
Sep 04, 2015
by
justcoding121
Committed by
justcoding121
Sep 04, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve code brevity
parent
4b302863
Hide 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 @
9e41d558
...
@@ -56,7 +56,4 @@ Global
...
@@ -56,7 +56,4 @@ Global
GlobalSection(ExtensibilityGlobals) = postSolution
GlobalSection(ExtensibilityGlobals) = postSolution
EnterpriseLibraryConfigurationToolBinariesPath = .1.505.2\lib\NET35
EnterpriseLibraryConfigurationToolBinariesPath = .1.505.2\lib\NET35
EndGlobalSection
EndGlobalSection
GlobalSection(Performance) = preSolution
HasPerformanceSessions = true
EndGlobalSection
EndGlobal
EndGlobal
Titanium.Web.Proxy/RequestHandler.cs
View file @
9e41d558
...
@@ -99,17 +99,7 @@ namespace Titanium.Web.Proxy
...
@@ -99,17 +99,7 @@ namespace Titanium.Web.Proxy
{
{
TcpHelper
.
SendRaw
(
tunnelHostName
,
tunnelPort
,
clientStreamReader
.
BaseStream
);
TcpHelper
.
SendRaw
(
tunnelHostName
,
tunnelPort
,
clientStreamReader
.
BaseStream
);
if
(
clientStreamReader
!=
null
)
Dispose
(
client
,
clientStream
,
clientStreamReader
,
clientStreamWriter
,
null
);
clientStreamReader
.
Dispose
();
if
(
clientStreamWriter
!=
null
)
clientStreamWriter
.
Dispose
();
if
(
clientStream
!=
null
)
clientStream
.
Dispose
();
if
(
client
!=
null
)
client
.
Close
();
return
;
return
;
}
}
...
@@ -159,17 +149,7 @@ namespace Titanium.Web.Proxy
...
@@ -159,17 +149,7 @@ namespace Titanium.Web.Proxy
//Hostname was a previously failed request due to certificate pinning, just relay (tunnel the request)
//Hostname was a previously failed request due to certificate pinning, just relay (tunnel the request)
TcpHelper
.
SendRaw
(
tunnelHostName
,
tunnelPort
,
clientStreamReader
.
BaseStream
);
TcpHelper
.
SendRaw
(
tunnelHostName
,
tunnelPort
,
clientStreamReader
.
BaseStream
);
if
(
clientStreamReader
!=
null
)
Dispose
(
client
,
clientStream
,
clientStreamReader
,
clientStreamWriter
,
null
);
clientStreamReader
.
Dispose
();
if
(
clientStreamWriter
!=
null
)
clientStreamWriter
.
Dispose
();
if
(
clientStream
!=
null
)
clientStream
.
Dispose
();
if
(
client
!=
null
)
client
.
Close
();
return
;
return
;
}
}
...
@@ -198,17 +178,7 @@ namespace Titanium.Web.Proxy
...
@@ -198,17 +178,7 @@ namespace Titanium.Web.Proxy
}
}
catch
catch
{
{
if
(
clientStreamReader
!=
null
)
Dispose
(
client
,
clientStream
,
clientStreamReader
,
clientStreamWriter
,
null
);
clientStreamReader
.
Dispose
();
if
(
clientStreamWriter
!=
null
)
clientStreamWriter
.
Dispose
();
if
(
clientStream
!=
null
)
clientStream
.
Dispose
();
if
(
client
!=
null
)
client
.
Close
();
}
}
...
@@ -219,17 +189,7 @@ namespace Titanium.Web.Proxy
...
@@ -219,17 +189,7 @@ namespace Titanium.Web.Proxy
if
(
httpCmd
==
null
)
if
(
httpCmd
==
null
)
{
{
if
(
clientStreamReader
!=
null
)
Dispose
(
client
,
clientStream
,
clientStreamReader
,
clientStreamWriter
,
null
);
clientStreamReader
.
Dispose
();
if
(
clientStreamWriter
!=
null
)
clientStreamWriter
.
Dispose
();
if
(
clientStream
!=
null
)
clientStream
.
Dispose
();
if
(
client
!=
null
)
client
.
Close
();
return
;
return
;
}
}
...
@@ -249,20 +209,7 @@ namespace Titanium.Web.Proxy
...
@@ -249,20 +209,7 @@ namespace Titanium.Web.Proxy
{
{
TcpHelper
.
SendRaw
(
httpCmd
,
tunnelHostName
,
requestLines
,
args
.
IsSSLRequest
,
clientStreamReader
.
BaseStream
);
TcpHelper
.
SendRaw
(
httpCmd
,
tunnelHostName
,
requestLines
,
args
.
IsSSLRequest
,
clientStreamReader
.
BaseStream
);
if
(
args
!=
null
)
Dispose
(
client
,
clientStream
,
clientStreamReader
,
clientStreamWriter
,
args
);
args
.
Dispose
();
if
(
clientStreamReader
!=
null
)
clientStreamReader
.
Dispose
();
if
(
clientStreamWriter
!=
null
)
clientStreamWriter
.
Dispose
();
if
(
clientStream
!=
null
)
clientStream
.
Dispose
();
if
(
client
!=
null
)
client
.
Close
();
return
;
return
;
}
}
...
@@ -305,20 +252,7 @@ namespace Titanium.Web.Proxy
...
@@ -305,20 +252,7 @@ namespace Titanium.Web.Proxy
TcpHelper
.
SendRaw
(
httpCmd
,
tunnelHostName
,
requestLines
,
args
.
IsSSLRequest
,
clientStreamReader
.
BaseStream
);
TcpHelper
.
SendRaw
(
httpCmd
,
tunnelHostName
,
requestLines
,
args
.
IsSSLRequest
,
clientStreamReader
.
BaseStream
);
if
(
args
!=
null
)
Dispose
(
client
,
clientStream
,
clientStreamReader
,
clientStreamWriter
,
args
);
args
.
Dispose
();
if
(
clientStreamReader
!=
null
)
clientStreamReader
.
Dispose
();
if
(
clientStreamWriter
!=
null
)
clientStreamWriter
.
Dispose
();
if
(
clientStream
!=
null
)
clientStream
.
Dispose
();
if
(
client
!=
null
)
client
.
Close
();
return
;
return
;
}
}
...
@@ -351,20 +285,7 @@ namespace Titanium.Web.Proxy
...
@@ -351,20 +285,7 @@ namespace Titanium.Web.Proxy
string
tmpLine
;
string
tmpLine
;
if
(
args
.
CancelRequest
)
if
(
args
.
CancelRequest
)
{
{
if
(
args
!=
null
)
Dispose
(
client
,
clientStream
,
clientStreamReader
,
clientStreamWriter
,
args
);
args
.
Dispose
();
if
(
clientStreamReader
!=
null
)
clientStreamReader
.
Dispose
();
if
(
clientStreamWriter
!=
null
)
clientStreamWriter
.
Dispose
();
if
(
clientStream
!=
null
)
clientStream
.
Dispose
();
if
(
client
!=
null
)
client
.
Close
();
return
;
return
;
}
}
...
@@ -390,17 +311,11 @@ namespace Titanium.Web.Proxy
...
@@ -390,17 +311,11 @@ namespace Titanium.Web.Proxy
{
{
SendClientRequestBody
(
args
);
SendClientRequestBody
(
args
);
//Http request body sent, now wait asynchronously for response
args
.
ProxyRequest
.
BeginGetResponse
(
new
AsyncCallback
(
HandleHttpSessionResponse
),
args
);
}
else
{
//otherwise wait for response asynchronously
args
.
ProxyRequest
.
BeginGetResponse
(
new
AsyncCallback
(
HandleHttpSessionResponse
),
args
);
}
}
//Http request body sent, now wait asynchronously for response
args
.
ProxyRequest
.
BeginGetResponse
(
new
AsyncCallback
(
HandleHttpSessionResponse
),
args
);
}
}
//Now read the next request (if keep-Alive is enabled, otherwise exit this thread)
//Now read the next request (if keep-Alive is enabled, otherwise exit this thread)
...
@@ -421,25 +336,27 @@ namespace Titanium.Web.Proxy
...
@@ -421,25 +336,27 @@ namespace Titanium.Web.Proxy
}
}
catch
catch
{
{
if
(
args
!=
null
)
Dispose
(
client
,
clientStream
,
clientStreamReader
,
clientStreamWriter
,
args
);
args
.
Dispose
();
}
if
(
clientStreamReader
!=
null
)
clientStreamReader
.
Dispose
();
if
(
clientStreamWriter
!=
null
)
clientStreamWriter
.
Dispose
();
if
(
clientStream
!=
null
)
clientStream
.
Dispose
();
if
(
client
!=
null
)
client
.
Close
();
}
private
static
void
Dispose
(
TcpClient
client
,
Stream
clientStream
,
CustomBinaryReader
clientStreamReader
,
StreamWriter
clientStreamWriter
,
SessionEventArgs
args
)
{
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
();
}
}
private
static
void
SetClientRequestHeaders
(
List
<
string
>
requestLines
,
HttpWebRequest
webRequest
)
private
static
void
SetClientRequestHeaders
(
List
<
string
>
requestLines
,
HttpWebRequest
webRequest
)
{
{
...
@@ -508,6 +425,7 @@ namespace Titanium.Web.Proxy
...
@@ -508,6 +425,7 @@ namespace Titanium.Web.Proxy
case
"user-agent"
:
case
"user-agent"
:
webRequest
.
UserAgent
=
header
[
1
];
webRequest
.
UserAgent
=
header
[
1
];
break
;
break
;
//revisit this, transfer-encoding is not a request header according to spec
//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?
//But how to identify if client is sending chunked body for PUT/POST?
case
"transfer-encoding"
:
case
"transfer-encoding"
:
...
@@ -537,7 +455,6 @@ namespace Titanium.Web.Proxy
...
@@ -537,7 +455,6 @@ namespace Titanium.Web.Proxy
private
static
void
SendClientRequestBody
(
SessionEventArgs
args
)
private
static
void
SendClientRequestBody
(
SessionEventArgs
args
)
{
{
// End the operation
// End the operation
Stream
postStream
=
args
.
ProxyRequest
.
GetRequestStream
();
Stream
postStream
=
args
.
ProxyRequest
.
GetRequestStream
();
...
@@ -574,12 +491,15 @@ namespace Titanium.Web.Proxy
...
@@ -574,12 +491,15 @@ namespace Titanium.Web.Proxy
}
}
postStream
.
Close
();
postStream
.
Close
();
postStream
.
Dispose
();
}
}
catch
catch
{
{
if
(
postStream
!=
null
)
if
(
postStream
!=
null
)
{
postStream
.
Close
();
postStream
.
Close
();
postStream
.
Dispose
();
}
throw
;
throw
;
}
}
...
@@ -649,7 +569,10 @@ namespace Titanium.Web.Proxy
...
@@ -649,7 +569,10 @@ namespace Titanium.Web.Proxy
catch
catch
{
{
if
(
postStream
!=
null
)
if
(
postStream
!=
null
)
{
postStream
.
Close
();
postStream
.
Close
();
postStream
.
Dispose
();
}
throw
;
throw
;
}
}
...
...
Titanium.Web.Proxy/ResponseHandler.cs
View file @
9e41d558
...
@@ -97,24 +97,11 @@ namespace Titanium.Web.Proxy
...
@@ -97,24 +97,11 @@ namespace Titanium.Web.Proxy
}
}
}
}
catch
catch
{
{
if
(
args
.
ClientStreamReader
!=
null
)
Dispose
(
args
.
Client
,
args
.
ClientStream
,
args
.
ClientStreamReader
,
args
.
ClientStreamWriter
,
args
);
args
.
ClientStreamReader
.
Dispose
();
if
(
args
.
ClientStreamWriter
!=
null
)
args
.
ClientStreamWriter
.
Dispose
();
if
(
args
.
ClientStream
!=
null
)
args
.
ClientStream
.
Dispose
();
if
(
args
.
Client
!=
null
)
args
.
Client
.
Close
();
}
}
finally
finally
{
{
if
(
args
!=
null
)
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