Commit bbd6f9b5 authored by Honfika's avatar Honfika

redundant parameter removed

parent 5f65f4d7
...@@ -65,7 +65,7 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -65,7 +65,7 @@ namespace Titanium.Web.Proxy.EventArguments
{ {
bytesRemaining = -1; bytesRemaining = -1;
//chunk trail // chunk trail
baseStream.ReadLineAsync().Wait(); baseStream.ReadLineAsync().Wait();
} }
} }
......
...@@ -88,14 +88,14 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -88,14 +88,14 @@ namespace Titanium.Web.Proxy.EventArguments
var request = WebSession.Request; var request = WebSession.Request;
//If not already read (not cached yet) // If not already read (not cached yet)
if (!request.IsBodyRead) if (!request.IsBodyRead)
{ {
var body = await ReadBodyAsync(true, cancellationToken); var body = await ReadBodyAsync(true, cancellationToken);
request.Body = body; request.Body = body;
//Now set the flag to true // Now set the flag to true
//So that next time we can deliver body from cache // So that next time we can deliver body from cache
request.IsBodyRead = true; request.IsBodyRead = true;
OnDataSent(body, 0, body.Length); OnDataSent(body, 0, body.Length);
} }
...@@ -106,7 +106,7 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -106,7 +106,7 @@ namespace Titanium.Web.Proxy.EventArguments
/// </summary> /// </summary>
internal async Task ClearResponse(CancellationToken cancellationToken) internal async Task ClearResponse(CancellationToken cancellationToken)
{ {
//syphon out the response body from server // syphon out the response body from server
await SyphonOutBodyAsync(false, cancellationToken); await SyphonOutBodyAsync(false, cancellationToken);
WebSession.Response = new Response(); WebSession.Response = new Response();
} }
...@@ -139,14 +139,14 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -139,14 +139,14 @@ namespace Titanium.Web.Proxy.EventArguments
return; return;
} }
//If not already read (not cached yet) // If not already read (not cached yet)
if (!response.IsBodyRead) if (!response.IsBodyRead)
{ {
var body = await ReadBodyAsync(false, cancellationToken); var body = await ReadBodyAsync(false, cancellationToken);
response.Body = body; response.Body = body;
//Now set the flag to true // Now set the flag to true
//So that next time we can deliver body from cache // So that next time we can deliver body from cache
response.IsBodyRead = true; response.IsBodyRead = true;
OnDataReceived(body, 0, body.Length); OnDataReceived(body, 0, body.Length);
} }
...@@ -196,7 +196,7 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -196,7 +196,7 @@ namespace Titanium.Web.Proxy.EventArguments
long contentLength = request.ContentLength; long contentLength = request.ContentLength;
//send the request body bytes to server // send the request body bytes to server
if (contentLength > 0 && hasMulipartEventSubscribers && request.IsMultipartFormData) if (contentLength > 0 && hasMulipartEventSubscribers && request.IsMultipartFormData)
{ {
var reader = GetStreamReader(true); var reader = GetStreamReader(true);
...@@ -323,7 +323,7 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -323,7 +323,7 @@ namespace Titanium.Web.Proxy.EventArguments
if (bufferDataLength == buffer.Length) if (bufferDataLength == buffer.Length)
{ {
//boundary is not longer than 70 bytes according to the specification, so keeping the last 100 (minimum 74) bytes is enough // boundary is not longer than 70 bytes according to the specification, so keeping the last 100 (minimum 74) bytes is enough
const int bytesToKeep = 100; const int bytesToKeep = 100;
Buffer.BlockCopy(buffer, buffer.Length - bytesToKeep, buffer, 0, bytesToKeep); Buffer.BlockCopy(buffer, buffer.Length - bytesToKeep, buffer, 0, bytesToKeep);
bufferDataLength = bytesToKeep; bufferDataLength = bytesToKeep;
......
...@@ -53,14 +53,14 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -53,14 +53,14 @@ namespace Titanium.Web.Proxy.EventArguments
{ {
var remoteEndPoint = ClientEndPoint; var remoteEndPoint = ClientEndPoint;
//If client is localhost get the process id // If client is localhost get the process id
if (NetworkHelper.IsLocalIpAddress(remoteEndPoint.Address)) if (NetworkHelper.IsLocalIpAddress(remoteEndPoint.Address))
{ {
var ipVersion = endPoint.IpV6Enabled ? IpVersion.Ipv6 : IpVersion.Ipv4; var ipVersion = endPoint.IpV6Enabled ? IpVersion.Ipv6 : IpVersion.Ipv4;
return TcpHelper.GetProcessIdByLocalPort(ipVersion, remoteEndPoint.Port); return TcpHelper.GetProcessIdByLocalPort(ipVersion, remoteEndPoint.Port);
} }
//can't access process Id of remote request from remote machine // can't access process Id of remote request from remote machine
return -1; return -1;
} }
......
...@@ -277,9 +277,8 @@ namespace Titanium.Web.Proxy ...@@ -277,9 +277,8 @@ namespace Titanium.Web.Proxy
} }
//Now create the request //Now create the request
await HandleHttpSessionRequest(endPoint, clientConnection, clientStream, await HandleHttpSessionRequest(endPoint, clientConnection, clientStream, clientStreamWriter,
clientStreamWriter, cancellationTokenSource, connectHostname, cancellationTokenSource, connectHostname, connectArgs?.WebSession.ConnectRequest);
connectArgs?.WebSession.ConnectRequest);
} }
catch (ProxyException e) catch (ProxyException e)
{ {
......
...@@ -31,10 +31,10 @@ namespace Titanium.Web.Proxy.Extensions ...@@ -31,10 +31,10 @@ namespace Titanium.Web.Proxy.Extensions
try try
{ {
//This line is important! // This line is important!
//contributors please don't remove it without discussion // contributors please don't remove it without discussion
//It helps to avoid eventual deterioration of performance due to TCP port exhaustion // It helps to avoid eventual deterioration of performance due to TCP port exhaustion
//due to default TCP CLOSE_WAIT timeout for 4 minutes // due to default TCP CLOSE_WAIT timeout for 4 minutes
if (socketCleanedUpGetter == null || !socketCleanedUpGetter(tcpClient.Client)) if (socketCleanedUpGetter == null || !socketCleanedUpGetter(tcpClient.Client))
{ {
tcpClient.LingerState = new LingerOption(true, 0); tcpClient.LingerState = new LingerOption(true, 0);
......
...@@ -44,8 +44,7 @@ namespace Titanium.Web.Proxy ...@@ -44,8 +44,7 @@ namespace Titanium.Web.Proxy
/// <returns></returns> /// <returns></returns>
private async Task HandleHttpSessionRequest(ProxyEndPoint endPoint, TcpClientConnection clientConnection, private async Task HandleHttpSessionRequest(ProxyEndPoint endPoint, TcpClientConnection clientConnection,
CustomBufferedStream clientStream, HttpResponseWriter clientStreamWriter, CustomBufferedStream clientStream, HttpResponseWriter clientStreamWriter,
CancellationTokenSource cancellationTokenSource, string httpsConnectHostname, ConnectRequest connectRequest, CancellationTokenSource cancellationTokenSource, string httpsConnectHostname, ConnectRequest connectRequest)
bool isTransparentEndPoint = false)
{ {
var cancellationToken = cancellationTokenSource.Token; var cancellationToken = cancellationTokenSource.Token;
TcpServerConnection serverConnection = null; TcpServerConnection serverConnection = null;
...@@ -123,20 +122,19 @@ namespace Titanium.Web.Proxy ...@@ -123,20 +122,19 @@ namespace Titanium.Web.Proxy
args.ProxyClient.ClientStream = clientStream; args.ProxyClient.ClientStream = clientStream;
args.ProxyClient.ClientStreamWriter = clientStreamWriter; args.ProxyClient.ClientStreamWriter = clientStreamWriter;
//proxy authorization check if (!args.IsTransparent)
if (!args.IsTransparent && httpsConnectHostname == null &&
await CheckAuthorization(args) == false)
{ {
await InvokeBeforeResponse(args); //proxy authorization check
if (httpsConnectHostname == null && await CheckAuthorization(args) == false)
{
await InvokeBeforeResponse(args);
//send the response //send the response
await clientStreamWriter.WriteResponseAsync(args.WebSession.Response, await clientStreamWriter.WriteResponseAsync(args.WebSession.Response,
cancellationToken: cancellationToken); cancellationToken: cancellationToken);
return; return;
} }
if (!isTransparentEndPoint)
{
PrepareRequestHeaders(request.Headers); PrepareRequestHeaders(request.Headers);
request.Host = request.RequestUri.Authority; request.Host = request.RequestUri.Authority;
} }
......
...@@ -99,7 +99,7 @@ namespace Titanium.Web.Proxy ...@@ -99,7 +99,7 @@ namespace Titanium.Web.Proxy
int available = clientStream.Available; int available = clientStream.Available;
if (available > 0) if (available > 0)
{ {
//send the buffered data // send the buffered data
var data = BufferPool.GetBuffer(BufferSize); var data = BufferPool.GetBuffer(BufferSize);
try try
...@@ -126,7 +126,7 @@ namespace Titanium.Web.Proxy ...@@ -126,7 +126,7 @@ 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(endPoint, clientConnection, clientStream, clientStreamWriter, await HandleHttpSessionRequest(endPoint, clientConnection, clientStream, clientStreamWriter,
cancellationTokenSource, isHttps ? httpsHostName : null, null, true); cancellationTokenSource, isHttps ? httpsHostName : null, null);
} }
catch (ProxyException e) catch (ProxyException e)
{ {
......
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