Commit 929f8627 authored by titanium007's avatar titanium007

cleanup

parent 44b4d4b7
using System;
using System.Text.RegularExpressions;
using Titanium.Web.Proxy.EventArguments;
namespace Titanium.Web.Proxy.Test
......@@ -46,27 +47,27 @@ namespace Titanium.Web.Proxy.Test
Console.WriteLine(e.ProxySession.Request.RequestUrl);
////read request headers
//var requestHeaders = e.RequestHeaders;
var requestHeaders = e.ProxySession.Request.RequestHeaders;
//if ((e.RequestMethod.ToUpper() == "POST" || e.RequestMethod.ToUpper() == "PUT"))
//{
// //Get/Set request body bytes
// byte[] bodyBytes = e.GetRequestBody();
// e.SetRequestBody(bodyBytes);
if ((e.RequestMethod.ToUpper() == "POST" || e.RequestMethod.ToUpper() == "PUT"))
{
//Get/Set request body bytes
byte[] bodyBytes = e.GetRequestBody();
e.SetRequestBody(bodyBytes);
// //Get/Set request body as string
// string bodyString = e.GetRequestBodyAsString();
// e.SetRequestBodyString(bodyString);
//Get/Set request body as string
string bodyString = e.GetRequestBodyAsString();
e.SetRequestBodyString(bodyString);
//}
}
////To cancel a request with a custom HTML content
////Filter URL
//To cancel a request with a custom HTML content
//Filter URL
//if (e.RequestURL.Contains("google.com"))
//{
// e.Ok("<!DOCTYPE html><html><body><h1>Website Blocked</h1><p>Blocked by titanium web proxy.</p></body></html>");
//}
if (e.ProxySession.Request.RequestUrl.Contains("google.com"))
{
e.Ok("<!DOCTYPE html><html><body><h1>Website Blocked</h1><p>Blocked by titanium web proxy.</p></body></html>");
}
}
//Test script injection
......@@ -74,10 +75,10 @@ namespace Titanium.Web.Proxy.Test
public void OnResponse(object sender, SessionEventArgs e)
{
////read response headers
//var responseHeaders = e.ResponseHeaders;
var responseHeaders = e.ProxySession.Response.ResponseHeaders;
//if (e.ResponseStatusCode == HttpStatusCode.OK)
//if (e.ResponseStatusCode == "200")
//{
// if (e.ResponseContentType.Trim().ToLower().Contains("text/html"))
// {
......
......@@ -79,14 +79,7 @@ namespace Titanium.Web.Proxy.EventArguments
public void Dispose()
{
//if (ProxyRequest != null)
// ProxyRequest.Abort();
//if (ResponseStream != null)
// ResponseStream.Dispose();
//if (ServerResponse != null)
// ServerResponse.Close();
}
private void ReadRequestBody()
......
......@@ -35,6 +35,7 @@ namespace Titanium.Web.Proxy.Http
internal byte[] RequestBody { get; set; }
internal string RequestBodyString { get; set; }
internal bool RequestBodyRead { get; set; }
public bool UpgradeToWebSocket { get; set; }
public List<HttpHeader> RequestHeaders { get; internal set; }
internal bool RequestLocked { get; set; }
......@@ -42,6 +43,7 @@ namespace Titanium.Web.Proxy.Http
{
this.RequestHeaders = new List<HttpHeader>();
}
}
public class Response
......@@ -62,15 +64,17 @@ namespace Titanium.Web.Proxy.Http
public bool ResponseKeepAlive { get; set; }
public string ResponseContentType { get; set; }
public int ContentLength { get; set; }
public bool IsChunked { get; set; }
public Response()
{
this.ResponseHeaders = new List<HttpHeader>();
this.ResponseKeepAlive = true;
}
public bool IsChunked { get; set; }
}
public class HttpWebSession
......
......@@ -20,28 +20,10 @@ namespace Titanium.Web.Proxy.Http
internal class TcpConnectionManager
{
static Dictionary<string, Stack<TcpConnection>> ConnectionCache = new Dictionary<string, Stack<TcpConnection>>();
public static TcpConnection GetClient(string Hostname, int port, bool IsSecure)
{
//var key = string.Concat(Hostname, ":", port, ":", IsSecure);
//TcpConnection client;
//lock (ConnectionCache)
//{
// Stack<TcpConnection> connections;
// if (!ConnectionCache.TryGetValue(key, out connections))
// {
// return CreateClient(Hostname, port, IsSecure);
// }
// if (connections.Count > 0)
// {
// client = connections.Pop();
// }
// else
return CreateClient(Hostname, port, IsSecure);
//}
//return client;
}
private static TcpConnection CreateClient(string Hostname, int port, bool IsSecure)
......@@ -69,25 +51,5 @@ namespace Titanium.Web.Proxy.Http
return new TcpConnection() { Client = client, ServerStreamReader = new CustomBinaryReader(stream, Encoding.ASCII), Stream = stream };
}
public static void AddClient(string Hostname, int port, bool IsSecure, TcpConnection Client)
{
var key = string.Concat(Hostname, ":", port, ":", IsSecure);
lock (ConnectionCache)
{
Stack<TcpConnection> connections;
if (!ConnectionCache.TryGetValue(key, out connections))
{
connections = new Stack<TcpConnection>();
connections.Push(Client);
ConnectionCache.Add(key, connections);
}
connections.Push(Client);
}
}
}
}
This diff is collapsed.
......@@ -39,7 +39,7 @@ namespace Titanium.Web.Proxy
if (args.ProxySession.Response.ResponseBodyRead)
{
var isChunked = args.ProxySession.Response.ResponseHeaders.Any(x => x.Name.ToLower() == "transfer-encoding" && x.Value.ToLower().Contains("chunked"));
var isChunked =args.ProxySession.Response.IsChunked;
var contentEncoding = args.ProxySession.Response.ResponseContentEncoding;
switch (contentEncoding.ToLower())
......@@ -105,14 +105,17 @@ namespace Titanium.Web.Proxy
response.Response.ResponseCharacterSet = response.Response.ResponseHeaders[i].Value.Split(';')[1].ToLower().Replace("charset=", string.Empty).Trim();
}
else
response.Response.ResponseContentType = response.Response.ResponseHeaders[i].Value.Trim();
response.Response.ResponseContentType = response.Response.ResponseHeaders[i].Value.ToLower().Trim();
break;
case "transfer-encoding":
if (response.Response.ResponseHeaders[i].Value.Contains("chunked"))
if (response.Response.ResponseHeaders[i].Value.ToLower().Contains("chunked"))
response.Response.IsChunked = true;
break;
case "connection":
if (response.Response.ResponseHeaders[i].Value.ToLower().Contains("close"))
response.Response.ResponseKeepAlive = false;
break;
default:
break;
}
......
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