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

Commit c625408

Browse files
committed
Merge pull request #54 from justcoding121/master
readme
2 parents ca5e25d + 65d6e3e commit c625408

File tree

1 file changed

+25
-24
lines changed

1 file changed

+25
-24
lines changed

README.md

+25-24
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,11 @@ Sample request and response event handlers
6868

6969
```csharp
7070

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

7677
//read request headers
7778
var requestHeaders = e.ProxySession.Request.RequestHeaders;
@@ -91,38 +92,38 @@ Sample request and response event handlers
9192
//To cancel a request with a custom HTML content
9293
//Filter URL
9394
94-
if (e.ProxySession.Request.RequestUrl.Contains("google.com"))
95+
if (e.ProxySession.Request.RequestUri.AbsoluteUri.Contains("google.com"))
9596
{
96-
e.Ok("<!DOCTYPE html><html><body><h1>Website Blocked</h1><p>Blocked by titanium web proxy.</p></body></html>");
97+
e.Ok("<!DOCTYPE html>"+
98+
"<html><body><h1>"+
99+
"Website Blocked"+
100+
"</h1>"+
101+
"<p>Blocked by titanium web proxy.</p>"+
102+
"</body>"+
103+
"</html>");
97104
}
98105
}
99-
100-
public void OnResponse(object sender, SessionEventArgs e)
101-
{
102-
////read response headers
106+
107+
//Test script injection
108+
//Insert script to read the Browser URL and send it back to proxy
109+
public void OnResponse(object sender, SessionEventArgs e)
110+
{
111+
112+
//read response headers
103113
var responseHeaders = e.ProxySession.Response.ResponseHeaders;
104114

105115

106-
if (e.ResponseStatusCode == "200")
116+
if (e.RequestMethod == "GET" || e.RequestMethod == "POST")
107117
{
108-
if (e.ResponseContentType.Trim().ToLower().Contains("text/html"))
118+
if (e.ProxySession.Response.ResponseStatusCode == "200")
109119
{
110-
//Get/Set response body bytes
111-
byte[] responseBodyBytes = e.GetResponseBody();
112-
e.SetResponseBody(responseBodyBytes);
113-
114-
//Get response body as string
115-
string responseBody = e.GetResponseBodyAsString();
116-
117-
//Modify e.ServerResponse
118-
Regex rex = new Regex("</body>", RegexOptions.RightToLeft | RegexOptions.IgnoreCase | RegexOptions.Multiline);
119-
string modified = rex.Replace(responseBody, "<script type =\"text/javascript\">alert('Response was modified by this script!');</script></body>", 1);
120-
121-
//Set modifed response Html Body
122-
e.SetResponseBodyString(modified);
120+
if (e.ProxySession.Response.ContentType.Trim().ToLower().Contains("text/html"))
121+
{
122+
string body = e.GetResponseBodyAsString();
123+
}
123124
}
124125
}
125-
}
126+
}
126127
```
127128
Future roadmap
128129
============

0 commit comments

Comments
 (0)