Commit 74ed1c2e authored by titanium007's avatar titanium007

Comment out sample code

parent 11563d36
...@@ -26,18 +26,6 @@ After installing nuget package mark following files to be copied to app director ...@@ -26,18 +26,6 @@ After installing nuget package mark following files to be copied to app director
* makecert.exe * makecert.exe
* Titanium_Proxy_Test_Root.cer * Titanium_Proxy_Test_Root.cer
Or install manually:
Add reference to
* Titanium.Web.Proxy.dll
These files also should be in your application directory
* Ionic.Zip.dll
* makecert.exe
* Titanium_Proxy_Test_Root.cer
Setup HTTP proxy: Setup HTTP proxy:
......
...@@ -60,22 +60,22 @@ namespace Titanium.Web.Proxy.Test ...@@ -60,22 +60,22 @@ namespace Titanium.Web.Proxy.Test
Console.WriteLine(e.RequestURL); Console.WriteLine(e.RequestURL);
if (e.RequestURL.Contains("somewebsite.com")) //if (e.RequestURL.Contains("somewebsite.com"))
if ((e.ProxyRequest.Method.ToUpper() == "POST" || e.ProxyRequest.Method.ToUpper() == "PUT") && e.ProxyRequest.ContentLength > 0) // if ((e.ProxyRequest.Method.ToUpper() == "POST" || e.ProxyRequest.Method.ToUpper() == "PUT") && e.ProxyRequest.ContentLength > 0)
{ // {
var m = e.GetRequestBody().Replace("a", "b"); // var m = e.GetRequestBody().Replace("a", "b");
e.SetRequestBody(m); // e.SetRequestBody(m);
} // }
//To cancel a request with a custom HTML content ////To cancel a request with a custom HTML content
//Filter URL ////Filter URL
if (e.RequestURL.Contains("somewebsite.com")) //if (e.RequestURL.Contains("somewebsite.com"))
{ //{
e.Ok("<!DOCTYPE html><html><body><h1>Blocked</h1><p>Website blocked.</p></body></html>"); // e.Ok("<!DOCTYPE html><html><body><h1>Blocked</h1><p>Website blocked.</p></body></html>");
} //}
} }
...@@ -85,21 +85,21 @@ namespace Titanium.Web.Proxy.Test ...@@ -85,21 +85,21 @@ namespace Titanium.Web.Proxy.Test
{ {
//To modify a response //To modify a response
if (e.ServerResponse.StatusCode == HttpStatusCode.OK) //if (e.ServerResponse.StatusCode == HttpStatusCode.OK)
{ //{
if (e.ServerResponse.ContentType.Trim().ToLower().Contains("text/html")) // if (e.ServerResponse.ContentType.Trim().ToLower().Contains("text/html"))
{ // {
//Get response body // //Get response body
string responseBody = e.GetResponseBody(); // string responseBody = e.GetResponseBody();
//Modify e.ServerResponse // //Modify e.ServerResponse
Regex rex = new Regex("</body>", RegexOptions.RightToLeft | RegexOptions.IgnoreCase | RegexOptions.Multiline); // Regex rex = new Regex("</body>", RegexOptions.RightToLeft | RegexOptions.IgnoreCase | RegexOptions.Multiline);
string modified = rex.Replace(responseBody, "<script type =\"text/javascript\">alert('Response was modified by this script!');</script></body>", 1); // string modified = rex.Replace(responseBody, "<script type =\"text/javascript\">alert('Response was modified by this script!');</script></body>", 1);
//Set modifed response Html Body // //Set modifed response Html Body
e.SetResponseBody(modified); // e.SetResponseBody(modified);
} // }
} //}
} }
......
...@@ -38,7 +38,7 @@ namespace Titanium.Web.Proxy ...@@ -38,7 +38,7 @@ namespace Titanium.Web.Proxy
{ {
string httpsDecoratedHostName = null, tmpLine = null; string httpsDecoratedHostName = null, tmpLine = null;
List<string> requestLines = new List<string>(); List<string> requestLines = new List<string>();
while (!String.IsNullOrEmpty(tmpLine = clientStreamReader.ReadLine())) while (!String.IsNullOrEmpty(tmpLine = clientStreamReader.ReadLine()))
{ {
requestLines.Add(tmpLine); requestLines.Add(tmpLine);
...@@ -75,12 +75,12 @@ namespace Titanium.Web.Proxy ...@@ -75,12 +75,12 @@ namespace Titanium.Web.Proxy
//instead = we are going to perform a man in the middle "attack" //instead = we are going to perform a man in the middle "attack"
//the user's browser should warn them of the certification errors, //the user's browser should warn them of the certification errors,
//to avoid that we need to install our root certficate in users machine as Certificate Authority. //to avoid that we need to install our root certficate in users machine as Certificate Authority.
remoteUri = "https://" + splitBuffer[1]; remoteUri = "https://" + splitBuffer[1];
HttpsHostName = splitBuffer[1].Split(':')[0]; HttpsHostName = splitBuffer[1].Split(':')[0];
int.TryParse(splitBuffer[1].Split(':')[1], out httpsPort); int.TryParse(splitBuffer[1].Split(':')[1], out httpsPort);
requestLines.Clear(); requestLines.Clear();
clientStreamWriter.WriteLine(RequestVersion + " 200 Connection established"); clientStreamWriter.WriteLine(RequestVersion + " 200 Connection established");
...@@ -110,7 +110,7 @@ namespace Titanium.Web.Proxy ...@@ -110,7 +110,7 @@ namespace Titanium.Web.Proxy
//Pinned certificate clients cannot be proxied //Pinned certificate clients cannot be proxied
//For example dropbox clients use certificate pinning //For example dropbox clients use certificate pinning
//So just relay the request //So just relay the request
if (!ExcludedHttpsHostNameRegex.Any(x=> Regex.IsMatch(HttpsHostName,x))) if (!ExcludedHttpsHostNameRegex.Any(x => Regex.IsMatch(HttpsHostName, x)))
{ {
try try
{ {
...@@ -125,7 +125,7 @@ namespace Titanium.Web.Proxy ...@@ -125,7 +125,7 @@ namespace Titanium.Web.Proxy
} }
catch catch
{ {
if (sslStream != null) if (sslStream != null)
sslStream.Dispose(); sslStream.Dispose();
...@@ -319,7 +319,7 @@ namespace Titanium.Web.Proxy ...@@ -319,7 +319,7 @@ namespace Titanium.Web.Proxy
Dispose(client, clientStream, clientStreamReader, clientStreamWriter, args); Dispose(client, clientStream, clientStreamReader, clientStreamWriter, args);
} }
} }
private static void Dispose(TcpClient client, Stream clientStream, CustomBinaryReader clientStreamReader, StreamWriter clientStreamWriter, SessionEventArgs args) private static void Dispose(TcpClient client, Stream clientStream, CustomBinaryReader clientStreamReader, StreamWriter clientStreamWriter, SessionEventArgs args)
{ {
...@@ -372,7 +372,7 @@ namespace Titanium.Web.Proxy ...@@ -372,7 +372,7 @@ namespace Titanium.Web.Proxy
webRequest.ContentLength = contentLen; webRequest.ContentLength = contentLen;
break; break;
case "content-type": case "content-type":
webRequest.ContentType = header[1]; webRequest.ContentType = header[1];
break; break;
case "expect": case "expect":
if (header[1].ToLower() == "100-continue") if (header[1].ToLower() == "100-continue")
...@@ -471,7 +471,7 @@ namespace Titanium.Web.Proxy ...@@ -471,7 +471,7 @@ namespace Titanium.Web.Proxy
} }
postStream.Close(); postStream.Close();
} }
catch catch
{ {
......
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