Commit 670a2be6 authored by justcoding121's avatar justcoding121 Committed by justcoding121

Add inline comments

parent 329d8555
...@@ -8,6 +8,7 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -8,6 +8,7 @@ namespace Titanium.Web.Proxy.Helpers
{ {
public class NetFrameworkHelper public class NetFrameworkHelper
{ {
//http://stackoverflow.com/questions/856885/httpwebrequest-to-url-with-dot-at-the-end
public static void URLPeriodFix() public static void URLPeriodFix()
{ {
MethodInfo getSyntax = typeof(UriParser).GetMethod("GetSyntax", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic); MethodInfo getSyntax = typeof(UriParser).GetMethod("GetSyntax", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic);
......
...@@ -74,6 +74,7 @@ namespace Titanium.Web.Proxy ...@@ -74,6 +74,7 @@ namespace Titanium.Web.Proxy
ServicePointManager.DnsRefreshTimeout = 3 * 60 * 1000;//3 minutes ServicePointManager.DnsRefreshTimeout = 3 * 60 * 1000;//3 minutes
ServicePointManager.MaxServicePointIdleTime = 3 * 60 * 1000; ServicePointManager.MaxServicePointIdleTime = 3 * 60 * 1000;
//HttpWebRequest certificate validation callback
ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{ {
if (sslPolicyErrors == SslPolicyErrors.None) return true; if (sslPolicyErrors == SslPolicyErrors.None) return true;
...@@ -81,6 +82,7 @@ namespace Titanium.Web.Proxy ...@@ -81,6 +82,7 @@ namespace Titanium.Web.Proxy
return false; return false;
}; };
//Fix a bug in .NET 4.0
NetFrameworkHelper.URLPeriodFix(); NetFrameworkHelper.URLPeriodFix();
} }
...@@ -107,6 +109,7 @@ namespace Titanium.Web.Proxy ...@@ -107,6 +109,7 @@ namespace Titanium.Web.Proxy
RootCertificateName = RootCertificateName == null ? "Titanium_Proxy_Test_Root" : RootCertificateName; RootCertificateName = RootCertificateName == null ? "Titanium_Proxy_Test_Root" : RootCertificateName;
bool certTrusted = CertManager.CreateTrustedRootCertificate(); bool certTrusted = CertManager.CreateTrustedRootCertificate();
//If certificate was trusted by the machine
if (certTrusted) if (certTrusted)
{ {
SystemProxyHelper.EnableProxyHTTPS("localhost", ListeningPort); SystemProxyHelper.EnableProxyHTTPS("localhost", ListeningPort);
...@@ -143,18 +146,14 @@ namespace Titanium.Web.Proxy ...@@ -143,18 +146,14 @@ namespace Titanium.Web.Proxy
{ {
while (ShouldListen) while (ShouldListen)
{ {
var client = listener.AcceptTcpClient(); var client = listener.AcceptTcpClient();
Task.Factory.StartNew(() => HandleClient(client)); Task.Factory.StartNew(() => HandleClient(client));
} }
} }
catch (ThreadInterruptedException) { } catch (ThreadInterruptedException) { }
catch (SocketException) catch (SocketException) { }
{
}
} }
......
This diff is collapsed.
...@@ -17,6 +17,7 @@ namespace Titanium.Web.Proxy ...@@ -17,6 +17,7 @@ namespace Titanium.Web.Proxy
{ {
partial class ProxyServer partial class ProxyServer
{ {
//Called asynchronously when a request was successfully and we received the response
private static void HandleHttpSessionResponse(IAsyncResult AsynchronousResult) private static void HandleHttpSessionResponse(IAsyncResult AsynchronousResult)
{ {
...@@ -27,7 +28,8 @@ namespace Titanium.Web.Proxy ...@@ -27,7 +28,8 @@ namespace Titanium.Web.Proxy
} }
catch (WebException webEx) catch (WebException webEx)
{ {
args.ProxyRequest.KeepAlive = false; //Things line 404, 500 etc
//args.ProxyRequest.KeepAlive = false;
args.ServerResponse = webEx.Response as HttpWebResponse; args.ServerResponse = webEx.Response as HttpWebResponse;
} }
...@@ -109,35 +111,25 @@ namespace Titanium.Web.Proxy ...@@ -109,35 +111,25 @@ namespace Titanium.Web.Proxy
} }
catch (IOException ex) catch (IOException)
{ {
args.ProxyRequest.KeepAlive = false; args.ProxyRequest.KeepAlive = false;
Debug.WriteLine(ex.Message);
} }
catch (SocketException ex) catch (SocketException ex)
{ {
args.ProxyRequest.KeepAlive = false; args.ProxyRequest.KeepAlive = false;
Debug.WriteLine(ex.Message);
} }
catch (ArgumentException ex) catch (ArgumentException)
{ {
args.ProxyRequest.KeepAlive = false; args.ProxyRequest.KeepAlive = false;
Debug.WriteLine(ex.Message);
} }
catch (WebException ex) catch (WebException)
{ {
args.ProxyRequest.KeepAlive = false; args.ProxyRequest.KeepAlive = false;
Debug.WriteLine(ex.Message);
} }
finally finally
{ {
//Close this HttpWebRequest session
if (args.ProxyRequest != null) args.ProxyRequest.Abort(); if (args.ProxyRequest != null) args.ProxyRequest.Abort();
if (args.ServerResponseStream != null) args.ServerResponseStream.Close(); if (args.ServerResponseStream != null) args.ServerResponseStream.Close();
...@@ -146,6 +138,7 @@ namespace Titanium.Web.Proxy ...@@ -146,6 +138,7 @@ namespace Titanium.Web.Proxy
} }
//If this is false then terminate the tcp client
if (args.ProxyRequest.KeepAlive == false) if (args.ProxyRequest.KeepAlive == false)
{ {
if (responseWriter != null) if (responseWriter != null)
...@@ -245,6 +238,7 @@ namespace Titanium.Web.Proxy ...@@ -245,6 +238,7 @@ namespace Titanium.Web.Proxy
} }
} }
//Send chunked response
public static void SendChunked(Stream InStream, Stream OutStream) public static void SendChunked(Stream InStream, Stream OutStream)
{ {
...@@ -274,8 +268,6 @@ namespace Titanium.Web.Proxy ...@@ -274,8 +268,6 @@ namespace Titanium.Web.Proxy
var ChunkTrail = Encoding.ASCII.GetBytes(Environment.NewLine); var ChunkTrail = Encoding.ASCII.GetBytes(Environment.NewLine);
var ChunkHead = Encoding.ASCII.GetBytes(Data.Length.ToString("x2")); var ChunkHead = Encoding.ASCII.GetBytes(Data.Length.ToString("x2"));
OutStream.Write(ChunkHead, 0, ChunkHead.Length); OutStream.Write(ChunkHead, 0, ChunkHead.Length);
OutStream.Write(ChunkTrail, 0, ChunkTrail.Length); OutStream.Write(ChunkTrail, 0, ChunkTrail.Length);
......
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