Commit 9e41d558 authored by justcoding121's avatar justcoding121 Committed by justcoding121

Improve code brevity

parent 4b302863
......@@ -56,7 +56,4 @@ Global
GlobalSection(ExtensibilityGlobals) = postSolution
EnterpriseLibraryConfigurationToolBinariesPath = .1.505.2\lib\NET35
EndGlobalSection
GlobalSection(Performance) = preSolution
HasPerformanceSessions = true
EndGlobalSection
EndGlobal
......@@ -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,17 +311,11 @@ 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
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)
......@@ -421,25 +336,27 @@ namespace Titanium.Web.Proxy
}
catch
{
if (args != null)
args.Dispose();
if (clientStreamReader != null)
clientStreamReader.Dispose();
if (clientStreamWriter != null)
clientStreamWriter.Dispose();
if (clientStream != null)
clientStream.Dispose();
Dispose(client, clientStream, clientStreamReader, clientStreamWriter, args);
}
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)
{
......@@ -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;
}
......
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment