Unverified Commit ae9e8501 authored by Jehonathan Thomas's avatar Jehonathan Thomas Committed by GitHub

Merge pull request #581 from honfika/master

typo fixes, add some missing xml comment for method arguments, fix the wpf test project (invalid cast exception)
parents 7b792b3f 1d038a36
...@@ -4,7 +4,7 @@ using System.Runtime.InteropServices; ...@@ -4,7 +4,7 @@ using System.Runtime.InteropServices;
namespace Titanium.Web.Proxy.Examples.Basic.Helpers namespace Titanium.Web.Proxy.Examples.Basic.Helpers
{ {
/// <summary> /// <summary>
/// Adapated from /// Adapted from
/// http://stackoverflow.com/questions/13656846/how-to-programmatic-disable-c-sharp-console-applications-quick-edit-mode /// http://stackoverflow.com/questions/13656846/how-to-programmatic-disable-c-sharp-console-applications-quick-edit-mode
/// </summary> /// </summary>
internal static class ConsoleHelper internal static class ConsoleHelper
......
...@@ -32,11 +32,11 @@ namespace Titanium.Web.Proxy.Examples.Basic ...@@ -32,11 +32,11 @@ namespace Titanium.Web.Proxy.Examples.Basic
{ {
if (exception is ProxyHttpException phex) if (exception is ProxyHttpException phex)
{ {
await WriteToConsole(exception.Message + ": " + phex.InnerException?.Message, true); await writeToConsole(exception.Message + ": " + phex.InnerException?.Message, true);
} }
else else
{ {
await WriteToConsole(exception.Message, true); await writeToConsole(exception.Message, true);
} }
}; };
proxyServer.ForwardToUpstreamGateway = true; proxyServer.ForwardToUpstreamGateway = true;
...@@ -52,8 +52,8 @@ namespace Titanium.Web.Proxy.Examples.Basic ...@@ -52,8 +52,8 @@ namespace Titanium.Web.Proxy.Examples.Basic
public void StartProxy() public void StartProxy()
{ {
proxyServer.BeforeRequest += OnRequest; proxyServer.BeforeRequest += onRequest;
proxyServer.BeforeResponse += OnResponse; proxyServer.BeforeResponse += onResponse;
proxyServer.ServerCertificateValidationCallback += OnCertificateValidation; proxyServer.ServerCertificateValidationCallback += OnCertificateValidation;
proxyServer.ClientCertificateSelectionCallback += OnCertificateSelection; proxyServer.ClientCertificateSelectionCallback += OnCertificateSelection;
...@@ -63,8 +63,8 @@ namespace Titanium.Web.Proxy.Examples.Basic ...@@ -63,8 +63,8 @@ namespace Titanium.Web.Proxy.Examples.Basic
explicitEndPoint = new ExplicitProxyEndPoint(IPAddress.Any, 8000); explicitEndPoint = new ExplicitProxyEndPoint(IPAddress.Any, 8000);
// Fired when a CONNECT request is received // Fired when a CONNECT request is received
explicitEndPoint.BeforeTunnelConnectRequest += OnBeforeTunnelConnectRequest; explicitEndPoint.BeforeTunnelConnectRequest += onBeforeTunnelConnectRequest;
explicitEndPoint.BeforeTunnelConnectResponse += OnBeforeTunnelConnectResponse; explicitEndPoint.BeforeTunnelConnectResponse += onBeforeTunnelConnectResponse;
// An explicit endpoint is where the client knows about the existence of a proxy // An explicit endpoint is where the client knows about the existence of a proxy
// So client sends request in a proxy friendly manner // So client sends request in a proxy friendly manner
...@@ -102,11 +102,11 @@ namespace Titanium.Web.Proxy.Examples.Basic ...@@ -102,11 +102,11 @@ namespace Titanium.Web.Proxy.Examples.Basic
public void Stop() public void Stop()
{ {
explicitEndPoint.BeforeTunnelConnectRequest -= OnBeforeTunnelConnectRequest; explicitEndPoint.BeforeTunnelConnectRequest -= onBeforeTunnelConnectRequest;
explicitEndPoint.BeforeTunnelConnectResponse -= OnBeforeTunnelConnectResponse; explicitEndPoint.BeforeTunnelConnectResponse -= onBeforeTunnelConnectResponse;
proxyServer.BeforeRequest -= OnRequest; proxyServer.BeforeRequest -= onRequest;
proxyServer.BeforeResponse -= OnResponse; proxyServer.BeforeResponse -= onResponse;
proxyServer.ServerCertificateValidationCallback -= OnCertificateValidation; proxyServer.ServerCertificateValidationCallback -= OnCertificateValidation;
proxyServer.ClientCertificateSelectionCallback -= OnCertificateSelection; proxyServer.ClientCertificateSelectionCallback -= OnCertificateSelection;
...@@ -116,10 +116,10 @@ namespace Titanium.Web.Proxy.Examples.Basic ...@@ -116,10 +116,10 @@ namespace Titanium.Web.Proxy.Examples.Basic
//proxyServer.CertificateManager.RemoveTrustedRootCertificates(); //proxyServer.CertificateManager.RemoveTrustedRootCertificates();
} }
private async Task OnBeforeTunnelConnectRequest(object sender, TunnelConnectSessionEventArgs e) private async Task onBeforeTunnelConnectRequest(object sender, TunnelConnectSessionEventArgs e)
{ {
string hostname = e.HttpClient.Request.RequestUri.Host; string hostname = e.HttpClient.Request.RequestUri.Host;
await WriteToConsole("Tunnel to: " + hostname); await writeToConsole("Tunnel to: " + hostname);
if (hostname.Contains("dropbox.com")) if (hostname.Contains("dropbox.com"))
{ {
...@@ -130,16 +130,16 @@ namespace Titanium.Web.Proxy.Examples.Basic ...@@ -130,16 +130,16 @@ namespace Titanium.Web.Proxy.Examples.Basic
} }
} }
private Task OnBeforeTunnelConnectResponse(object sender, TunnelConnectSessionEventArgs e) private Task onBeforeTunnelConnectResponse(object sender, TunnelConnectSessionEventArgs e)
{ {
return Task.FromResult(false); return Task.FromResult(false);
} }
// intecept & cancel redirect or update requests // intecept & cancel redirect or update requests
private async Task OnRequest(object sender, SessionEventArgs e) private async Task onRequest(object sender, SessionEventArgs e)
{ {
await WriteToConsole("Active Client Connections:" + ((ProxyServer)sender).ClientConnectionCount); await writeToConsole("Active Client Connections:" + ((ProxyServer)sender).ClientConnectionCount);
await WriteToConsole(e.HttpClient.Request.Url); await writeToConsole(e.HttpClient.Request.Url);
// store it in the UserData property // store it in the UserData property
// It can be a simple integer, Guid, or any type // It can be a simple integer, Guid, or any type
...@@ -177,19 +177,19 @@ namespace Titanium.Web.Proxy.Examples.Basic ...@@ -177,19 +177,19 @@ namespace Titanium.Web.Proxy.Examples.Basic
} }
// Modify response // Modify response
private async Task MultipartRequestPartSent(object sender, MultipartRequestPartSentEventArgs e) private async Task multipartRequestPartSent(object sender, MultipartRequestPartSentEventArgs e)
{ {
var session = (SessionEventArgs)sender; var session = (SessionEventArgs)sender;
await WriteToConsole("Multipart form data headers:"); await writeToConsole("Multipart form data headers:");
foreach (var header in e.Headers) foreach (var header in e.Headers)
{ {
await WriteToConsole(header.ToString()); await writeToConsole(header.ToString());
} }
} }
private async Task OnResponse(object sender, SessionEventArgs e) private async Task onResponse(object sender, SessionEventArgs e)
{ {
await WriteToConsole("Active Server Connections:" + ((ProxyServer)sender).ServerConnectionCount); await writeToConsole("Active Server Connections:" + ((ProxyServer)sender).ServerConnectionCount);
string ext = System.IO.Path.GetExtension(e.HttpClient.Request.RequestUri.AbsolutePath); string ext = System.IO.Path.GetExtension(e.HttpClient.Request.RequestUri.AbsolutePath);
...@@ -261,7 +261,7 @@ namespace Titanium.Web.Proxy.Examples.Basic ...@@ -261,7 +261,7 @@ namespace Titanium.Web.Proxy.Examples.Basic
return Task.FromResult(0); return Task.FromResult(0);
} }
private async Task WriteToConsole(string message, bool useRedColor = false) private async Task writeToConsole(string message, bool useRedColor = false)
{ {
await @lock.WaitAsync(); await @lock.WaitAsync();
......
...@@ -106,7 +106,7 @@ namespace Titanium.Web.Proxy.Examples.Wpf ...@@ -106,7 +106,7 @@ namespace Titanium.Web.Proxy.Examples.Wpf
if (value != selectedSession) if (value != selectedSession)
{ {
selectedSession = value; selectedSession = value;
SelectedSessionChanged(); selectedSessionChanged();
} }
} }
} }
...@@ -131,7 +131,7 @@ namespace Titanium.Web.Proxy.Examples.Wpf ...@@ -131,7 +131,7 @@ namespace Titanium.Web.Proxy.Examples.Wpf
e.DecryptSsl = false; e.DecryptSsl = false;
} }
await Dispatcher.InvokeAsync(() => { AddSession(e); }); await Dispatcher.InvokeAsync(() => { addSession(e); });
} }
private async Task ProxyServer_BeforeTunnelConnectResponse(object sender, TunnelConnectSessionEventArgs e) private async Task ProxyServer_BeforeTunnelConnectResponse(object sender, TunnelConnectSessionEventArgs e)
...@@ -148,7 +148,7 @@ namespace Titanium.Web.Proxy.Examples.Wpf ...@@ -148,7 +148,7 @@ namespace Titanium.Web.Proxy.Examples.Wpf
private async Task ProxyServer_BeforeRequest(object sender, SessionEventArgs e) private async Task ProxyServer_BeforeRequest(object sender, SessionEventArgs e)
{ {
SessionListItem item = null; SessionListItem item = null;
await Dispatcher.InvokeAsync(() => { item = AddSession(e); }); await Dispatcher.InvokeAsync(() => { item = addSession(e); });
if (e.HttpClient.Request.HasBody) if (e.HttpClient.Request.HasBody)
{ {
...@@ -191,15 +191,15 @@ namespace Titanium.Web.Proxy.Examples.Wpf ...@@ -191,15 +191,15 @@ namespace Titanium.Web.Proxy.Examples.Wpf
}); });
} }
private SessionListItem AddSession(SessionEventArgsBase e) private SessionListItem addSession(SessionEventArgsBase e)
{ {
var item = CreateSessionListItem(e); var item = createSessionListItem(e);
Sessions.Add(item); Sessions.Add(item);
sessionDictionary.Add(e.HttpClient, item); sessionDictionary.Add(e.HttpClient, item);
return item; return item;
} }
private SessionListItem CreateSessionListItem(SessionEventArgsBase e) private SessionListItem createSessionListItem(SessionEventArgsBase e)
{ {
lastSessionNumber++; lastSessionNumber++;
bool isTunnelConnect = e is TunnelConnectSessionEventArgs; bool isTunnelConnect = e is TunnelConnectSessionEventArgs;
...@@ -214,7 +214,7 @@ namespace Titanium.Web.Proxy.Examples.Wpf ...@@ -214,7 +214,7 @@ namespace Titanium.Web.Proxy.Examples.Wpf
{ {
e.DataReceived += (sender, args) => e.DataReceived += (sender, args) =>
{ {
var session = (SessionEventArgs)sender; var session = (SessionEventArgsBase)sender;
if (sessionDictionary.TryGetValue(session.HttpClient, out var li)) if (sessionDictionary.TryGetValue(session.HttpClient, out var li))
{ {
li.ReceivedDataCount += args.Count; li.ReceivedDataCount += args.Count;
...@@ -223,7 +223,7 @@ namespace Titanium.Web.Proxy.Examples.Wpf ...@@ -223,7 +223,7 @@ namespace Titanium.Web.Proxy.Examples.Wpf
e.DataSent += (sender, args) => e.DataSent += (sender, args) =>
{ {
var session = (SessionEventArgs)sender; var session = (SessionEventArgsBase)sender;
if (sessionDictionary.TryGetValue(session.HttpClient, out var li)) if (sessionDictionary.TryGetValue(session.HttpClient, out var li))
{ {
li.SentDataCount += args.Count; li.SentDataCount += args.Count;
...@@ -248,7 +248,7 @@ namespace Titanium.Web.Proxy.Examples.Wpf ...@@ -248,7 +248,7 @@ namespace Titanium.Web.Proxy.Examples.Wpf
} }
} }
private void SelectedSessionChanged() private void selectedSessionChanged()
{ {
if (SelectedSession == null) if (SelectedSession == null)
{ {
......
...@@ -73,7 +73,7 @@ namespace Titanium.Web.Proxy.Examples.Wpf.Annotations ...@@ -73,7 +73,7 @@ namespace Titanium.Web.Proxy.Examples.Wpf.Annotations
} }
/// <summary> /// <summary>
/// Can be appplied to symbols of types derived from IEnumerable as well as to symbols of Task /// Can be applied to symbols of types derived from IEnumerable as well as to symbols of Task
/// and Lazy classes to indicate that the value of a collection item, of the Task.Result property /// and Lazy classes to indicate that the value of a collection item, of the Task.Result property
/// or of the Lazy.Value property can never be null. /// or of the Lazy.Value property can never be null.
/// </summary> /// </summary>
...@@ -85,7 +85,7 @@ namespace Titanium.Web.Proxy.Examples.Wpf.Annotations ...@@ -85,7 +85,7 @@ namespace Titanium.Web.Proxy.Examples.Wpf.Annotations
} }
/// <summary> /// <summary>
/// Can be appplied to symbols of types derived from IEnumerable as well as to symbols of Task /// Can be applied to symbols of types derived from IEnumerable as well as to symbols of Task
/// and Lazy classes to indicate that the value of a collection item, of the Task.Result property /// and Lazy classes to indicate that the value of a collection item, of the Task.Result property
/// or of the Lazy.Value property can be null. /// or of the Lazy.Value property can be null.
/// </summary> /// </summary>
...@@ -251,7 +251,7 @@ namespace Titanium.Web.Proxy.Examples.Wpf.Annotations ...@@ -251,7 +251,7 @@ namespace Titanium.Web.Proxy.Examples.Wpf.Annotations
/// </list> /// </list>
/// If method has single input parameter, it's name could be omitted.<br /> /// If method has single input parameter, it's name could be omitted.<br />
/// Using <c>halt</c> (or <c>void</c>/<c>nothing</c>, which is the same) for method output /// Using <c>halt</c> (or <c>void</c>/<c>nothing</c>, which is the same) for method output
/// means that the methos doesn't return normally (throws or terminates the process).<br /> /// means that the method doesn't return normally (throws or terminates the process).<br />
/// Value <c>canbenull</c> is only applicable for output parameters.<br /> /// Value <c>canbenull</c> is only applicable for output parameters.<br />
/// You can use multiple <c>[ContractAnnotation]</c> for each FDT row, or use single attribute /// You can use multiple <c>[ContractAnnotation]</c> for each FDT row, or use single attribute
/// with rows separated by semicolon. There is no notion of order rows, all rows are checked /// with rows separated by semicolon. There is no notion of order rows, all rows are checked
......
...@@ -19,16 +19,19 @@ ...@@ -19,16 +19,19 @@
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=MTA/@EntryIndexedValue">MTA</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/=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/Abbreviations/=OIDS/@EntryIndexedValue">OIDS</s:String>
<s:Boolean x:Key="/Default/CodeStyle/Naming/CSharpNaming/ApplyAutoDetectedRules/@EntryValue">False</s:Boolean>
<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>
<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/PredefinedNamingRules/=PublicFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/UserRules/=a4ab2e69_002D4d9c_002D4345_002Dbcd1_002D5541dacf5d38/@EntryIndexedValue">&lt;Policy&gt;&lt;Descriptor Staticness="Static, Instance" AccessRightKinds="Private" Description="Method (private)"&gt;&lt;ElementKinds&gt;&lt;Kind Name="METHOD" /&gt;&lt;/ElementKinds&gt;&lt;/Descriptor&gt;&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;&lt;/Policy&gt;</s:String> <s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/UserRules/=a4ab2e69_002D4d9c_002D4345_002Dbcd1_002D5541dacf5d38/@EntryIndexedValue">&lt;Policy&gt;&lt;Descriptor Staticness="Static, Instance" AccessRightKinds="Private" Description="Method (private)"&gt;&lt;ElementKinds&gt;&lt;Kind Name="METHOD" /&gt;&lt;/ElementKinds&gt;&lt;/Descriptor&gt;&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;&lt;/Policy&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> <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>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpAttributeForSingleLineMethodUpgrade/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpAttributeForSingleLineMethodUpgrade/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpKeepExistingMigration/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpKeepExistingMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpPlaceEmbeddedOnSameLineMigration/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpPlaceEmbeddedOnSameLineMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpRenamePlacementToArrangementMigration/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpRenamePlacementToArrangementMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpUseContinuousIndentInsideBracesMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EAddAccessorOwnerDeclarationBracesMigration/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EAddAccessorOwnerDeclarationBracesMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002ECSharpPlaceAttributeOnSameLineMigration/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002ECSharpPlaceAttributeOnSameLineMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean>
......
...@@ -29,7 +29,7 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -29,7 +29,7 @@ namespace Titanium.Web.Proxy.EventArguments
public X509Certificate RemoteCertificate { get; internal set; } public X509Certificate RemoteCertificate { get; internal set; }
/// <summary> /// <summary>
/// Acceptable issuers as listed by remoted server. /// Acceptable issuers as listed by remote server.
/// </summary> /// </summary>
public string[] AcceptableIssuers { get; internal set; } public string[] AcceptableIssuers { get; internal set; }
......
...@@ -117,7 +117,7 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -117,7 +117,7 @@ namespace Titanium.Web.Proxy.EventArguments
} }
catch (Exception ex) catch (Exception ex)
{ {
exceptionFunc(new Exception("Exception thrown in user event", ex)); ExceptionFunc(new Exception("Exception thrown in user event", ex));
} }
} }
...@@ -154,7 +154,7 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -154,7 +154,7 @@ namespace Titanium.Web.Proxy.EventArguments
{ {
using (var bodyStream = new MemoryStream()) using (var bodyStream = new MemoryStream())
{ {
var writer = new HttpWriter(bodyStream, bufferPool, bufferSize); var writer = new HttpWriter(bodyStream, BufferPool, BufferSize);
if (isRequest) if (isRequest)
{ {
...@@ -186,7 +186,7 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -186,7 +186,7 @@ namespace Titanium.Web.Proxy.EventArguments
using (var bodyStream = new MemoryStream()) using (var bodyStream = new MemoryStream())
{ {
var writer = new HttpWriter(bodyStream, bufferPool, bufferSize); var writer = new HttpWriter(bodyStream, BufferPool, BufferSize);
await copyBodyAsync(isRequest, true, writer, TransformationMode.None, null, cancellationToken); await copyBodyAsync(isRequest, true, writer, TransformationMode.None, null, cancellationToken);
} }
} }
...@@ -207,7 +207,7 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -207,7 +207,7 @@ namespace Titanium.Web.Proxy.EventArguments
var reader = getStreamReader(true); var reader = getStreamReader(true);
string boundary = HttpHelper.GetBoundaryFromContentType(request.ContentType); string boundary = HttpHelper.GetBoundaryFromContentType(request.ContentType);
using (var copyStream = new CopyStream(reader, writer, bufferPool, bufferSize)) using (var copyStream = new CopyStream(reader, writer, BufferPool, BufferSize))
{ {
while (contentLength > copyStream.ReadBytes) while (contentLength > copyStream.ReadBytes)
{ {
...@@ -259,7 +259,7 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -259,7 +259,7 @@ namespace Titanium.Web.Proxy.EventArguments
string contentEncoding = useOriginalHeaderValues ? requestResponse.OriginalContentEncoding : requestResponse.ContentEncoding; string contentEncoding = useOriginalHeaderValues ? requestResponse.OriginalContentEncoding : requestResponse.ContentEncoding;
Stream s = limitedStream = new LimitedStream(stream, bufferPool, isChunked, contentLength); Stream s = limitedStream = new LimitedStream(stream, BufferPool, isChunked, contentLength);
if (transformation == TransformationMode.Uncompress && contentEncoding != null) if (transformation == TransformationMode.Uncompress && contentEncoding != null)
{ {
...@@ -268,7 +268,7 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -268,7 +268,7 @@ namespace Titanium.Web.Proxy.EventArguments
try try
{ {
using (var bufStream = new CustomBufferedStream(s, bufferPool, bufferSize, true)) using (var bufStream = new CustomBufferedStream(s, BufferPool, BufferSize, true))
{ {
await writer.CopyBodyAsync(bufStream, false, -1, onCopy, cancellationToken); await writer.CopyBodyAsync(bufStream, false, -1, onCopy, cancellationToken);
} }
...@@ -290,7 +290,7 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -290,7 +290,7 @@ namespace Titanium.Web.Proxy.EventArguments
{ {
int bufferDataLength = 0; int bufferDataLength = 0;
var buffer = bufferPool.GetBuffer(bufferSize); var buffer = BufferPool.GetBuffer(BufferSize);
try try
{ {
int boundaryLength = boundary.Length + 4; int boundaryLength = boundary.Length + 4;
...@@ -340,7 +340,7 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -340,7 +340,7 @@ namespace Titanium.Web.Proxy.EventArguments
} }
finally finally
{ {
bufferPool.ReturnBuffer(buffer); BufferPool.ReturnBuffer(buffer);
} }
} }
......
...@@ -24,9 +24,9 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -24,9 +24,9 @@ namespace Titanium.Web.Proxy.EventArguments
internal TcpServerConnection ServerConnection => HttpClient.Connection; internal TcpServerConnection ServerConnection => HttpClient.Connection;
internal TcpClientConnection ClientConnection => ProxyClient.Connection; internal TcpClientConnection ClientConnection => ProxyClient.Connection;
protected readonly int bufferSize; protected readonly int BufferSize;
protected readonly IBufferPool bufferPool; protected readonly IBufferPool BufferPool;
protected readonly ExceptionHandler exceptionFunc; protected readonly ExceptionHandler ExceptionFunc;
/// <summary> /// <summary>
/// Relative milliseconds for various events. /// Relative milliseconds for various events.
...@@ -39,9 +39,9 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -39,9 +39,9 @@ namespace Titanium.Web.Proxy.EventArguments
private SessionEventArgsBase(ProxyServer server, ProxyEndPoint endPoint, private SessionEventArgsBase(ProxyServer server, ProxyEndPoint endPoint,
CancellationTokenSource cancellationTokenSource) CancellationTokenSource cancellationTokenSource)
{ {
bufferSize = server.BufferSize; BufferSize = server.BufferSize;
bufferPool = server.BufferPool; BufferPool = server.BufferPool;
exceptionFunc = server.ExceptionFunc; ExceptionFunc = server.ExceptionFunc;
TimeLine["Session Created"] = DateTime.Now; TimeLine["Session Created"] = DateTime.Now;
} }
...@@ -161,7 +161,7 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -161,7 +161,7 @@ namespace Titanium.Web.Proxy.EventArguments
} }
catch (Exception ex) catch (Exception ex)
{ {
exceptionFunc(new Exception("Exception thrown in user event", ex)); ExceptionFunc(new Exception("Exception thrown in user event", ex));
} }
} }
...@@ -173,7 +173,7 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -173,7 +173,7 @@ namespace Titanium.Web.Proxy.EventArguments
} }
catch (Exception ex) catch (Exception ex)
{ {
exceptionFunc(new Exception("Exception thrown in user event", ex)); ExceptionFunc(new Exception("Exception thrown in user event", ex));
} }
} }
......
...@@ -31,12 +31,12 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -31,12 +31,12 @@ namespace Titanium.Web.Proxy.EventArguments
public bool DenyConnect { get; set; } public bool DenyConnect { get; set; }
/// <summary> /// <summary>
/// Is this a connect request to secure HTTP server? Or is it to someother protocol. /// Is this a connect request to secure HTTP server? Or is it to some other protocol.
/// </summary> /// </summary>
public bool IsHttpsConnect public bool IsHttpsConnect
{ {
get => isHttpsConnect ?? get => isHttpsConnect ??
throw new Exception("The value of this property is known in the BeforeTunnectConnectResponse event"); throw new Exception("The value of this property is known in the BeforeTunnelConnectResponse event");
internal set => isHttpsConnect = value; internal set => isHttpsConnect = value;
} }
......
...@@ -20,7 +20,7 @@ namespace Titanium.Web.Proxy.Exceptions ...@@ -20,7 +20,7 @@ namespace Titanium.Web.Proxy.Exceptions
/// Initializes a new instance of the <see cref="ProxyException" /> class. /// Initializes a new instance of the <see cref="ProxyException" /> class.
/// - must be invoked by derived classes' constructors /// - must be invoked by derived classes' constructors
/// </summary> /// </summary>
/// <param name="message">Excception message</param> /// <param name="message">Exception message</param>
/// <param name="innerException">Inner exception associated</param> /// <param name="innerException">Inner exception associated</param>
protected ProxyException(string message, Exception innerException) : base(message, innerException) protected ProxyException(string message, Exception innerException) : base(message, innerException)
{ {
......
...@@ -111,8 +111,8 @@ namespace Titanium.Web.Proxy ...@@ -111,8 +111,8 @@ namespace Titanium.Web.Proxy
return; return;
} }
// write back successfull CONNECT response // write back successful CONNECT response
var response = ConnectResponse.CreateSuccessfullConnectResponse(version); var response = ConnectResponse.CreateSuccessfulConnectResponse(version);
// Set ContentLength explicitly to properly handle HTTP 1.0 // Set ContentLength explicitly to properly handle HTTP 1.0
response.ContentLength = 0; response.ContentLength = 0;
...@@ -148,7 +148,7 @@ namespace Titanium.Web.Proxy ...@@ -148,7 +148,7 @@ namespace Titanium.Web.Proxy
http2Supported = connection.NegotiatedApplicationProtocol == SslApplicationProtocol.Http2; http2Supported = connection.NegotiatedApplicationProtocol == SslApplicationProtocol.Http2;
//release connection back to pool intead of closing when connection pool is enabled. //release connection back to pool instead of closing when connection pool is enabled.
await tcpConnectionFactory.Release(connection, true); await tcpConnectionFactory.Release(connection, true);
} }
...@@ -253,7 +253,7 @@ namespace Titanium.Web.Proxy ...@@ -253,7 +253,7 @@ namespace Titanium.Web.Proxy
try try
{ {
await clientStream.ReadAsync(data, 0, available, cancellationToken); await clientStream.ReadAsync(data, 0, available, cancellationToken);
// clientStream.Available sbould be at most BufferSize because it is using the same buffer size // clientStream.Available should be at most BufferSize because it is using the same buffer size
await connection.StreamWriter.WriteAsync(data, 0, available, true, cancellationToken); await connection.StreamWriter.WriteAsync(data, 0, available, true, cancellationToken);
} }
finally finally
......
...@@ -17,6 +17,7 @@ namespace Titanium.Web.Proxy.Extensions ...@@ -17,6 +17,7 @@ namespace Titanium.Web.Proxy.Extensions
/// <param name="input"></param> /// <param name="input"></param>
/// <param name="output"></param> /// <param name="output"></param>
/// <param name="onCopy"></param> /// <param name="onCopy"></param>
/// <param name="bufferPool"></param>
/// <param name="bufferSize"></param> /// <param name="bufferSize"></param>
internal static Task CopyToAsync(this Stream input, Stream output, Action<byte[], int, int> onCopy, internal static Task CopyToAsync(this Stream input, Stream output, Action<byte[], int, int> onCopy,
IBufferPool bufferPool, int bufferSize) IBufferPool bufferPool, int bufferSize)
...@@ -30,6 +31,7 @@ namespace Titanium.Web.Proxy.Extensions ...@@ -30,6 +31,7 @@ namespace Titanium.Web.Proxy.Extensions
/// <param name="input"></param> /// <param name="input"></param>
/// <param name="output"></param> /// <param name="output"></param>
/// <param name="onCopy"></param> /// <param name="onCopy"></param>
/// <param name="bufferPool"></param>
/// <param name="bufferSize"></param> /// <param name="bufferSize"></param>
/// <param name="cancellationToken"></param> /// <param name="cancellationToken"></param>
internal static async Task CopyToAsync(this Stream input, Stream output, Action<byte[], int, int> onCopy, internal static async Task CopyToAsync(this Stream input, Stream output, Action<byte[], int, int> onCopy,
......
...@@ -70,7 +70,7 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -70,7 +70,7 @@ namespace Titanium.Web.Proxy.Helpers
internal static bool IsRunningAsUwp() internal static bool IsRunningAsUwp()
{ {
if (IsWindows7OrLower) if (isWindows7OrLower)
{ {
return false; return false;
} }
...@@ -87,7 +87,7 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -87,7 +87,7 @@ namespace Titanium.Web.Proxy.Helpers
} }
} }
private static bool IsWindows7OrLower private static bool isWindows7OrLower
{ {
get get
{ {
......
...@@ -80,7 +80,7 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -80,7 +80,7 @@ namespace Titanium.Web.Proxy.Helpers
/// <param name="protocolType"></param> /// <param name="protocolType"></param>
internal void SetProxy(string hostname, int port, ProxyProtocolType protocolType) internal void SetProxy(string hostname, int port, ProxyProtocolType protocolType)
{ {
using (var reg = OpenInternetSettingsKey()) using (var reg = openInternetSettingsKey())
{ {
if (reg == null) if (reg == null)
{ {
...@@ -127,7 +127,7 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -127,7 +127,7 @@ namespace Titanium.Web.Proxy.Helpers
/// </summary> /// </summary>
internal void RemoveProxy(ProxyProtocolType protocolType, bool saveOriginalConfig = true) internal void RemoveProxy(ProxyProtocolType protocolType, bool saveOriginalConfig = true)
{ {
using (var reg = OpenInternetSettingsKey()) using (var reg = openInternetSettingsKey())
{ {
if (reg == null) if (reg == null)
{ {
...@@ -168,7 +168,7 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -168,7 +168,7 @@ namespace Titanium.Web.Proxy.Helpers
/// </summary> /// </summary>
internal void DisableAllProxy() internal void DisableAllProxy()
{ {
using (var reg = OpenInternetSettingsKey()) using (var reg = openInternetSettingsKey())
{ {
if (reg == null) if (reg == null)
{ {
...@@ -186,7 +186,7 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -186,7 +186,7 @@ namespace Titanium.Web.Proxy.Helpers
internal void SetAutoProxyUrl(string url) internal void SetAutoProxyUrl(string url)
{ {
using (var reg = OpenInternetSettingsKey()) using (var reg = openInternetSettingsKey())
{ {
if (reg == null) if (reg == null)
{ {
...@@ -201,7 +201,7 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -201,7 +201,7 @@ namespace Titanium.Web.Proxy.Helpers
internal void SetProxyOverride(string proxyOverride) internal void SetProxyOverride(string proxyOverride)
{ {
using (var reg = OpenInternetSettingsKey()) using (var reg = openInternetSettingsKey())
{ {
if (reg == null) if (reg == null)
{ {
...@@ -286,7 +286,7 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -286,7 +286,7 @@ namespace Titanium.Web.Proxy.Helpers
internal ProxyInfo GetProxyInfoFromRegistry() internal ProxyInfo GetProxyInfoFromRegistry()
{ {
using (var reg = OpenInternetSettingsKey()) using (var reg = openInternetSettingsKey())
{ {
if (reg == null) if (reg == null)
{ {
...@@ -347,7 +347,7 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -347,7 +347,7 @@ namespace Titanium.Web.Proxy.Helpers
/// <summary> /// <summary>
/// Opens the registry key with the internet settings /// Opens the registry key with the internet settings
/// </summary> /// </summary>
private static RegistryKey OpenInternetSettingsKey() private static RegistryKey openInternetSettingsKey()
{ {
return Registry.CurrentUser.OpenSubKey(regKeyInternetSettings, true); return Registry.CurrentUser.OpenSubKey(regKeyInternetSettings, true);
} }
......
using System; using System;
using System.IO; using System.IO;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Threading; using System.Threading;
...@@ -96,11 +96,12 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -96,11 +96,12 @@ namespace Titanium.Web.Proxy.Helpers
/// <summary> /// <summary>
/// relays the input clientStream to the server at the specified host name and port with the given httpCmd and headers /// relays the input clientStream to the server at the specified host name and port with the given httpCmd and headers
/// as prefix /// as prefix
/// Usefull for websocket requests /// Useful for websocket requests
/// Task-based Asynchronous Pattern /// Task-based Asynchronous Pattern
/// </summary> /// </summary>
/// <param name="clientStream"></param> /// <param name="clientStream"></param>
/// <param name="serverStream"></param> /// <param name="serverStream"></param>
/// <param name="bufferPool"></param>
/// <param name="bufferSize"></param> /// <param name="bufferSize"></param>
/// <param name="onDataSend"></param> /// <param name="onDataSend"></param>
/// <param name="onDataReceive"></param> /// <param name="onDataReceive"></param>
...@@ -128,10 +129,11 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -128,10 +129,11 @@ namespace Titanium.Web.Proxy.Helpers
/// <summary> /// <summary>
/// relays the input clientStream to the server at the specified host name and port with the given httpCmd and headers /// relays the input clientStream to the server at the specified host name and port with the given httpCmd and headers
/// as prefix /// as prefix
/// Usefull for websocket requests /// Useful for websocket requests
/// </summary> /// </summary>
/// <param name="clientStream"></param> /// <param name="clientStream"></param>
/// <param name="serverStream"></param> /// <param name="serverStream"></param>
/// <param name="bufferPool"></param>
/// <param name="bufferSize"></param> /// <param name="bufferSize"></param>
/// <param name="onDataSend"></param> /// <param name="onDataSend"></param>
/// <param name="onDataReceive"></param> /// <param name="onDataReceive"></param>
......
...@@ -12,11 +12,11 @@ namespace Titanium.Web.Proxy.Http ...@@ -12,11 +12,11 @@ namespace Titanium.Web.Proxy.Http
public ServerHelloInfo ServerHelloInfo { get; set; } public ServerHelloInfo ServerHelloInfo { get; set; }
/// <summary> /// <summary>
/// Creates a successfull CONNECT response /// Creates a successful CONNECT response
/// </summary> /// </summary>
/// <param name="httpVersion"></param> /// <param name="httpVersion"></param>
/// <returns></returns> /// <returns></returns>
internal static ConnectResponse CreateSuccessfullConnectResponse(Version httpVersion) internal static ConnectResponse CreateSuccessfulConnectResponse(Version httpVersion)
{ {
var response = new ConnectResponse var response = new ConnectResponse
{ {
......
...@@ -67,7 +67,7 @@ namespace Titanium.Web.Proxy.Http ...@@ -67,7 +67,7 @@ namespace Titanium.Web.Proxy.Http
/// <summary> /// <summary>
/// Returns all headers with given name if exists /// Returns all headers with given name if exists
/// Returns null if does'nt exist /// Returns null if doesn't exist
/// </summary> /// </summary>
/// <param name="name"></param> /// <param name="name"></param>
/// <returns></returns> /// <returns></returns>
......
...@@ -189,7 +189,7 @@ namespace Titanium.Web.Proxy.Http ...@@ -189,7 +189,7 @@ namespace Titanium.Web.Proxy.Http
public bool IsBodyRead { get; internal set; } public bool IsBodyRead { get; internal set; }
/// <summary> /// <summary>
/// Is the request/response no more modifyable by user (user callbacks complete?) /// Is the request/response no more modifiable by user (user callbacks complete?)
/// Also if user set this as a custom response then this should be true. /// Also if user set this as a custom response then this should be true.
/// </summary> /// </summary>
internal bool Locked { get; set; } internal bool Locked { get; set; }
......
#if NETCOREAPP2_1 #if NETCOREAPP2_1
using System; using System;
using System.IO; using System.IO;
using System.Threading; using System.Threading;
...@@ -22,7 +22,7 @@ namespace Titanium.Web.Proxy.Http2 ...@@ -22,7 +22,7 @@ namespace Titanium.Web.Proxy.Http2
/// <summary> /// <summary>
/// relays the input clientStream to the server at the specified host name and port with the given httpCmd and headers /// relays the input clientStream to the server at the specified host name and port with the given httpCmd and headers
/// as prefix /// as prefix
/// Usefull for websocket requests /// Useful for websocket requests
/// Task-based Asynchronous Pattern /// Task-based Asynchronous Pattern
/// </summary> /// </summary>
/// <param name="clientStream"></param> /// <param name="clientStream"></param>
......
...@@ -31,7 +31,7 @@ namespace Titanium.Web.Proxy.Models ...@@ -31,7 +31,7 @@ namespace Titanium.Web.Proxy.Models
/// Intercept tunnel connect request. /// Intercept tunnel connect request.
/// Valid only for explicit endpoints. /// Valid only for explicit endpoints.
/// Set the <see cref="TunnelConnectSessionEventArgs.DecryptSsl" /> property to false if this HTTP connect request /// Set the <see cref="TunnelConnectSessionEventArgs.DecryptSsl" /> property to false if this HTTP connect request
/// should'nt be decrypted and instead be relayed. /// shouldn't be decrypted and instead be relayed.
/// </summary> /// </summary>
public event AsyncEventHandler<TunnelConnectSessionEventArgs> BeforeTunnelConnectRequest; public event AsyncEventHandler<TunnelConnectSessionEventArgs> BeforeTunnelConnectRequest;
......
...@@ -70,7 +70,7 @@ namespace Titanium.Web.Proxy.Models ...@@ -70,7 +70,7 @@ namespace Titanium.Web.Proxy.Models
public int Port { get; set; } public int Port { get; set; }
/// <summary> /// <summary>
/// Get cache key for Tcp connection cahe. /// Get cache key for Tcp connection cache.
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
internal string GetCacheKey() internal string GetCacheKey()
......
...@@ -49,7 +49,7 @@ namespace Titanium.Web.Proxy.Network ...@@ -49,7 +49,7 @@ namespace Titanium.Web.Proxy.Network
/// <summary> /// <summary>
/// A list of pending certificate creation tasks. /// A list of pending certificate creation tasks.
/// Usefull to prevent multiple threads working on same certificate generation /// Useful to prevent multiple threads working on same certificate generation
/// when burst certificate generation requests happen for same certificate. /// when burst certificate generation requests happen for same certificate.
/// </summary> /// </summary>
private readonly ConcurrentDictionary<string, Task<X509Certificate2>> pendingCertificateCreationTasks private readonly ConcurrentDictionary<string, Task<X509Certificate2>> pendingCertificateCreationTasks
......
...@@ -38,11 +38,11 @@ namespace Titanium.Web.Proxy.Network.Tcp ...@@ -38,11 +38,11 @@ namespace Titanium.Web.Proxy.Network.Tcp
internal TcpConnectionFactory(ProxyServer server) internal TcpConnectionFactory(ProxyServer server)
{ {
this.server = server; this.Server = server;
Task.Run(async () => await clearOutdatedConnections()); Task.Run(async () => await clearOutdatedConnections());
} }
internal ProxyServer server { get; set; } internal ProxyServer Server { get; set; }
internal string GetConnectionCacheKey(string remoteHostName, int remotePort, internal string GetConnectionCacheKey(string remoteHostName, int remotePort,
bool isHttps, List<SslApplicationProtocol> applicationProtocols, bool isHttps, List<SslApplicationProtocol> applicationProtocols,
...@@ -50,7 +50,7 @@ namespace Titanium.Web.Proxy.Network.Tcp ...@@ -50,7 +50,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
{ {
//http version is ignored since its an application level decision b/w HTTP 1.0/1.1 //http version is ignored since its an application level decision b/w HTTP 1.0/1.1
//also when doing connect request MS Edge browser sends http 1.0 but uses 1.1 after server sends 1.1 its response. //also when doing connect request MS Edge browser sends http 1.0 but uses 1.1 after server sends 1.1 its response.
//That can create cache miss for same server connection unneccessarily expecially when prefetcing with Connect. //That can create cache miss for same server connection unnecessarily especially when prefetching with Connect.
//http version 2 is separated using applicationProtocols below. //http version 2 is separated using applicationProtocols below.
var cacheKeyBuilder = new StringBuilder($"{remoteHostName}-{remotePort}-" + var cacheKeyBuilder = new StringBuilder($"{remoteHostName}-{remotePort}-" +
//when creating Tcp client isConnect won't matter //when creating Tcp client isConnect won't matter
...@@ -232,7 +232,7 @@ namespace Titanium.Web.Proxy.Network.Tcp ...@@ -232,7 +232,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
CancellationToken cancellationToken) CancellationToken cancellationToken)
{ {
//deny connection to proxy end points to avoid infinite connection loop. //deny connection to proxy end points to avoid infinite connection loop.
if (server.ProxyEndPoints.Any(x => x.Port == remotePort) if (Server.ProxyEndPoints.Any(x => x.Port == remotePort)
&& NetworkHelper.IsLocalIpAddress(remoteHostName)) && NetworkHelper.IsLocalIpAddress(remoteHostName))
{ {
throw new Exception($"A client is making HTTP request to one of the listening ports of this proxy {remoteHostName}:{remotePort}"); throw new Exception($"A client is making HTTP request to one of the listening ports of this proxy {remoteHostName}:{remotePort}");
...@@ -240,7 +240,7 @@ namespace Titanium.Web.Proxy.Network.Tcp ...@@ -240,7 +240,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
if (externalProxy != null) if (externalProxy != null)
{ {
if (server.ProxyEndPoints.Any(x => x.Port == externalProxy.Port) if (Server.ProxyEndPoints.Any(x => x.Port == externalProxy.Port)
&& NetworkHelper.IsLocalIpAddress(externalProxy.HostName)) && NetworkHelper.IsLocalIpAddress(externalProxy.HostName))
{ {
throw new Exception($"A client is making HTTP request via external proxy to one of the listening ports of this proxy {remoteHostName}:{remotePort}"); throw new Exception($"A client is making HTTP request via external proxy to one of the listening ports of this proxy {remoteHostName}:{remotePort}");
...@@ -416,7 +416,7 @@ namespace Titanium.Web.Proxy.Network.Tcp ...@@ -416,7 +416,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
return; return;
} }
if (close || connection.IsWinAuthenticated || !server.EnableConnectionPool || connection.Stream.IsClosed) if (close || connection.IsWinAuthenticated || !Server.EnableConnectionPool || connection.Stream.IsClosed)
{ {
disposalBag.Add(connection); disposalBag.Add(connection);
return; return;
...@@ -432,7 +432,7 @@ namespace Titanium.Web.Proxy.Network.Tcp ...@@ -432,7 +432,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
{ {
if (cache.TryGetValue(connection.CacheKey, out var existingConnections)) if (cache.TryGetValue(connection.CacheKey, out var existingConnections))
{ {
while (existingConnections.Count >= server.MaxCachedConnections) while (existingConnections.Count >= Server.MaxCachedConnections)
{ {
if (existingConnections.TryDequeue(out var staleConnection)) if (existingConnections.TryDequeue(out var staleConnection))
{ {
...@@ -489,8 +489,8 @@ namespace Titanium.Web.Proxy.Network.Tcp ...@@ -489,8 +489,8 @@ namespace Titanium.Web.Proxy.Network.Tcp
{ {
if (queue.TryDequeue(out var connection)) if (queue.TryDequeue(out var connection))
{ {
var cutOff = DateTime.Now.AddSeconds(-1 * server.ConnectionTimeOutSeconds); var cutOff = DateTime.Now.AddSeconds(-1 * Server.ConnectionTimeOutSeconds);
if (!server.EnableConnectionPool if (!Server.EnableConnectionPool
|| connection.LastAccess < cutOff) || connection.LastAccess < cutOff)
{ {
disposalBag.Add(connection); disposalBag.Add(connection);
...@@ -530,7 +530,7 @@ namespace Titanium.Web.Proxy.Network.Tcp ...@@ -530,7 +530,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
} }
catch (Exception e) catch (Exception e)
{ {
server.ExceptionFunc(new Exception("An error occurred when disposing server connections.", e)); Server.ExceptionFunc(new Exception("An error occurred when disposing server connections.", e));
} }
finally finally
{ {
......
// //
// Mono.Security.BitConverterLE.cs // Mono.Security.BitConverterLE.cs
// Like System.BitConverter but always little endian // Like System.BitConverter but always little endian
// //
......
...@@ -146,7 +146,7 @@ namespace Titanium.Web.Proxy ...@@ -146,7 +146,7 @@ namespace Titanium.Web.Proxy
public bool EnableWinAuth { get; set; } public bool EnableWinAuth { get; set; }
/// <summary> /// <summary>
/// Should we check for certificare revocation during SSL authentication to servers /// Should we check for certificate revocation during SSL authentication to servers
/// Note: If enabled can reduce performance. Defaults to false. /// Note: If enabled can reduce performance. Defaults to false.
/// </summary> /// </summary>
public X509RevocationMode CheckCertificateRevocation { get; set; } public X509RevocationMode CheckCertificateRevocation { get; set; }
...@@ -169,7 +169,7 @@ namespace Titanium.Web.Proxy ...@@ -169,7 +169,7 @@ namespace Titanium.Web.Proxy
/// When enabled, as soon as we receive a client connection we concurrently initiate /// When enabled, as soon as we receive a client connection we concurrently initiate
/// corresponding server connection process using CONNECT hostname or SNI hostname on a separate task so that after parsing client request /// corresponding server connection process using CONNECT hostname or SNI hostname on a separate task so that after parsing client request
/// we will have the server connection immediately ready or in the process of getting ready. /// we will have the server connection immediately ready or in the process of getting ready.
/// If a server connection is available in cache then this prefetch task will immediatly return with the available connection from cache. /// If a server connection is available in cache then this prefetch task will immediately return with the available connection from cache.
/// Defaults to true. /// Defaults to true.
/// </summary> /// </summary>
public bool EnableTcpServerConnectionPrefetch { get; set; } = true; public bool EnableTcpServerConnectionPrefetch { get; set; } = true;
...@@ -380,7 +380,7 @@ namespace Titanium.Web.Proxy ...@@ -380,7 +380,7 @@ namespace Titanium.Web.Proxy
/// <summary> /// <summary>
/// Remove a proxy end point. /// Remove a proxy end point.
/// Will throw error if the end point does'nt exist. /// Will throw error if the end point doesn't exist.
/// </summary> /// </summary>
/// <param name="endPoint">The existing endpoint to remove.</param> /// <param name="endPoint">The existing endpoint to remove.</param>
public void RemoveEndPoint(ProxyEndPoint endPoint) public void RemoveEndPoint(ProxyEndPoint endPoint)
...@@ -743,13 +743,11 @@ namespace Titanium.Web.Proxy ...@@ -743,13 +743,11 @@ namespace Titanium.Web.Proxy
/// <summary> /// <summary>
/// Change the ThreadPool.WorkerThread minThread /// Change the ThreadPool.WorkerThread minThread
/// </summary> /// </summary>
/// <param name="workerThreadsToAdd">minimum Threads allocated in the ThreadPool</param> /// <param name="workerThreads">minimum Threads allocated in the ThreadPool</param>
private void setThreadPoolMinThread(int workerThreads) private void setThreadPoolMinThread(int workerThreads)
{ {
int minWorkerThreads, minCompletionPortThreads, maxWorkerThreads; ThreadPool.GetMinThreads(out int minWorkerThreads, out int minCompletionPortThreads);
ThreadPool.GetMaxThreads(out int maxWorkerThreads, out _);
ThreadPool.GetMinThreads(out minWorkerThreads, out minCompletionPortThreads);
ThreadPool.GetMaxThreads(out maxWorkerThreads, out _);
minWorkerThreads = Math.Min(maxWorkerThreads, Math.Max(workerThreads, Environment.ProcessorCount)); minWorkerThreads = Math.Min(maxWorkerThreads, Math.Max(workerThreads, Environment.ProcessorCount));
......
...@@ -44,7 +44,7 @@ namespace Titanium.Web.Proxy ...@@ -44,7 +44,7 @@ namespace Titanium.Web.Proxy
/// The https hostname as appeared in CONNECT request if this is a HTTPS request from /// The https hostname as appeared in CONNECT request if this is a HTTPS request from
/// explicit endpoint. /// explicit endpoint.
/// </param> /// </param>
/// <param name="connectRequest">The Connect request if this is a HTTPS request from explicit endpoint.</param> /// <param name="connectArgs">The Connect request if this is a HTTPS request from explicit endpoint.</param>
/// <param name="prefetchConnectionTask">Prefetched server connection for current client using Connect/SNI headers.</param> /// <param name="prefetchConnectionTask">Prefetched server connection for current client using Connect/SNI headers.</param>
private async Task handleHttpSessionRequest(ProxyEndPoint endPoint, TcpClientConnection clientConnection, private async Task handleHttpSessionRequest(ProxyEndPoint endPoint, TcpClientConnection clientConnection,
CustomBufferedStream clientStream, HttpResponseWriter clientStreamWriter, CustomBufferedStream clientStream, HttpResponseWriter clientStreamWriter,
...@@ -61,7 +61,7 @@ namespace Titanium.Web.Proxy ...@@ -61,7 +61,7 @@ namespace Titanium.Web.Proxy
{ {
var cancellationToken = cancellationTokenSource.Token; var cancellationToken = cancellationTokenSource.Token;
// Loop through each subsequest request on this particular client connection // Loop through each subsequent request on this particular client connection
// (assuming HTTP connection is kept alive by client) // (assuming HTTP connection is kept alive by client)
while (true) while (true)
{ {
...@@ -373,7 +373,7 @@ namespace Titanium.Web.Proxy ...@@ -373,7 +373,7 @@ namespace Titanium.Web.Proxy
} }
/// <summary> /// <summary>
/// Prepare the request headers so that we can avoid encodings not parsable by this proxy /// Prepare the request headers so that we can avoid encodings not parseable by this proxy
/// </summary> /// </summary>
private void prepareRequestHeaders(HeaderCollection requestHeaders) private void prepareRequestHeaders(HeaderCollection requestHeaders)
{ {
......
...@@ -14,7 +14,7 @@ namespace Titanium.Web.Proxy ...@@ -14,7 +14,7 @@ namespace Titanium.Web.Proxy
public partial class ProxyServer public partial class ProxyServer
{ {
/// <summary> /// <summary>
/// Called asynchronously when a request was successfull and we received the response. /// Called asynchronously when a request was successful and we received the response.
/// </summary> /// </summary>
/// <param name="args">The session event arguments.</param> /// <param name="args">The session event arguments.</param>
/// <returns> The task.</returns> /// <returns> The task.</returns>
......
...@@ -112,7 +112,7 @@ namespace Titanium.Web.Proxy ...@@ -112,7 +112,7 @@ namespace Titanium.Web.Proxy
var data = BufferPool.GetBuffer(BufferSize); var data = BufferPool.GetBuffer(BufferSize);
try try
{ {
// clientStream.Available sbould be at most BufferSize because it is using the same buffer size // clientStream.Available should be at most BufferSize because it is using the same buffer size
await clientStream.ReadAsync(data, 0, available, cancellationToken); await clientStream.ReadAsync(data, 0, available, cancellationToken);
serverStream = connection.Stream; serverStream = connection.Stream;
await serverStream.WriteAsync(data, 0, available, cancellationToken); await serverStream.WriteAsync(data, 0, available, cancellationToken);
......
...@@ -150,7 +150,7 @@ namespace Titanium.Web.Proxy ...@@ -150,7 +150,7 @@ namespace Titanium.Web.Proxy
} }
// Need to revisit this. // Need to revisit this.
// Should we cache all Set-Cokiee headers from server during auth process // Should we cache all Set-Cookie headers from server during auth process
// and send it to client after auth? // and send it to client after auth?
// Let ResponseHandler send the updated request // Let ResponseHandler send the updated request
......
...@@ -43,7 +43,7 @@ namespace Titanium.Web.Proxy.IntegrationTests.Helpers ...@@ -43,7 +43,7 @@ namespace Titanium.Web.Proxy.IntegrationTests.Helpers
if (!requireBody) if (!requireBody)
return request as Request; return request as Request;
if (ParseBody(reader, ref request)) if (parseBody(reader, ref request))
return request as Request; return request as Request;
} }
catch { } catch { }
...@@ -84,7 +84,7 @@ namespace Titanium.Web.Proxy.IntegrationTests.Helpers ...@@ -84,7 +84,7 @@ namespace Titanium.Web.Proxy.IntegrationTests.Helpers
if (line?.Length != 0) if (line?.Length != 0)
return null; return null;
if (ParseBody(reader, ref response)) if (parseBody(reader, ref response))
return response as Response; return response as Response;
} }
catch { } catch { }
...@@ -92,7 +92,7 @@ namespace Titanium.Web.Proxy.IntegrationTests.Helpers ...@@ -92,7 +92,7 @@ namespace Titanium.Web.Proxy.IntegrationTests.Helpers
return null; return null;
} }
private static bool ParseBody(StringReader reader, ref RequestResponseBase obj) private static bool parseBody(StringReader reader, ref RequestResponseBase obj)
{ {
obj.OriginalContentLength = obj.ContentLength; obj.OriginalContentLength = obj.ContentLength;
if (obj.ContentLength <= 0) if (obj.ContentLength <= 0)
......
...@@ -11,22 +11,22 @@ namespace Titanium.Web.Proxy.UnitTests ...@@ -11,22 +11,22 @@ namespace Titanium.Web.Proxy.UnitTests
public class SystemProxyTest public class SystemProxyTest
{ {
[TestMethod] [TestMethod]
public void CompareProxyAdddressReturendByWebProxyAndWinHttpProxyResolver() public void CompareProxyAddressReturnedByWebProxyAndWinHttpProxyResolver()
{ {
var proxyManager = new SystemProxyManager(); var proxyManager = new SystemProxyManager();
try try
{ {
CompareUrls(); compareUrls();
proxyManager.SetProxy("127.0.0.1", 8000, ProxyProtocolType.Http); proxyManager.SetProxy("127.0.0.1", 8000, ProxyProtocolType.Http);
CompareUrls(); compareUrls();
proxyManager.SetProxy("127.0.0.1", 8000, ProxyProtocolType.Https); proxyManager.SetProxy("127.0.0.1", 8000, ProxyProtocolType.Https);
CompareUrls(); compareUrls();
proxyManager.SetProxy("127.0.0.1", 8000, ProxyProtocolType.AllHttp); proxyManager.SetProxy("127.0.0.1", 8000, ProxyProtocolType.AllHttp);
CompareUrls(); compareUrls();
// for this test you need to add a proxy.pac file to a local webserver // for this test you need to add a proxy.pac file to a local webserver
//function FindProxyForURL(url, host) //function FindProxyForURL(url, host)
...@@ -43,25 +43,25 @@ namespace Titanium.Web.Proxy.UnitTests ...@@ -43,25 +43,25 @@ namespace Titanium.Web.Proxy.UnitTests
//CompareUrls(); //CompareUrls();
proxyManager.SetProxyOverride("<-loopback>"); proxyManager.SetProxyOverride("<-loopback>");
CompareUrls(); compareUrls();
proxyManager.SetProxyOverride("<local>"); proxyManager.SetProxyOverride("<local>");
CompareUrls(); compareUrls();
proxyManager.SetProxyOverride("yahoo.com"); proxyManager.SetProxyOverride("yahoo.com");
CompareUrls(); compareUrls();
proxyManager.SetProxyOverride("*.local"); proxyManager.SetProxyOverride("*.local");
CompareUrls(); compareUrls();
proxyManager.SetProxyOverride("http://*.local"); proxyManager.SetProxyOverride("http://*.local");
CompareUrls(); compareUrls();
proxyManager.SetProxyOverride("<-loopback>;*.local"); proxyManager.SetProxyOverride("<-loopback>;*.local");
CompareUrls(); compareUrls();
proxyManager.SetProxyOverride("<-loopback>;*.local;<local>"); proxyManager.SetProxyOverride("<-loopback>;*.local;<local>");
CompareUrls(); compareUrls();
} }
finally finally
{ {
...@@ -69,7 +69,7 @@ namespace Titanium.Web.Proxy.UnitTests ...@@ -69,7 +69,7 @@ namespace Titanium.Web.Proxy.UnitTests
} }
} }
private void CompareUrls() private void compareUrls()
{ {
var webProxy = WebRequest.GetSystemWebProxy(); var webProxy = WebRequest.GetSystemWebProxy();
......
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