Skip to content
This repository has been archived by the owner on Jul 9, 2023. It is now read-only.

Commit

Permalink
Merge pull request #54 from justcoding121/master
Browse files Browse the repository at this point in the history
readme
  • Loading branch information
justcoding121 committed Mar 21, 2016
2 parents ca5e25d + 65d6e3e commit c625408
Showing 1 changed file with 25 additions and 24 deletions.
49 changes: 25 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,11 @@ Sample request and response event handlers

```csharp

//Test On Request, intercept requests
//Test On Request, intecept requests
//Read browser URL send back to proxy by the injection script in OnResponse event
public void OnRequest(object sender, SessionEventArgs e)
{
Console.WriteLine(e.ProxySession.Request.RequestUrl);
Console.WriteLine(e.ProxySession.Request.Url);

//read request headers
var requestHeaders = e.ProxySession.Request.RequestHeaders;
Expand All @@ -91,38 +92,38 @@ Sample request and response event handlers
//To cancel a request with a custom HTML content
//Filter URL
if (e.ProxySession.Request.RequestUrl.Contains("google.com"))
if (e.ProxySession.Request.RequestUri.AbsoluteUri.Contains("google.com"))
{
e.Ok("<!DOCTYPE html><html><body><h1>Website Blocked</h1><p>Blocked by titanium web proxy.</p></body></html>");
e.Ok("<!DOCTYPE html>"+
"<html><body><h1>"+
"Website Blocked"+
"</h1>"+
"<p>Blocked by titanium web proxy.</p>"+
"</body>"+
"</html>");
}
}

public void OnResponse(object sender, SessionEventArgs e)
{
////read response headers

//Test script injection
//Insert script to read the Browser URL and send it back to proxy
public void OnResponse(object sender, SessionEventArgs e)
{

//read response headers
var responseHeaders = e.ProxySession.Response.ResponseHeaders;


if (e.ResponseStatusCode == "200")
if (e.RequestMethod == "GET" || e.RequestMethod == "POST")
{
if (e.ResponseContentType.Trim().ToLower().Contains("text/html"))
if (e.ProxySession.Response.ResponseStatusCode == "200")
{
//Get/Set response body bytes
byte[] responseBodyBytes = e.GetResponseBody();
e.SetResponseBody(responseBodyBytes);

//Get response body as string
string responseBody = e.GetResponseBodyAsString();

//Modify e.ServerResponse
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);

//Set modifed response Html Body
e.SetResponseBodyString(modified);
if (e.ProxySession.Response.ContentType.Trim().ToLower().Contains("text/html"))
{
string body = e.GetResponseBodyAsString();
}
}
}
}
}
```
Future roadmap
============
Expand Down

0 comments on commit c625408

Please sign in to comment.