Commit f870fad5 authored by justcoding121's avatar justcoding121

order method signatures for readabilty

parent 59792b59
using System; using System.Threading.Tasks;
using System.Threading.Tasks;
namespace Titanium.Web.Proxy.EventArguments namespace Titanium.Web.Proxy.EventArguments
{ {
......
...@@ -9,7 +9,7 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -9,7 +9,7 @@ namespace Titanium.Web.Proxy.EventArguments
internal BeforeSslAuthenticateEventArgs(CancellationTokenSource taskCancellationSource) internal BeforeSslAuthenticateEventArgs(CancellationTokenSource taskCancellationSource)
{ {
this.TaskCancellationSource = taskCancellationSource; TaskCancellationSource = taskCancellationSource;
} }
public string SniHostName { get; internal set; } public string SniHostName { get; internal set; }
......
...@@ -10,7 +10,7 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -10,7 +10,7 @@ namespace Titanium.Web.Proxy.EventArguments
public int Count { get; } public int Count { get; }
public DataEventArgs(byte[] buffer, int offset, int count) internal DataEventArgs(byte[] buffer, int offset, int count)
{ {
Buffer = buffer; Buffer = buffer;
Offset = offset; Offset = offset;
......
...@@ -16,7 +16,7 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -16,7 +16,7 @@ namespace Titanium.Web.Proxy.EventArguments
private bool readChunkTrail; private bool readChunkTrail;
private long bytesRemaining; private long bytesRemaining;
public LimitedStream(CustomBufferedStream baseStream, CustomBinaryReader baseReader, bool isChunked, long contentLength) internal LimitedStream(CustomBufferedStream baseStream, CustomBinaryReader baseReader, bool isChunked, long contentLength)
{ {
this.baseStream = baseStream; this.baseStream = baseStream;
this.baseReader = baseReader; this.baseReader = baseReader;
......
...@@ -57,13 +57,15 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -57,13 +57,15 @@ namespace Titanium.Web.Proxy.EventArguments
/// <summary> /// <summary>
/// Constructor to initialize the proxy /// Constructor to initialize the proxy
/// </summary> /// </summary>
internal SessionEventArgs(int bufferSize, ProxyEndPoint endPoint, ExceptionHandler exceptionFunc, CancellationTokenSource cancellationTokenSource) internal SessionEventArgs(int bufferSize, ProxyEndPoint endPoint,
: this(bufferSize, endPoint, exceptionFunc, null, cancellationTokenSource) CancellationTokenSource cancellationTokenSource, ExceptionHandler exceptionFunc)
: this(bufferSize, endPoint, cancellationTokenSource, null, exceptionFunc)
{ {
} }
protected SessionEventArgs(int bufferSize, ProxyEndPoint endPoint, ExceptionHandler exceptionFunc, Request request, CancellationTokenSource cancellationTokenSource) protected SessionEventArgs(int bufferSize, ProxyEndPoint endPoint,
: base(bufferSize, endPoint, exceptionFunc, request, cancellationTokenSource) CancellationTokenSource cancellationTokenSource, Request request, ExceptionHandler exceptionFunc)
: base(bufferSize, endPoint, cancellationTokenSource, request, exceptionFunc)
{ {
} }
......
...@@ -70,13 +70,15 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -70,13 +70,15 @@ namespace Titanium.Web.Proxy.EventArguments
/// <summary> /// <summary>
/// Constructor to initialize the proxy /// Constructor to initialize the proxy
/// </summary> /// </summary>
internal SessionEventArgsBase(int bufferSize, ProxyEndPoint endPoint, ExceptionHandler exceptionFunc, CancellationTokenSource cancellationTokenSource) internal SessionEventArgsBase(int bufferSize, ProxyEndPoint endPoint,
: this(bufferSize, endPoint, exceptionFunc, null, cancellationTokenSource) CancellationTokenSource cancellationTokenSource, ExceptionHandler exceptionFunc)
: this(bufferSize, endPoint, cancellationTokenSource, null, exceptionFunc)
{ {
} }
protected SessionEventArgsBase(int bufferSize, ProxyEndPoint endPoint, ExceptionHandler exceptionFunc, protected SessionEventArgsBase(int bufferSize, ProxyEndPoint endPoint,
Request request, CancellationTokenSource cancellationTokenSource) CancellationTokenSource cancellationTokenSource,
Request request, ExceptionHandler exceptionFunc)
{ {
this.BufferSize = bufferSize; this.BufferSize = bufferSize;
this.ExceptionFunc = exceptionFunc; this.ExceptionFunc = exceptionFunc;
......
...@@ -17,7 +17,7 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -17,7 +17,7 @@ namespace Titanium.Web.Proxy.EventArguments
public bool IsHttpsConnect { get; internal set; } public bool IsHttpsConnect { get; internal set; }
internal TunnelConnectSessionEventArgs(int bufferSize, ProxyEndPoint endPoint, ConnectRequest connectRequest, ExceptionHandler exceptionFunc, CancellationTokenSource cancellationTokenSource) internal TunnelConnectSessionEventArgs(int bufferSize, ProxyEndPoint endPoint, ConnectRequest connectRequest, ExceptionHandler exceptionFunc, CancellationTokenSource cancellationTokenSource)
: base(bufferSize, endPoint, exceptionFunc, connectRequest, cancellationTokenSource) : base(bufferSize, endPoint, cancellationTokenSource, connectRequest, exceptionFunc)
{ {
} }
} }
......
...@@ -200,7 +200,7 @@ namespace Titanium.Web.Proxy ...@@ -200,7 +200,7 @@ namespace Titanium.Web.Proxy
} }
//Now create the request //Now create the request
await HandleHttpSessionRequest(tcpClient, clientStream, clientStreamReader, clientStreamWriter, connectHostname, endPoint, connectRequest, cancellationTokenSource); await HandleHttpSessionRequest(endPoint, tcpClient, clientStream, clientStreamReader, clientStreamWriter, cancellationTokenSource, connectHostname, connectRequest);
} }
catch (ProxyHttpException e) catch (ProxyHttpException e)
{ {
......
...@@ -21,18 +21,18 @@ namespace Titanium.Web.Proxy.Network.Tcp ...@@ -21,18 +21,18 @@ namespace Titanium.Web.Proxy.Network.Tcp
/// <summary> /// <summary>
/// Creates a TCP connection to server /// Creates a TCP connection to server
/// </summary> /// </summary>
/// <param name="server"></param>
/// <param name="remoteHostName"></param> /// <param name="remoteHostName"></param>
/// <param name="remotePort"></param> /// <param name="remotePort"></param>
/// <param name="httpVersion"></param> /// <param name="httpVersion"></param>
/// <param name="isHttps"></param> /// <param name="isHttps"></param>
/// <param name="isConnect"></param> /// <param name="isConnect"></param>
/// <param name="proxyServer"></param>
/// <param name="upStreamEndPoint"></param> /// <param name="upStreamEndPoint"></param>
/// <param name="externalProxy"></param> /// <param name="externalProxy"></param>
/// <returns></returns> /// <returns></returns>
internal async Task<TcpConnection> CreateClient(ProxyServer server, internal async Task<TcpConnection> CreateClient(string remoteHostName,
string remoteHostName, int remotePort, Version httpVersion, bool isHttps, int remotePort, Version httpVersion, bool isHttps, bool isConnect,
bool isConnect, IPEndPoint upStreamEndPoint, ExternalProxy externalProxy) ProxyServer proxyServer, IPEndPoint upStreamEndPoint, ExternalProxy externalProxy)
{ {
bool useUpstreamProxy = false; bool useUpstreamProxy = false;
...@@ -65,11 +65,11 @@ namespace Titanium.Web.Proxy.Network.Tcp ...@@ -65,11 +65,11 @@ namespace Titanium.Web.Proxy.Network.Tcp
await client.ConnectAsync(remoteHostName, remotePort); await client.ConnectAsync(remoteHostName, remotePort);
} }
stream = new CustomBufferedStream(client.GetStream(), server.BufferSize); stream = new CustomBufferedStream(client.GetStream(), proxyServer.BufferSize);
if (useUpstreamProxy && (isConnect || isHttps)) if (useUpstreamProxy && (isConnect || isHttps))
{ {
var writer = new HttpRequestWriter(stream, server.BufferSize); var writer = new HttpRequestWriter(stream, proxyServer.BufferSize);
await writer.WriteLineAsync($"CONNECT {remoteHostName}:{remotePort} HTTP/{httpVersion}"); await writer.WriteLineAsync($"CONNECT {remoteHostName}:{remotePort} HTTP/{httpVersion}");
await writer.WriteLineAsync($"Host: {remoteHostName}:{remotePort}"); await writer.WriteLineAsync($"Host: {remoteHostName}:{remotePort}");
await writer.WriteLineAsync($"{KnownHeaders.Connection}: {KnownHeaders.ConnectionKeepAlive}"); await writer.WriteLineAsync($"{KnownHeaders.Connection}: {KnownHeaders.ConnectionKeepAlive}");
...@@ -84,7 +84,7 @@ namespace Titanium.Web.Proxy.Network.Tcp ...@@ -84,7 +84,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
await writer.WriteLineAsync(); await writer.WriteLineAsync();
using (var reader = new CustomBinaryReader(stream, server.BufferSize)) using (var reader = new CustomBinaryReader(stream, proxyServer.BufferSize))
{ {
string httpStatus = await reader.ReadLineAsync(); string httpStatus = await reader.ReadLineAsync();
...@@ -102,14 +102,14 @@ namespace Titanium.Web.Proxy.Network.Tcp ...@@ -102,14 +102,14 @@ namespace Titanium.Web.Proxy.Network.Tcp
if (isHttps) if (isHttps)
{ {
var sslStream = new SslStream(stream, false, server.ValidateServerCertificate, server.SelectClientCertificate); var sslStream = new SslStream(stream, false, proxyServer.ValidateServerCertificate, proxyServer.SelectClientCertificate);
stream = new CustomBufferedStream(sslStream, server.BufferSize); stream = new CustomBufferedStream(sslStream, proxyServer.BufferSize);
await sslStream.AuthenticateAsClientAsync(remoteHostName, null, server.SupportedSslProtocols, server.CheckCertificateRevocation); await sslStream.AuthenticateAsClientAsync(remoteHostName, null, proxyServer.SupportedSslProtocols, proxyServer.CheckCertificateRevocation);
} }
client.ReceiveTimeout = server.ConnectionTimeOutSeconds * 1000; client.ReceiveTimeout = proxyServer.ConnectionTimeOutSeconds * 1000;
client.SendTimeout = server.ConnectionTimeOutSeconds * 1000; client.SendTimeout = proxyServer.ConnectionTimeOutSeconds * 1000;
} }
catch (Exception) catch (Exception)
{ {
...@@ -118,7 +118,7 @@ namespace Titanium.Web.Proxy.Network.Tcp ...@@ -118,7 +118,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
throw; throw;
} }
return new TcpConnection(server) return new TcpConnection(proxyServer)
{ {
UpStreamProxy = externalProxy, UpStreamProxy = externalProxy,
UpStreamEndPoint = upStreamEndPoint, UpStreamEndPoint = upStreamEndPoint,
...@@ -127,8 +127,8 @@ namespace Titanium.Web.Proxy.Network.Tcp ...@@ -127,8 +127,8 @@ namespace Titanium.Web.Proxy.Network.Tcp
IsHttps = isHttps, IsHttps = isHttps,
UseUpstreamProxy = useUpstreamProxy, UseUpstreamProxy = useUpstreamProxy,
TcpClient = client, TcpClient = client,
StreamReader = new CustomBinaryReader(stream, server.BufferSize), StreamReader = new CustomBinaryReader(stream, proxyServer.BufferSize),
StreamWriter = new HttpRequestWriter(stream, server.BufferSize), StreamWriter = new HttpRequestWriter(stream, proxyServer.BufferSize),
Stream = stream, Stream = stream,
Version = httpVersion Version = httpVersion
}; };
......
...@@ -33,14 +33,15 @@ namespace Titanium.Web.Proxy ...@@ -33,14 +33,15 @@ namespace Titanium.Web.Proxy
/// <param name="clientStream"></param> /// <param name="clientStream"></param>
/// <param name="clientStreamReader"></param> /// <param name="clientStreamReader"></param>
/// <param name="clientStreamWriter"></param> /// <param name="clientStreamWriter"></param>
/// <param name="cancellationTokenSource"></param>
/// <param name="httpsConnectHostname"></param> /// <param name="httpsConnectHostname"></param>
/// <param name="endPoint"></param> /// <param name="endPoint"></param>
/// <param name="connectRequest"></param> /// <param name="connectRequest"></param>
/// <param name="isTransparentEndPoint"></param> /// <param name="isTransparentEndPoint"></param>
/// <returns></returns> /// <returns></returns>
private async Task HandleHttpSessionRequest(TcpClient client, CustomBufferedStream clientStream, private async Task HandleHttpSessionRequest(ProxyEndPoint endPoint, TcpClient client,
CustomBinaryReader clientStreamReader, HttpResponseWriter clientStreamWriter, string httpsConnectHostname, CustomBufferedStream clientStream, CustomBinaryReader clientStreamReader, HttpResponseWriter clientStreamWriter,
ProxyEndPoint endPoint, ConnectRequest connectRequest, CancellationTokenSource cancellationTokenSource, bool isTransparentEndPoint = false) CancellationTokenSource cancellationTokenSource, string httpsConnectHostname, ConnectRequest connectRequest, bool isTransparentEndPoint = false)
{ {
TcpConnection connection = null; TcpConnection connection = null;
...@@ -57,7 +58,7 @@ namespace Titanium.Web.Proxy ...@@ -57,7 +58,7 @@ namespace Titanium.Web.Proxy
return; return;
} }
var args = new SessionEventArgs(BufferSize, endPoint, ExceptionFunc, cancellationTokenSource) var args = new SessionEventArgs(BufferSize, endPoint, cancellationTokenSource, ExceptionFunc)
{ {
ProxyClient = { TcpClient = client }, ProxyClient = { TcpClient = client },
WebSession = { ConnectRequest = connectRequest } WebSession = { ConnectRequest = connectRequest }
...@@ -354,11 +355,11 @@ namespace Titanium.Web.Proxy ...@@ -354,11 +355,11 @@ namespace Titanium.Web.Proxy
args.CustomUpStreamProxyUsed = customUpStreamProxy; args.CustomUpStreamProxyUsed = customUpStreamProxy;
return await tcpConnectionFactory.CreateClient(this, return await tcpConnectionFactory.CreateClient(args.WebSession.Request.RequestUri.Host,
args.WebSession.Request.RequestUri.Host,
args.WebSession.Request.RequestUri.Port, args.WebSession.Request.RequestUri.Port,
args.WebSession.Request.HttpVersion, args.WebSession.Request.HttpVersion,
isHttps, isConnect, isHttps,
isConnect, this,
args.WebSession.UpStreamEndPoint ?? UpStreamEndPoint, args.WebSession.UpStreamEndPoint ?? UpStreamEndPoint,
customUpStreamProxy ?? (isHttps ? UpStreamHttpsProxy : UpStreamHttpProxy)); customUpStreamProxy ?? (isHttps ? UpStreamHttpsProxy : UpStreamHttpProxy));
} }
......
...@@ -122,8 +122,8 @@ namespace Titanium.Web.Proxy ...@@ -122,8 +122,8 @@ namespace Titanium.Web.Proxy
//HTTPS server created - we can now decrypt the client's traffic //HTTPS server created - we can now decrypt the client's traffic
//Now create the request //Now create the request
await HandleHttpSessionRequest(tcpClient, clientStream, clientStreamReader, clientStreamWriter, await HandleHttpSessionRequest(endPoint, tcpClient, clientStream, clientStreamReader,
isHttps ? httpsHostName : null, endPoint, null, cancellationTokenSource, true); clientStreamWriter, cancellationTokenSource, isHttps ? httpsHostName : null, null, true);
} }
finally finally
{ {
......
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