Commit 6cb2ed4f authored by titanium007's avatar titanium007

Add inline comments

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