Commit 929f8627 authored by titanium007's avatar titanium007

cleanup

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