Commit 9c7e4240 authored by Honfika's avatar Honfika

Small cleanup

parent ea20d43f
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Net; using System.Net;
using System.Security.Cryptography.X509Certificates;
using System.Threading.Tasks; using System.Threading.Tasks;
using Titanium.Web.Proxy.EventArguments; using Titanium.Web.Proxy.EventArguments;
using Titanium.Web.Proxy.Models; using Titanium.Web.Proxy.Models;
...@@ -129,6 +128,7 @@ namespace Titanium.Web.Proxy.Examples.Basic ...@@ -129,6 +128,7 @@ namespace Titanium.Web.Proxy.Examples.Basic
"</body>" + "</body>" +
"</html>"); "</html>");
} }
//Redirect example //Redirect example
if (e.WebSession.Request.RequestUri.AbsoluteUri.Contains("wikipedia.org")) if (e.WebSession.Request.RequestUri.AbsoluteUri.Contains("wikipedia.org"))
{ {
...@@ -144,6 +144,7 @@ namespace Titanium.Web.Proxy.Examples.Basic ...@@ -144,6 +144,7 @@ namespace Titanium.Web.Proxy.Examples.Basic
//access request body by looking up the shared dictionary using requestId //access request body by looking up the shared dictionary using requestId
var requestBody = requestBodyHistory[e.Id]; var requestBody = requestBodyHistory[e.Id];
} }
//read response headers //read response headers
var responseHeaders = e.WebSession.Response.ResponseHeaders; var responseHeaders = e.WebSession.Response.ResponseHeaders;
......
using System; using System;
using Microsoft.VisualStudio.TestTools.UnitTesting; using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Net; using System.Net;
using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using Titanium.Web.Proxy.EventArguments; using Titanium.Web.Proxy.EventArguments;
using Titanium.Web.Proxy.Models; using Titanium.Web.Proxy.Models;
...@@ -28,14 +27,13 @@ namespace Titanium.Web.Proxy.IntegrationTests ...@@ -28,14 +27,13 @@ namespace Titanium.Web.Proxy.IntegrationTests
{ {
var response = client.GetAsync(new Uri(testUrl)).Result; var response = client.GetAsync(new Uri(testUrl)).Result;
} }
} }
private HttpClient CreateHttpClient(string url, int localProxyPort) private HttpClient CreateHttpClient(string url, int localProxyPort)
{ {
var handler = new HttpClientHandler var handler = new HttpClientHandler
{ {
Proxy = new WebProxy(string.Format("http://localhost:{0}", localProxyPort), false), Proxy = new WebProxy($"http://localhost:{localProxyPort}", false),
UseProxy = true, UseProxy = true,
}; };
...@@ -47,7 +45,7 @@ namespace Titanium.Web.Proxy.IntegrationTests ...@@ -47,7 +45,7 @@ namespace Titanium.Web.Proxy.IntegrationTests
public class ProxyTestController public class ProxyTestController
{ {
private ProxyServer proxyServer; private readonly ProxyServer proxyServer;
public ProxyTestController() public ProxyTestController()
{ {
...@@ -63,7 +61,6 @@ namespace Titanium.Web.Proxy.IntegrationTests ...@@ -63,7 +61,6 @@ namespace Titanium.Web.Proxy.IntegrationTests
proxyServer.ClientCertificateSelectionCallback += OnCertificateSelection; proxyServer.ClientCertificateSelectionCallback += OnCertificateSelection;
var explicitEndPoint = new ExplicitProxyEndPoint(IPAddress.Any, proxyPort, true); var explicitEndPoint = new ExplicitProxyEndPoint(IPAddress.Any, proxyPort, true);
//An explicit endpoint is where the client knows about the existance of a proxy //An explicit endpoint is where the client knows about the existance of a proxy
//So client sends request in a proxy friendly manner //So client sends request in a proxy friendly manner
...@@ -73,7 +70,6 @@ namespace Titanium.Web.Proxy.IntegrationTests ...@@ -73,7 +70,6 @@ namespace Titanium.Web.Proxy.IntegrationTests
foreach (var endPoint in proxyServer.ProxyEndPoints) foreach (var endPoint in proxyServer.ProxyEndPoints)
Console.WriteLine("Listening on '{0}' endpoint at Ip {1} and port: {2} ", Console.WriteLine("Listening on '{0}' endpoint at Ip {1} and port: {2} ",
endPoint.GetType().Name, endPoint.IpAddress, endPoint.Port); endPoint.GetType().Name, endPoint.IpAddress, endPoint.Port);
} }
public void Stop() public void Stop()
......
<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:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=BC/@EntryIndexedValue">BC</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/=PrivateStaticReadonly/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String> <s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateStaticReadonly/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/UserRules/=dda2ffa1_002D435c_002D4111_002D88eb_002D1a7c93c382f0/@EntryIndexedValue">&lt;Policy&gt;&lt;Descriptor Staticness="Static, Instance" AccessRightKinds="Private" Description="Property (private)"&gt;&lt;ElementKinds&gt;&lt;Kind Name="PROPERTY" /&gt;&lt;/ElementKinds&gt;&lt;/Descriptor&gt;&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;&lt;/Policy&gt;</s:String></wpf:ResourceDictionary> <s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/UserRules/=dda2ffa1_002D435c_002D4111_002D88eb_002D1a7c93c382f0/@EntryIndexedValue">&lt;Policy&gt;&lt;Descriptor Staticness="Static, Instance" AccessRightKinds="Private" Description="Property (private)"&gt;&lt;ElementKinds&gt;&lt;Kind Name="PROPERTY" /&gt;&lt;/ElementKinds&gt;&lt;/Descriptor&gt;&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;&lt;/Policy&gt;</s:String></wpf:ResourceDictionary>
\ No newline at end of file
...@@ -46,7 +46,7 @@ namespace Titanium.Web.Proxy.Extensions ...@@ -46,7 +46,7 @@ namespace Titanium.Web.Proxy.Extensions
while (totalbytesRead < totalBytesToRead) while (totalbytesRead < totalBytesToRead)
{ {
var buffer = await streamReader.ReadBytesAsync(bufferSize, bytesToRead); var buffer = await streamReader.ReadBytesAsync(bytesToRead);
if (buffer.Length == 0) if (buffer.Length == 0)
{ {
...@@ -81,7 +81,7 @@ namespace Titanium.Web.Proxy.Extensions ...@@ -81,7 +81,7 @@ namespace Titanium.Web.Proxy.Extensions
if (chunkSize != 0) if (chunkSize != 0)
{ {
var buffer = await clientStreamReader.ReadBytesAsync(bufferSize, chunkSize); var buffer = await clientStreamReader.ReadBytesAsync(chunkSize);
await stream.WriteAsync(buffer, 0, buffer.Length); await stream.WriteAsync(buffer, 0, buffer.Length);
//chunk trail //chunk trail
await clientStreamReader.ReadLineAsync(); await clientStreamReader.ReadLineAsync();
...@@ -179,7 +179,7 @@ namespace Titanium.Web.Proxy.Extensions ...@@ -179,7 +179,7 @@ namespace Titanium.Web.Proxy.Extensions
if (chunkSize != 0) if (chunkSize != 0)
{ {
var buffer = await inStreamReader.ReadBytesAsync(bufferSize, chunkSize); var buffer = await inStreamReader.ReadBytesAsync(chunkSize);
var chunkHeadBytes = Encoding.ASCII.GetBytes(chunkSize.ToString("x2")); var chunkHeadBytes = Encoding.ASCII.GetBytes(chunkSize.ToString("x2"));
......
using System; using System.Globalization;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Titanium.Web.Proxy.Extensions namespace Titanium.Web.Proxy.Extensions
{ {
......
...@@ -19,18 +19,18 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -19,18 +19,18 @@ namespace Titanium.Web.Proxy.Helpers
private readonly Encoding encoding; private readonly Encoding encoding;
[ThreadStatic] [ThreadStatic]
private static byte[] staticBuffer; private static byte[] staticBufferField;
private byte[] buffer private byte[] staticBuffer
{ {
get get
{ {
if (staticBuffer == null || staticBuffer.Length != bufferSize) if (staticBufferField == null || staticBufferField.Length != bufferSize)
{ {
staticBuffer = new byte[bufferSize]; staticBufferField = new byte[bufferSize];
} }
return staticBuffer; return staticBufferField;
} }
} }
...@@ -56,7 +56,7 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -56,7 +56,7 @@ namespace Titanium.Web.Proxy.Helpers
int bufferDataLength = 0; int bufferDataLength = 0;
// try to use the thread static buffer, usually it is enough // try to use the thread static buffer, usually it is enough
var buffer = this.buffer; var buffer = staticBuffer;
while (stream.DataAvailable || await stream.FillBufferAsync()) while (stream.DataAvailable || await stream.FillBufferAsync())
{ {
...@@ -117,22 +117,16 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -117,22 +117,16 @@ namespace Titanium.Web.Proxy.Helpers
/// <summary> /// <summary>
/// Read the specified number of raw bytes from the base stream /// Read the specified number of raw bytes from the base stream
/// </summary> /// </summary>
/// <param name="bufferSize"></param>
/// <param name="totalBytesToRead"></param> /// <param name="totalBytesToRead"></param>
/// <returns></returns> /// <returns></returns>
internal async Task<byte[]> ReadBytesAsync(int bufferSize, long totalBytesToRead) internal async Task<byte[]> ReadBytesAsync(long totalBytesToRead)
{ {
int bytesToRead = bufferSize; int bytesToRead = bufferSize;
if (totalBytesToRead < bufferSize) if (totalBytesToRead < bufferSize)
bytesToRead = (int)totalBytesToRead; bytesToRead = (int)totalBytesToRead;
var buffer = this.buffer; var buffer = staticBuffer;
if (bytesToRead > buffer.Length)
{
buffer = new byte[bytesToRead];
}
int bytesRead; int bytesRead;
var totalBytesRead = 0; var totalBytesRead = 0;
......
...@@ -16,7 +16,7 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -16,7 +16,7 @@ namespace Titanium.Web.Proxy.Helpers
{ {
private readonly Stream baseStream; private readonly Stream baseStream;
private readonly byte[] buffer; private readonly byte[] streamBuffer;
private int bufferLength; private int bufferLength;
...@@ -30,7 +30,7 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -30,7 +30,7 @@ namespace Titanium.Web.Proxy.Helpers
public CustomBufferedStream(Stream baseStream, int bufferSize) public CustomBufferedStream(Stream baseStream, int bufferSize)
{ {
this.baseStream = baseStream; this.baseStream = baseStream;
buffer = new byte[bufferSize]; streamBuffer = new byte[bufferSize];
} }
/// <summary> /// <summary>
...@@ -84,7 +84,7 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -84,7 +84,7 @@ namespace Titanium.Web.Proxy.Helpers
int available = Math.Min(bufferLength, count); int available = Math.Min(bufferLength, count);
if (available > 0) if (available > 0)
{ {
Buffer.BlockCopy(this.buffer, bufferPos, buffer, offset, available); Buffer.BlockCopy(streamBuffer, bufferPos, buffer, offset, available);
bufferPos += available; bufferPos += available;
bufferLength -= available; bufferLength -= available;
} }
...@@ -120,7 +120,7 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -120,7 +120,7 @@ namespace Titanium.Web.Proxy.Helpers
if (bufferLength > 0) if (bufferLength > 0)
{ {
int available = Math.Min(bufferLength, count); int available = Math.Min(bufferLength, count);
Buffer.BlockCopy(this.buffer, bufferPos, buffer, offset, available); Buffer.BlockCopy(streamBuffer, bufferPos, buffer, offset, available);
bufferPos += available; bufferPos += available;
bufferLength -= available; bufferLength -= available;
return new ReadAsyncResult(available); return new ReadAsyncResult(available);
...@@ -167,7 +167,7 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -167,7 +167,7 @@ namespace Titanium.Web.Proxy.Helpers
{ {
if (bufferLength > 0) if (bufferLength > 0)
{ {
await destination.WriteAsync(buffer, bufferPos, bufferLength, cancellationToken); await destination.WriteAsync(streamBuffer, bufferPos, bufferLength, cancellationToken);
} }
await baseStream.CopyToAsync(destination, bufferSize, cancellationToken); await baseStream.CopyToAsync(destination, bufferSize, cancellationToken);
...@@ -256,7 +256,7 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -256,7 +256,7 @@ namespace Titanium.Web.Proxy.Helpers
int available = Math.Min(bufferLength, count); int available = Math.Min(bufferLength, count);
if (available > 0) if (available > 0)
{ {
Buffer.BlockCopy(this.buffer, bufferPos, buffer, offset, available); Buffer.BlockCopy(streamBuffer, bufferPos, buffer, offset, available);
bufferPos += available; bufferPos += available;
bufferLength -= available; bufferLength -= available;
} }
...@@ -283,7 +283,7 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -283,7 +283,7 @@ namespace Titanium.Web.Proxy.Helpers
} }
bufferLength--; bufferLength--;
return buffer[bufferPos++]; return streamBuffer[bufferPos++];
} }
public byte ReadByteFromBuffer() public byte ReadByteFromBuffer()
...@@ -294,7 +294,7 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -294,7 +294,7 @@ namespace Titanium.Web.Proxy.Helpers
} }
bufferLength--; bufferLength--;
return buffer[bufferPos++]; return streamBuffer[bufferPos++];
} }
/// <summary> /// <summary>
...@@ -390,7 +390,7 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -390,7 +390,7 @@ namespace Titanium.Web.Proxy.Helpers
/// </summary> /// </summary>
public bool FillBuffer() public bool FillBuffer()
{ {
bufferLength = baseStream.Read(buffer, 0, buffer.Length); bufferLength = baseStream.Read(streamBuffer, 0, streamBuffer.Length);
bufferPos = 0; bufferPos = 0;
return bufferLength > 0; return bufferLength > 0;
} }
...@@ -411,7 +411,7 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -411,7 +411,7 @@ namespace Titanium.Web.Proxy.Helpers
/// <returns></returns> /// <returns></returns>
public async Task<bool> FillBufferAsync(CancellationToken cancellationToken) public async Task<bool> FillBufferAsync(CancellationToken cancellationToken)
{ {
bufferLength = await baseStream.ReadAsync(buffer, 0, buffer.Length, cancellationToken); bufferLength = await baseStream.ReadAsync(streamBuffer, 0, streamBuffer.Length, cancellationToken);
bufferPos = 0; bufferPos = 0;
return bufferLength > 0; return bufferLength > 0;
} }
......
...@@ -55,7 +55,7 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -55,7 +55,7 @@ namespace Titanium.Web.Proxy.Helpers
{ {
localhost = Dns.GetHostEntry(Dns.GetHostName()); localhost = Dns.GetHostEntry(Dns.GetHostName());
IPAddress ipAddress = null; IPAddress ipAddress;
if (IPAddress.TryParse(hostName, out ipAddress)) if (IPAddress.TryParse(hostName, out ipAddress))
isLocalhost = localhost.AddressList.Any(x => x.Equals(ipAddress)); isLocalhost = localhost.AddressList.Any(x => x.Equals(ipAddress));
......
...@@ -21,9 +21,9 @@ namespace Titanium.Web.Proxy.Models ...@@ -21,9 +21,9 @@ namespace Titanium.Web.Proxy.Models
/// <param name="enableSsl"></param> /// <param name="enableSsl"></param>
protected ProxyEndPoint(IPAddress ipAddress, int port, bool enableSsl) protected ProxyEndPoint(IPAddress ipAddress, int port, bool enableSsl)
{ {
this.IpAddress = ipAddress; IpAddress = ipAddress;
this.Port = port; Port = port;
this.EnableSsl = enableSsl; EnableSsl = enableSsl;
} }
/// <summary> /// <summary>
...@@ -55,8 +55,8 @@ namespace Titanium.Web.Proxy.Models ...@@ -55,8 +55,8 @@ namespace Titanium.Web.Proxy.Models
/// </summary> /// </summary>
public class ExplicitProxyEndPoint : ProxyEndPoint public class ExplicitProxyEndPoint : ProxyEndPoint
{ {
internal List<Regex> excludedHttpsHostNameRegex; internal List<Regex> ExcludedHttpsHostNameRegexList;
internal List<Regex> includedHttpsHostNameRegex; internal List<Regex> IncludedHttpsHostNameRegexList;
internal bool IsSystemHttpProxy { get; set; } internal bool IsSystemHttpProxy { get; set; }
...@@ -67,7 +67,7 @@ namespace Titanium.Web.Proxy.Models ...@@ -67,7 +67,7 @@ namespace Titanium.Web.Proxy.Models
/// </summary> /// </summary>
public IEnumerable<string> ExcludedHttpsHostNameRegex public IEnumerable<string> ExcludedHttpsHostNameRegex
{ {
get { return excludedHttpsHostNameRegex?.Select(x => x.ToString()).ToList(); } get { return ExcludedHttpsHostNameRegexList?.Select(x => x.ToString()).ToList(); }
set set
{ {
if (IncludedHttpsHostNameRegex != null) if (IncludedHttpsHostNameRegex != null)
...@@ -75,7 +75,7 @@ namespace Titanium.Web.Proxy.Models ...@@ -75,7 +75,7 @@ namespace Titanium.Web.Proxy.Models
throw new ArgumentException("Cannot set excluded when included is set"); throw new ArgumentException("Cannot set excluded when included is set");
} }
excludedHttpsHostNameRegex = value?.Select(x=>new Regex(x, RegexOptions.Compiled)).ToList(); ExcludedHttpsHostNameRegexList = value?.Select(x=>new Regex(x, RegexOptions.Compiled)).ToList();
} }
} }
...@@ -84,7 +84,7 @@ namespace Titanium.Web.Proxy.Models ...@@ -84,7 +84,7 @@ namespace Titanium.Web.Proxy.Models
/// </summary> /// </summary>
public IEnumerable<string> IncludedHttpsHostNameRegex public IEnumerable<string> IncludedHttpsHostNameRegex
{ {
get { return includedHttpsHostNameRegex?.Select(x => x.ToString()).ToList(); } get { return IncludedHttpsHostNameRegexList?.Select(x => x.ToString()).ToList(); }
set set
{ {
if (ExcludedHttpsHostNameRegex != null) if (ExcludedHttpsHostNameRegex != null)
...@@ -92,7 +92,7 @@ namespace Titanium.Web.Proxy.Models ...@@ -92,7 +92,7 @@ namespace Titanium.Web.Proxy.Models
throw new ArgumentException("Cannot set included when excluded is set"); throw new ArgumentException("Cannot set included when excluded is set");
} }
includedHttpsHostNameRegex = value?.Select(x => new Regex(x, RegexOptions.Compiled)).ToList(); IncludedHttpsHostNameRegexList = value?.Select(x => new Regex(x, RegexOptions.Compiled)).ToList();
} }
} }
...@@ -136,7 +136,7 @@ namespace Titanium.Web.Proxy.Models ...@@ -136,7 +136,7 @@ namespace Titanium.Web.Proxy.Models
public TransparentProxyEndPoint(IPAddress ipAddress, int port, bool enableSsl) public TransparentProxyEndPoint(IPAddress ipAddress, int port, bool enableSsl)
: base(ipAddress, port, enableSsl) : base(ipAddress, port, enableSsl)
{ {
this.GenericCertificateName = "localhost"; GenericCertificateName = "localhost";
} }
} }
......
...@@ -181,7 +181,7 @@ namespace Titanium.Web.Proxy.Network.Certificate ...@@ -181,7 +181,7 @@ namespace Titanium.Web.Proxy.Network.Certificate
} }
}); });
manualResetEvent.Wait(TimeSpan.FromMinutes(1), cancellationToken: cancellationToken); manualResetEvent.Wait(TimeSpan.FromMinutes(1), cancellationToken);
} }
return certificate; return certificate;
......
...@@ -204,14 +204,13 @@ namespace Titanium.Web.Proxy.Network ...@@ -204,14 +204,13 @@ namespace Titanium.Web.Proxy.Network
/// <summary> /// <summary>
/// Trusts the root certificate. /// Trusts the root certificate.
/// </summary> /// </summary>
/// <param name="exceptionFunc"></param> internal void TrustRootCertificate()
internal void TrustRootCertificate(Action<Exception> exceptionFunc)
{ {
//current user //current user
TrustRootCertificate(StoreLocation.CurrentUser, exceptionFunc); TrustRootCertificate(StoreLocation.CurrentUser);
//current system //current system
TrustRootCertificate(StoreLocation.LocalMachine, exceptionFunc); TrustRootCertificate(StoreLocation.LocalMachine);
} }
/// <summary> /// <summary>
...@@ -300,10 +299,8 @@ namespace Titanium.Web.Proxy.Network ...@@ -300,10 +299,8 @@ namespace Titanium.Web.Proxy.Network
/// Make current machine trust the Root Certificate used by this proxy /// Make current machine trust the Root Certificate used by this proxy
/// </summary> /// </summary>
/// <param name="storeLocation"></param> /// <param name="storeLocation"></param>
/// <param name="exceptionFunc"></param>
/// <returns></returns> /// <returns></returns>
internal void TrustRootCertificate(StoreLocation storeLocation, internal void TrustRootCertificate(StoreLocation storeLocation)
Action<Exception> exceptionFunc)
{ {
if (RootCertificate == null) if (RootCertificate == null)
{ {
......
...@@ -16,6 +16,7 @@ namespace Titanium.Web.Proxy.Network.Tcp ...@@ -16,6 +16,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
internal ExternalProxy UpStreamHttpsProxy { get; set; } internal ExternalProxy UpStreamHttpsProxy { get; set; }
internal string HostName { get; set; } internal string HostName { get; set; }
internal int Port { get; set; } internal int Port { get; set; }
internal bool IsHttps { get; set; } internal bool IsHttps { get; set; }
...@@ -58,7 +59,6 @@ namespace Titanium.Web.Proxy.Network.Tcp ...@@ -58,7 +59,6 @@ namespace Titanium.Web.Proxy.Network.Tcp
TcpClient.LingerState = new LingerOption(true, 0); TcpClient.LingerState = new LingerOption(true, 0);
TcpClient.Close(); TcpClient.Close();
} }
} }
} }
...@@ -264,6 +264,15 @@ namespace Titanium.Web.Proxy ...@@ -264,6 +264,15 @@ namespace Titanium.Web.Proxy
#endif #endif
certificateManager = new CertificateManager(ExceptionFunc); certificateManager = new CertificateManager(ExceptionFunc);
if (rootCertificateName != null)
{
RootCertificateName = rootCertificateName;
}
if (rootCertificateIssuerName != null)
{
RootCertificateIssuerName = rootCertificateIssuerName;
}
} }
/// <summary> /// <summary>
...@@ -556,7 +565,7 @@ namespace Titanium.Web.Proxy ...@@ -556,7 +565,7 @@ namespace Titanium.Web.Proxy
if (TrustRootCertificate) if (TrustRootCertificate)
{ {
certificateManager.TrustRootCertificate(ExceptionFunc); certificateManager.TrustRootCertificate();
} }
} }
} }
......
...@@ -75,12 +75,12 @@ namespace Titanium.Web.Proxy ...@@ -75,12 +75,12 @@ namespace Titanium.Web.Proxy
if (endPoint.ExcludedHttpsHostNameRegex != null) if (endPoint.ExcludedHttpsHostNameRegex != null)
{ {
excluded = endPoint.excludedHttpsHostNameRegex.Any(x => x.IsMatch(httpRemoteUri.Host)); excluded = endPoint.ExcludedHttpsHostNameRegexList.Any(x => x.IsMatch(httpRemoteUri.Host));
} }
if (endPoint.IncludedHttpsHostNameRegex != null) if (endPoint.IncludedHttpsHostNameRegex != null)
{ {
excluded = !endPoint.includedHttpsHostNameRegex.Any(x => x.IsMatch(httpRemoteUri.Host)); excluded = !endPoint.IncludedHttpsHostNameRegexList.Any(x => x.IsMatch(httpRemoteUri.Host));
} }
List<HttpHeader> connectRequestHeaders = null; List<HttpHeader> connectRequestHeaders = null;
......
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