Commit 3ad68ea6 authored by Honfika's avatar Honfika

cleanup

parent ce8c03a3
...@@ -150,7 +150,7 @@ namespace Titanium.Web.Proxy.Examples.Basic ...@@ -150,7 +150,7 @@ namespace Titanium.Web.Proxy.Examples.Basic
//Modify response //Modify response
public async Task OnResponse(object sender, SessionEventArgs e) public async Task OnResponse(object sender, SessionEventArgs e)
{ {
Console.WriteLine("Active Server Connections:" + (sender as ProxyServer).ServerConnectionCount); Console.WriteLine("Active Server Connections:" + ((ProxyServer) sender).ServerConnectionCount);
if (requestBodyHistory.ContainsKey(e.Id)) if (requestBodyHistory.ContainsKey(e.Id))
{ {
......
...@@ -14,7 +14,6 @@ namespace Titanium.Web.Proxy.IntegrationTests ...@@ -14,7 +14,6 @@ namespace Titanium.Web.Proxy.IntegrationTests
public class SslTests public class SslTests
{ {
[TestMethod] [TestMethod]
public void TestSsl() public void TestSsl()
{ {
//expand this to stress test to find //expand this to stress test to find
......
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> <wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/LINE_FEED_AT_FILE_END/@EntryValue">True</s:Boolean> <s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/LINE_FEED_AT_FILE_END/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_AFTER_TYPECAST_PARENTHESES/@EntryValue">False</s:Boolean>
<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_LIMIT/@EntryValue">240</s:Int64>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=BC/@EntryIndexedValue">BC</s:String> <s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=BC/@EntryIndexedValue">BC</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=CN/@EntryIndexedValue">CN</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=DN/@EntryIndexedValue">DN</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=EKU/@EntryIndexedValue">EKU</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=KU/@EntryIndexedValue">KU</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=MTA/@EntryIndexedValue">MTA</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=OID/@EntryIndexedValue">OID</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=OIDS/@EntryIndexedValue">OIDS</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateConstants/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String> <s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateConstants/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateInstanceFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String> <s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateInstanceFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateStaticFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String> <s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateStaticFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
......
using System; using System;
using System.Net.Security; using System.Net.Security;
using System.Security.Cryptography.X509Certificates; using System.Security.Cryptography.X509Certificates;
using System.Threading.Tasks;
using Titanium.Web.Proxy.EventArguments; using Titanium.Web.Proxy.EventArguments;
using Titanium.Web.Proxy.Extensions; using Titanium.Web.Proxy.Extensions;
......
...@@ -56,7 +56,7 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -56,7 +56,7 @@ namespace Titanium.Web.Proxy.EventArguments
/// <summary> /// <summary>
/// Client End Point. /// Client End Point.
/// </summary> /// </summary>
public IPEndPoint ClientEndPoint => (IPEndPoint) ProxyClient.TcpClient.Client.RemoteEndPoint; public IPEndPoint ClientEndPoint => (IPEndPoint)ProxyClient.TcpClient.Client.RemoteEndPoint;
/// <summary> /// <summary>
/// A web session corresponding to a single request/response sequence /// A web session corresponding to a single request/response sequence
...@@ -158,7 +158,7 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -158,7 +158,7 @@ namespace Titanium.Web.Proxy.EventArguments
await WebSession.ServerConnection.StreamReader.CopyBytesToStream(bufferSize, responseBodyStream, await WebSession.ServerConnection.StreamReader.CopyBytesToStream(bufferSize, responseBodyStream,
WebSession.Response.ContentLength); WebSession.Response.ContentLength);
} }
else if ((WebSession.Response.HttpVersion.Major == 1 && WebSession.Response.HttpVersion.Minor == 0) || WebSession.Response.ContentLength == -1) else if (WebSession.Response.HttpVersion.Major == 1 && WebSession.Response.HttpVersion.Minor == 0 || WebSession.Response.ContentLength == -1)
{ {
await WebSession.ServerConnection.StreamReader.CopyBytesToStream(bufferSize, responseBodyStream, long.MaxValue); await WebSession.ServerConnection.StreamReader.CopyBytesToStream(bufferSize, responseBodyStream, long.MaxValue);
} }
......
using System; using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Titanium.Web.Proxy.Extensions namespace Titanium.Web.Proxy.Extensions
......
...@@ -136,7 +136,7 @@ namespace Titanium.Web.Proxy.Extensions ...@@ -136,7 +136,7 @@ namespace Titanium.Web.Proxy.Extensions
if (contentLength < bufferSize) if (contentLength < bufferSize)
{ {
bytesToRead = (int) contentLength; bytesToRead = (int)contentLength;
} }
var buffer = new byte[bufferSize]; var buffer = new byte[bufferSize];
...@@ -153,8 +153,8 @@ namespace Titanium.Web.Proxy.Extensions ...@@ -153,8 +153,8 @@ namespace Titanium.Web.Proxy.Extensions
break; break;
bytesRead = 0; bytesRead = 0;
var remainingBytes = (contentLength - totalBytesRead); var remainingBytes = contentLength - totalBytesRead;
bytesToRead = remainingBytes > (long) bufferSize ? bufferSize : (int) remainingBytes; bytesToRead = remainingBytes > (long)bufferSize ? bufferSize : (int)remainingBytes;
} }
} }
else else
......
...@@ -118,7 +118,7 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -118,7 +118,7 @@ namespace Titanium.Web.Proxy.Helpers
var buffer = staticBuffer; var buffer = staticBuffer;
if (totalBytesToRead < bufferSize) if (totalBytesToRead < bufferSize)
{ {
bytesToRead = (int) totalBytesToRead; bytesToRead = (int)totalBytesToRead;
buffer = new byte[bytesToRead]; buffer = new byte[bytesToRead];
} }
...@@ -133,7 +133,7 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -133,7 +133,7 @@ namespace Titanium.Web.Proxy.Helpers
break; break;
var remainingBytes = totalBytesToRead - totalBytesRead; var remainingBytes = totalBytesToRead - totalBytesRead;
bytesToRead = Math.Min(bufferSize, (int) remainingBytes); bytesToRead = Math.Min(bufferSize, (int)remainingBytes);
if (totalBytesRead + bytesToRead > buffer.Length) if (totalBytesRead + bytesToRead > buffer.Length)
{ {
......
...@@ -198,7 +198,7 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -198,7 +198,7 @@ namespace Titanium.Web.Proxy.Helpers
{ {
if (asyncResult is ReadAsyncResult) if (asyncResult is ReadAsyncResult)
{ {
return ((ReadAsyncResult) asyncResult).ReadBytes; return ((ReadAsyncResult)asyncResult).ReadBytes;
} }
return baseStream.EndRead(asyncResult); return baseStream.EndRead(asyncResult);
......
...@@ -229,7 +229,7 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -229,7 +229,7 @@ namespace Titanium.Web.Proxy.Helpers
finally finally
{ {
tcpConnection.Dispose(); tcpConnection.Dispose();
Interlocked.Decrement(ref server.serverConnectionCount); Interlocked.Decrement(ref server.ServerConnectionCountField);
} }
} }
} }
......
...@@ -29,7 +29,7 @@ namespace Titanium.Web.Proxy.Http ...@@ -29,7 +29,7 @@ namespace Titanium.Web.Proxy.Http
{ {
var existing = headers[newHeader.Name]; var existing = headers[newHeader.Name];
var nonUniqueHeaders = new List<HttpHeader> { existing, newHeader }; var nonUniqueHeaders = new List<HttpHeader> {existing, newHeader};
nonUniqueResponseHeaders.Add(newHeader.Name, nonUniqueHeaders); nonUniqueResponseHeaders.Add(newHeader.Name, nonUniqueHeaders);
headers.Remove(newHeader.Name); headers.Remove(newHeader.Name);
......
...@@ -79,7 +79,7 @@ namespace Titanium.Web.Proxy.Http ...@@ -79,7 +79,7 @@ namespace Titanium.Web.Proxy.Http
var requestLines = new StringBuilder(); var requestLines = new StringBuilder();
//prepare the request & headers //prepare the request & headers
if ((ServerConnection.UpStreamHttpProxy != null && ServerConnection.IsHttps == false) || (ServerConnection.UpStreamHttpsProxy != null && ServerConnection.IsHttps)) if (ServerConnection.UpStreamHttpProxy != null && ServerConnection.IsHttps == false || ServerConnection.UpStreamHttpsProxy != null && ServerConnection.IsHttps)
{ {
requestLines.AppendLine($"{Request.Method} {Request.RequestUri.AbsoluteUri} HTTP/{Request.HttpVersion.Major}.{Request.HttpVersion.Minor}"); requestLines.AppendLine($"{Request.Method} {Request.RequestUri.AbsoluteUri} HTTP/{Request.HttpVersion.Major}.{Request.HttpVersion.Minor}");
} }
......
...@@ -13,7 +13,7 @@ namespace Titanium.Web.Proxy.Http.Responses ...@@ -13,7 +13,7 @@ namespace Titanium.Web.Proxy.Http.Responses
/// <param name="status"></param> /// <param name="status"></param>
public GenericResponse(HttpStatusCode status) public GenericResponse(HttpStatusCode status)
{ {
ResponseStatusCode = ((int) status).ToString(); ResponseStatusCode = ((int)status).ToString();
ResponseStatusDescription = status.ToString(); ResponseStatusDescription = status.ToString();
} }
......
...@@ -110,7 +110,7 @@ namespace Titanium.Web.Proxy.Network.Certificate ...@@ -110,7 +110,7 @@ namespace Titanium.Web.Proxy.Network.Certificate
// Corresponding private key // Corresponding private key
var privateKeyInfo = PrivateKeyInfoFactory.CreatePrivateKeyInfo(subjectKeyPair.Private); var privateKeyInfo = PrivateKeyInfoFactory.CreatePrivateKeyInfo(subjectKeyPair.Private);
var seq = (Asn1Sequence) Asn1Object.FromByteArray(privateKeyInfo.ParsePrivateKey().GetDerEncoded()); var seq = (Asn1Sequence)Asn1Object.FromByteArray(privateKeyInfo.ParsePrivateKey().GetDerEncoded());
if (seq.Count != 9) if (seq.Count != 9)
{ {
......
...@@ -114,7 +114,7 @@ namespace Titanium.Web.Proxy.Network.Certificate ...@@ -114,7 +114,7 @@ namespace Titanium.Web.Proxy.Network.Certificate
typeX509PrivateKey.InvokeMember("ProviderName", BindingFlags.PutDispProperty, null, sharedPrivateKey, typeValue); typeX509PrivateKey.InvokeMember("ProviderName", BindingFlags.PutDispProperty, null, sharedPrivateKey, typeValue);
typeValue[0] = 2; typeValue[0] = 2;
typeX509PrivateKey.InvokeMember("ExportPolicy", BindingFlags.PutDispProperty, null, sharedPrivateKey, typeValue); typeX509PrivateKey.InvokeMember("ExportPolicy", BindingFlags.PutDispProperty, null, sharedPrivateKey, typeValue);
typeValue = new object[] {(isRoot ? 2 : 1)}; typeValue = new object[] {isRoot ? 2 : 1};
typeX509PrivateKey.InvokeMember("KeySpec", BindingFlags.PutDispProperty, null, sharedPrivateKey, typeValue); typeX509PrivateKey.InvokeMember("KeySpec", BindingFlags.PutDispProperty, null, sharedPrivateKey, typeValue);
if (!isRoot) if (!isRoot)
...@@ -251,7 +251,7 @@ namespace Titanium.Web.Proxy.Network.Certificate ...@@ -251,7 +251,7 @@ namespace Titanium.Web.Proxy.Network.Certificate
try try
{ {
var empty = (string) typeX509Enrollment.InvokeMember("CreatePFX", BindingFlags.InvokeMethod, null, x509Enrollment, typeValue); var empty = (string)typeX509Enrollment.InvokeMember("CreatePFX", BindingFlags.InvokeMethod, null, x509Enrollment, typeValue);
return new X509Certificate2(Convert.FromBase64String(empty), string.Empty, X509KeyStorageFlags.Exportable); return new X509Certificate2(Convert.FromBase64String(empty), string.Empty, X509KeyStorageFlags.Exportable);
} }
catch (Exception) catch (Exception)
...@@ -293,8 +293,7 @@ namespace Titanium.Web.Proxy.Network.Certificate ...@@ -293,8 +293,7 @@ namespace Titanium.Web.Proxy.Network.Certificate
var graceTime = DateTime.Now.AddDays(GraceDays); var graceTime = DateTime.Now.AddDays(GraceDays);
var now = DateTime.Now; var now = DateTime.Now;
rCert = !isRoot ? MakeCertificate(false, sSubjectCN, fullSubject, keyLength, HashAlgo, graceTime, now.AddDays(ValidDays), signingCert) : rCert = MakeCertificate(isRoot, sSubjectCN, fullSubject, keyLength, HashAlgo, graceTime, now.AddDays(ValidDays), isRoot ? null : signingCert);
MakeCertificate(true, sSubjectCN, fullSubject, keyLength, HashAlgo, graceTime, now.AddDays(ValidDays), null);
return rCert; return rCert;
} }
} }
......
...@@ -52,7 +52,7 @@ namespace Titanium.Web.Proxy.Network ...@@ -52,7 +52,7 @@ namespace Titanium.Web.Proxy.Network
if (certEngine == null) if (certEngine == null)
{ {
certEngine = engine == CertificateEngine.BouncyCastle certEngine = engine == CertificateEngine.BouncyCastle
? (ICertificateMaker) new BCCertificateMaker() ? (ICertificateMaker)new BCCertificateMaker()
: new WinCertificateMaker(); : new WinCertificateMaker();
} }
} }
......
...@@ -18,7 +18,6 @@ namespace Titanium.Web.Proxy.Network.Tcp ...@@ -18,7 +18,6 @@ namespace Titanium.Web.Proxy.Network.Tcp
/// </summary> /// </summary>
internal class TcpConnectionFactory internal class TcpConnectionFactory
{ {
/// <summary> /// <summary>
/// Creates a TCP connection to server /// Creates a TCP connection to server
/// </summary> /// </summary>
...@@ -40,10 +39,10 @@ namespace Titanium.Web.Proxy.Network.Tcp ...@@ -40,10 +39,10 @@ namespace Titanium.Web.Proxy.Network.Tcp
TcpClient client; TcpClient client;
CustomBufferedStream stream; CustomBufferedStream stream;
bool isLocalhost = (externalHttpsProxy == null && externalHttpProxy == null) ? false : NetworkHelper.IsLocalIpAddress(remoteHostName); bool isLocalhost = (externalHttpsProxy != null || externalHttpProxy != null) && NetworkHelper.IsLocalIpAddress(remoteHostName);
bool useHttpsProxy = externalHttpsProxy != null && externalHttpsProxy.HostName != remoteHostName && (externalHttpsProxy.BypassForLocalhost && !isLocalhost); bool useHttpsProxy = externalHttpsProxy != null && externalHttpsProxy.HostName != remoteHostName && externalHttpsProxy.BypassForLocalhost && !isLocalhost;
bool useHttpProxy = externalHttpProxy != null && externalHttpProxy.HostName != remoteHostName && (externalHttpProxy.BypassForLocalhost && !isLocalhost); bool useHttpProxy = externalHttpProxy != null && externalHttpProxy.HostName != remoteHostName && externalHttpProxy.BypassForLocalhost && !isLocalhost;
if (isHttps) if (isHttps)
{ {
...@@ -128,7 +127,7 @@ namespace Titanium.Web.Proxy.Network.Tcp ...@@ -128,7 +127,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
client.LingerState = new LingerOption(true, 0); client.LingerState = new LingerOption(true, 0);
Interlocked.Increment(ref server.serverConnectionCount); Interlocked.Increment(ref server.ServerConnectionCountField);
return new TcpConnection return new TcpConnection
{ {
......
...@@ -36,8 +36,8 @@ namespace Titanium.Web.Proxy ...@@ -36,8 +36,8 @@ namespace Titanium.Web.Proxy
private Action<Exception> exceptionFunc; private Action<Exception> exceptionFunc;
private bool trustRootCertificate; private bool trustRootCertificate;
private int clientConnectionCount; private int clientConnectionCountField;
internal int serverConnectionCount; internal int ServerConnectionCountField;
/// <summary> /// <summary>
/// A object that creates tcp connection to server /// A object that creates tcp connection to server
...@@ -53,8 +53,7 @@ namespace Titanium.Web.Proxy ...@@ -53,8 +53,7 @@ namespace Titanium.Web.Proxy
/// <summary> /// <summary>
/// Set firefox to use default system proxy /// Set firefox to use default system proxy
/// </summary> /// </summary>
private FireFoxProxySettingsManager firefoxProxySettingsManager private FireFoxProxySettingsManager firefoxProxySettingsManager = new FireFoxProxySettingsManager();
= new FireFoxProxySettingsManager();
#endif #endif
/// <summary> /// <summary>
...@@ -232,13 +231,13 @@ namespace Titanium.Web.Proxy ...@@ -232,13 +231,13 @@ namespace Titanium.Web.Proxy
/// <summary> /// <summary>
/// Total number of active client connections /// Total number of active client connections
/// </summary> /// </summary>
public int ClientConnectionCount => clientConnectionCount; public int ClientConnectionCount => clientConnectionCountField;
/// <summary> /// <summary>
/// Total number of active server connections /// Total number of active server connections
/// </summary> /// </summary>
public int ServerConnectionCount => serverConnectionCount; public int ServerConnectionCount => ServerConnectionCountField;
/// <summary> /// <summary>
/// Constructor /// Constructor
...@@ -599,7 +598,7 @@ namespace Titanium.Web.Proxy ...@@ -599,7 +598,7 @@ namespace Titanium.Web.Proxy
{ {
Task.Run(async () => Task.Run(async () =>
{ {
Interlocked.Increment(ref clientConnectionCount); Interlocked.Increment(ref clientConnectionCountField);
//This line is important! //This line is important!
//contributors please don't remove it without discussion //contributors please don't remove it without discussion
...@@ -620,7 +619,7 @@ namespace Titanium.Web.Proxy ...@@ -620,7 +619,7 @@ namespace Titanium.Web.Proxy
} }
finally finally
{ {
Interlocked.Decrement(ref clientConnectionCount); Interlocked.Decrement(ref clientConnectionCountField);
tcpClient?.Close(); tcpClient?.Close();
} }
}); });
......
...@@ -33,7 +33,7 @@ namespace Titanium.Web.Proxy ...@@ -33,7 +33,7 @@ namespace Titanium.Web.Proxy
clientStream.WriteTimeout = ConnectionTimeOutSeconds * 1000; clientStream.WriteTimeout = ConnectionTimeOutSeconds * 1000;
var clientStreamReader = new CustomBinaryReader(clientStream, BufferSize); var clientStreamReader = new CustomBinaryReader(clientStream, BufferSize);
var clientStreamWriter = new StreamWriter(clientStream) { NewLine = ProxyConstants.NewLine }; var clientStreamWriter = new StreamWriter(clientStream) {NewLine = ProxyConstants.NewLine};
Uri httpRemoteUri; Uri httpRemoteUri;
...@@ -188,7 +188,7 @@ namespace Titanium.Web.Proxy ...@@ -188,7 +188,7 @@ namespace Titanium.Web.Proxy
clientStream = new CustomBufferedStream(sslStream, BufferSize); clientStream = new CustomBufferedStream(sslStream, BufferSize);
clientStreamReader = new CustomBinaryReader(clientStream, BufferSize); clientStreamReader = new CustomBinaryReader(clientStream, BufferSize);
clientStreamWriter = new StreamWriter(clientStream) { NewLine = ProxyConstants.NewLine }; clientStreamWriter = new StreamWriter(clientStream) {NewLine = ProxyConstants.NewLine};
//HTTPS server created - we can now decrypt the client's traffic //HTTPS server created - we can now decrypt the client's traffic
} }
catch (Exception) catch (Exception)
...@@ -205,7 +205,7 @@ namespace Titanium.Web.Proxy ...@@ -205,7 +205,7 @@ namespace Titanium.Web.Proxy
else else
{ {
clientStreamReader = new CustomBinaryReader(clientStream, BufferSize); clientStreamReader = new CustomBinaryReader(clientStream, BufferSize);
clientStreamWriter = new StreamWriter(clientStream) { NewLine = ProxyConstants.NewLine }; clientStreamWriter = new StreamWriter(clientStream) {NewLine = ProxyConstants.NewLine};
} }
//now read the request line //now read the request line
...@@ -392,8 +392,6 @@ namespace Titanium.Web.Proxy ...@@ -392,8 +392,6 @@ namespace Titanium.Web.Proxy
/// <param name="httpsHostName"></param> /// <param name="httpsHostName"></param>
/// <param name="endPoint"></param> /// <param name="endPoint"></param>
/// <param name="connectHeaders"></param> /// <param name="connectHeaders"></param>
/// <param name="customUpStreamHttpProxy"></param>
/// <param name="customUpStreamHttpsProxy"></param>
/// <returns></returns> /// <returns></returns>
private async Task HandleHttpSessionRequest(TcpClient client, string httpCmd, Stream clientStream, private async Task HandleHttpSessionRequest(TcpClient client, string httpCmd, Stream clientStream,
CustomBinaryReader clientStreamReader, StreamWriter clientStreamWriter, string httpsHostName, CustomBinaryReader clientStreamReader, StreamWriter clientStreamWriter, string httpsHostName,
...@@ -417,8 +415,8 @@ namespace Titanium.Web.Proxy ...@@ -417,8 +415,8 @@ namespace Titanium.Web.Proxy
var args = new SessionEventArgs(BufferSize, HandleHttpSessionResponse) var args = new SessionEventArgs(BufferSize, HandleHttpSessionResponse)
{ {
ProxyClient = { TcpClient = client }, ProxyClient = {TcpClient = client},
WebSession = { ConnectHeaders = connectHeaders } WebSession = {ConnectHeaders = connectHeaders}
}; };
args.WebSession.ProcessId = new Lazy<int>(() => args.WebSession.ProcessId = new Lazy<int>(() =>
...@@ -457,7 +455,8 @@ namespace Titanium.Web.Proxy ...@@ -457,7 +455,8 @@ namespace Titanium.Web.Proxy
//Read the request headers in to unique and non-unique header collections //Read the request headers in to unique and non-unique header collections
await HeaderParser.ReadHeaders(clientStreamReader, args.WebSession.Request.NonUniqueRequestHeaders, args.WebSession.Request.RequestHeaders); await HeaderParser.ReadHeaders(clientStreamReader, args.WebSession.Request.NonUniqueRequestHeaders, args.WebSession.Request.RequestHeaders);
var httpRemoteUri = new Uri(httpsHostName == null ? httpCmdSplit[1] var httpRemoteUri = new Uri(httpsHostName == null
? httpCmdSplit[1]
: string.Concat("https://", args.WebSession.Request.Host ?? httpsHostName, httpCmdSplit[1])); : string.Concat("https://", args.WebSession.Request.Host ?? httpsHostName, httpCmdSplit[1]));
args.WebSession.Request.RequestUri = httpRemoteUri; args.WebSession.Request.RequestUri = httpRemoteUri;
......
...@@ -46,10 +46,10 @@ namespace Titanium.Web.Proxy ...@@ -46,10 +46,10 @@ namespace Titanium.Web.Proxy
if (args.ReRequest) if (args.ReRequest)
{ {
if(args.WebSession.ServerConnection != null) if (args.WebSession.ServerConnection != null)
{ {
args.WebSession.ServerConnection.Dispose(); args.WebSession.ServerConnection.Dispose();
Interlocked.Decrement(ref serverConnectionCount); Interlocked.Decrement(ref ServerConnectionCountField);
} }
var connection = await GetServerConnection(args); var connection = await GetServerConnection(args);
...@@ -233,7 +233,7 @@ namespace Titanium.Web.Proxy ...@@ -233,7 +233,7 @@ namespace Titanium.Web.Proxy
StreamWriter clientStreamWriter, StreamWriter clientStreamWriter,
TcpConnection serverConnection) TcpConnection serverConnection)
{ {
Interlocked.Decrement(ref serverConnectionCount); Interlocked.Decrement(ref ServerConnectionCountField);
clientStream?.Close(); clientStream?.Close();
clientStream?.Dispose(); clientStream?.Dispose();
......
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