diff --git a/examples/Titanium.Web.Proxy.Examples.Basic/Helpers/ConsoleHelper.cs b/examples/Titanium.Web.Proxy.Examples.Basic/Helpers/ConsoleHelper.cs index 2032e19f7..579c92648 100644 --- a/examples/Titanium.Web.Proxy.Examples.Basic/Helpers/ConsoleHelper.cs +++ b/examples/Titanium.Web.Proxy.Examples.Basic/Helpers/ConsoleHelper.cs @@ -4,7 +4,7 @@ namespace Titanium.Web.Proxy.Examples.Basic.Helpers { /// - /// Adapated from + /// Adapted from /// http://stackoverflow.com/questions/13656846/how-to-programmatic-disable-c-sharp-console-applications-quick-edit-mode /// internal static class ConsoleHelper diff --git a/examples/Titanium.Web.Proxy.Examples.Basic/ProxyTestController.cs b/examples/Titanium.Web.Proxy.Examples.Basic/ProxyTestController.cs index 088615c91..04681b95c 100644 --- a/examples/Titanium.Web.Proxy.Examples.Basic/ProxyTestController.cs +++ b/examples/Titanium.Web.Proxy.Examples.Basic/ProxyTestController.cs @@ -32,11 +32,11 @@ public ProxyTestController() { if (exception is ProxyHttpException phex) { - await WriteToConsole(exception.Message + ": " + phex.InnerException?.Message, true); + await writeToConsole(exception.Message + ": " + phex.InnerException?.Message, true); } else { - await WriteToConsole(exception.Message, true); + await writeToConsole(exception.Message, true); } }; proxyServer.ForwardToUpstreamGateway = true; @@ -52,8 +52,8 @@ public ProxyTestController() public void StartProxy() { - proxyServer.BeforeRequest += OnRequest; - proxyServer.BeforeResponse += OnResponse; + proxyServer.BeforeRequest += onRequest; + proxyServer.BeforeResponse += onResponse; proxyServer.ServerCertificateValidationCallback += OnCertificateValidation; proxyServer.ClientCertificateSelectionCallback += OnCertificateSelection; @@ -63,8 +63,8 @@ public void StartProxy() explicitEndPoint = new ExplicitProxyEndPoint(IPAddress.Any, 8000); // Fired when a CONNECT request is received - explicitEndPoint.BeforeTunnelConnectRequest += OnBeforeTunnelConnectRequest; - explicitEndPoint.BeforeTunnelConnectResponse += OnBeforeTunnelConnectResponse; + explicitEndPoint.BeforeTunnelConnectRequest += onBeforeTunnelConnectRequest; + explicitEndPoint.BeforeTunnelConnectResponse += onBeforeTunnelConnectResponse; // An explicit endpoint is where the client knows about the existence of a proxy // So client sends request in a proxy friendly manner @@ -102,11 +102,11 @@ public void StartProxy() public void Stop() { - explicitEndPoint.BeforeTunnelConnectRequest -= OnBeforeTunnelConnectRequest; - explicitEndPoint.BeforeTunnelConnectResponse -= OnBeforeTunnelConnectResponse; + explicitEndPoint.BeforeTunnelConnectRequest -= onBeforeTunnelConnectRequest; + explicitEndPoint.BeforeTunnelConnectResponse -= onBeforeTunnelConnectResponse; - proxyServer.BeforeRequest -= OnRequest; - proxyServer.BeforeResponse -= OnResponse; + proxyServer.BeforeRequest -= onRequest; + proxyServer.BeforeResponse -= onResponse; proxyServer.ServerCertificateValidationCallback -= OnCertificateValidation; proxyServer.ClientCertificateSelectionCallback -= OnCertificateSelection; @@ -116,10 +116,10 @@ public void Stop() //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; - await WriteToConsole("Tunnel to: " + hostname); + await writeToConsole("Tunnel to: " + hostname); if (hostname.Contains("dropbox.com")) { @@ -130,16 +130,16 @@ private async Task OnBeforeTunnelConnectRequest(object sender, TunnelConnectSess } } - private Task OnBeforeTunnelConnectResponse(object sender, TunnelConnectSessionEventArgs e) + private Task onBeforeTunnelConnectResponse(object sender, TunnelConnectSessionEventArgs e) { return Task.FromResult(false); } // 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(e.HttpClient.Request.Url); + await writeToConsole("Active Client Connections:" + ((ProxyServer)sender).ClientConnectionCount); + await writeToConsole(e.HttpClient.Request.Url); // store it in the UserData property // It can be a simple integer, Guid, or any type @@ -177,19 +177,19 @@ private async Task OnRequest(object sender, SessionEventArgs e) } // Modify response - private async Task MultipartRequestPartSent(object sender, MultipartRequestPartSentEventArgs e) + private async Task multipartRequestPartSent(object sender, MultipartRequestPartSentEventArgs e) { var session = (SessionEventArgs)sender; - await WriteToConsole("Multipart form data headers:"); + await writeToConsole("Multipart form data 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); @@ -261,7 +261,7 @@ public Task OnCertificateSelection(object sender, CertificateSelectionEventArgs 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(); diff --git a/examples/Titanium.Web.Proxy.Examples.Wpf/MainWindow.xaml.cs b/examples/Titanium.Web.Proxy.Examples.Wpf/MainWindow.xaml.cs index dea71368d..94b592fe6 100644 --- a/examples/Titanium.Web.Proxy.Examples.Wpf/MainWindow.xaml.cs +++ b/examples/Titanium.Web.Proxy.Examples.Wpf/MainWindow.xaml.cs @@ -106,7 +106,7 @@ public SessionListItem SelectedSession if (value != selectedSession) { selectedSession = value; - SelectedSessionChanged(); + selectedSessionChanged(); } } } @@ -131,7 +131,7 @@ private async Task ProxyServer_BeforeTunnelConnectRequest(object sender, TunnelC e.DecryptSsl = false; } - await Dispatcher.InvokeAsync(() => { AddSession(e); }); + await Dispatcher.InvokeAsync(() => { addSession(e); }); } private async Task ProxyServer_BeforeTunnelConnectResponse(object sender, TunnelConnectSessionEventArgs e) @@ -148,7 +148,7 @@ await Dispatcher.InvokeAsync(() => private async Task ProxyServer_BeforeRequest(object sender, SessionEventArgs e) { SessionListItem item = null; - await Dispatcher.InvokeAsync(() => { item = AddSession(e); }); + await Dispatcher.InvokeAsync(() => { item = addSession(e); }); if (e.HttpClient.Request.HasBody) { @@ -191,15 +191,15 @@ await Dispatcher.InvokeAsync(() => }); } - private SessionListItem AddSession(SessionEventArgsBase e) + private SessionListItem addSession(SessionEventArgsBase e) { - var item = CreateSessionListItem(e); + var item = createSessionListItem(e); Sessions.Add(item); sessionDictionary.Add(e.HttpClient, item); return item; } - private SessionListItem CreateSessionListItem(SessionEventArgsBase e) + private SessionListItem createSessionListItem(SessionEventArgsBase e) { lastSessionNumber++; bool isTunnelConnect = e is TunnelConnectSessionEventArgs; @@ -214,7 +214,7 @@ private SessionListItem CreateSessionListItem(SessionEventArgsBase e) { e.DataReceived += (sender, args) => { - var session = (SessionEventArgs)sender; + var session = (SessionEventArgsBase)sender; if (sessionDictionary.TryGetValue(session.HttpClient, out var li)) { li.ReceivedDataCount += args.Count; @@ -223,7 +223,7 @@ private SessionListItem CreateSessionListItem(SessionEventArgsBase e) e.DataSent += (sender, args) => { - var session = (SessionEventArgs)sender; + var session = (SessionEventArgsBase)sender; if (sessionDictionary.TryGetValue(session.HttpClient, out var li)) { li.SentDataCount += args.Count; @@ -248,7 +248,7 @@ private void ListViewSessions_OnKeyDown(object sender, KeyEventArgs e) } } - private void SelectedSessionChanged() + private void selectedSessionChanged() { if (SelectedSession == null) { diff --git a/examples/Titanium.Web.Proxy.Examples.Wpf/Properties/Annotations.cs b/examples/Titanium.Web.Proxy.Examples.Wpf/Properties/Annotations.cs index cead89589..680d71b38 100644 --- a/examples/Titanium.Web.Proxy.Examples.Wpf/Properties/Annotations.cs +++ b/examples/Titanium.Web.Proxy.Examples.Wpf/Properties/Annotations.cs @@ -73,7 +73,7 @@ public sealed class NotNullAttribute : Attribute } /// - /// 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 /// or of the Lazy.Value property can never be null. /// @@ -85,7 +85,7 @@ public sealed class ItemNotNullAttribute : Attribute } /// - /// 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 /// or of the Lazy.Value property can be null. /// @@ -251,7 +251,7 @@ public NotifyPropertyChangedInvocatorAttribute([NotNull] string parameterName) /// /// If method has single input parameter, it's name could be omitted.
/// Using halt (or void/nothing, which is the same) for method output - /// means that the methos doesn't return normally (throws or terminates the process).
+ /// means that the method doesn't return normally (throws or terminates the process).
/// Value canbenull is only applicable for output parameters.
/// You can use multiple [ContractAnnotation] for each FDT row, or use single attribute /// with rows separated by semicolon. There is no notion of order rows, all rows are checked diff --git a/src/Titanium.Web.Proxy.sln.DotSettings b/src/Titanium.Web.Proxy.sln.DotSettings index d0c946856..1b03ebb37 100644 --- a/src/Titanium.Web.Proxy.sln.DotSettings +++ b/src/Titanium.Web.Proxy.sln.DotSettings @@ -19,16 +19,19 @@ MTA OID OIDS + False <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> <Policy><Descriptor Staticness="Static, Instance" AccessRightKinds="Private" Description="Method (private)"><ElementKinds><Kind Name="METHOD" /></ElementKinds></Descriptor><Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /></Policy> <Policy><Descriptor Staticness="Static, Instance" AccessRightKinds="Private" Description="Property (private)"><ElementKinds><Kind Name="PROPERTY" /></ElementKinds></Descriptor><Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /></Policy> True True True True + True True True True diff --git a/src/Titanium.Web.Proxy/EventArguments/CertificateSelectionEventArgs.cs b/src/Titanium.Web.Proxy/EventArguments/CertificateSelectionEventArgs.cs index 90f22abb5..5dda6dd5d 100644 --- a/src/Titanium.Web.Proxy/EventArguments/CertificateSelectionEventArgs.cs +++ b/src/Titanium.Web.Proxy/EventArguments/CertificateSelectionEventArgs.cs @@ -29,7 +29,7 @@ public class CertificateSelectionEventArgs : EventArgs public X509Certificate RemoteCertificate { get; internal set; } /// - /// Acceptable issuers as listed by remoted server. + /// Acceptable issuers as listed by remote server. /// public string[] AcceptableIssuers { get; internal set; } diff --git a/src/Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs b/src/Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs index f4d38dec1..35d1ee35d 100644 --- a/src/Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs +++ b/src/Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs @@ -117,7 +117,7 @@ internal void OnMultipartRequestPartSent(string boundary, HeaderCollection heade } 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 @@ private async Task readBodyAsync(bool isRequest, CancellationToken cance { using (var bodyStream = new MemoryStream()) { - var writer = new HttpWriter(bodyStream, bufferPool, bufferSize); + var writer = new HttpWriter(bodyStream, BufferPool, BufferSize); if (isRequest) { @@ -186,7 +186,7 @@ internal async Task SyphonOutBodyAsync(bool isRequest, CancellationToken cancell 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); } } @@ -207,7 +207,7 @@ internal async Task CopyRequestBodyAsync(HttpWriter writer, TransformationMode t var reader = getStreamReader(true); 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) { @@ -259,7 +259,7 @@ private async Task copyBodyAsync(bool isRequest, bool useOriginalHeaderValues, H 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) { @@ -268,7 +268,7 @@ private async Task copyBodyAsync(bool isRequest, bool useOriginalHeaderValues, H 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); } @@ -290,7 +290,7 @@ private async Task readUntilBoundaryAsync(ICustomStreamReader reader, long { int bufferDataLength = 0; - var buffer = bufferPool.GetBuffer(bufferSize); + var buffer = BufferPool.GetBuffer(BufferSize); try { int boundaryLength = boundary.Length + 4; @@ -340,7 +340,7 @@ private async Task readUntilBoundaryAsync(ICustomStreamReader reader, long } finally { - bufferPool.ReturnBuffer(buffer); + BufferPool.ReturnBuffer(buffer); } } diff --git a/src/Titanium.Web.Proxy/EventArguments/SessionEventArgsBase.cs b/src/Titanium.Web.Proxy/EventArguments/SessionEventArgsBase.cs index dc627e3f6..0359c5eaf 100644 --- a/src/Titanium.Web.Proxy/EventArguments/SessionEventArgsBase.cs +++ b/src/Titanium.Web.Proxy/EventArguments/SessionEventArgsBase.cs @@ -24,9 +24,9 @@ public abstract class SessionEventArgsBase : EventArgs, IDisposable internal TcpServerConnection ServerConnection => HttpClient.Connection; internal TcpClientConnection ClientConnection => ProxyClient.Connection; - protected readonly int bufferSize; - protected readonly IBufferPool bufferPool; - protected readonly ExceptionHandler exceptionFunc; + protected readonly int BufferSize; + protected readonly IBufferPool BufferPool; + protected readonly ExceptionHandler ExceptionFunc; /// /// Relative milliseconds for various events. @@ -39,9 +39,9 @@ public abstract class SessionEventArgsBase : EventArgs, IDisposable private SessionEventArgsBase(ProxyServer server, ProxyEndPoint endPoint, CancellationTokenSource cancellationTokenSource) { - bufferSize = server.BufferSize; - bufferPool = server.BufferPool; - exceptionFunc = server.ExceptionFunc; + BufferSize = server.BufferSize; + BufferPool = server.BufferPool; + ExceptionFunc = server.ExceptionFunc; TimeLine["Session Created"] = DateTime.Now; } @@ -161,7 +161,7 @@ internal void OnDataSent(byte[] buffer, int offset, int count) } 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 @@ internal void OnDataReceived(byte[] buffer, int offset, int count) } catch (Exception ex) { - exceptionFunc(new Exception("Exception thrown in user event", ex)); + ExceptionFunc(new Exception("Exception thrown in user event", ex)); } } diff --git a/src/Titanium.Web.Proxy/EventArguments/TunnelConnectEventArgs.cs b/src/Titanium.Web.Proxy/EventArguments/TunnelConnectEventArgs.cs index 47ffd896a..a4615ef39 100644 --- a/src/Titanium.Web.Proxy/EventArguments/TunnelConnectEventArgs.cs +++ b/src/Titanium.Web.Proxy/EventArguments/TunnelConnectEventArgs.cs @@ -31,12 +31,12 @@ internal TunnelConnectSessionEventArgs(ProxyServer server, ProxyEndPoint endPoin public bool DenyConnect { get; set; } /// - /// 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. /// public bool 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; } diff --git a/src/Titanium.Web.Proxy/Exceptions/ProxyException.cs b/src/Titanium.Web.Proxy/Exceptions/ProxyException.cs index 61696d8d6..e38435287 100644 --- a/src/Titanium.Web.Proxy/Exceptions/ProxyException.cs +++ b/src/Titanium.Web.Proxy/Exceptions/ProxyException.cs @@ -20,7 +20,7 @@ protected ProxyException(string message) : base(message) /// Initializes a new instance of the class. /// - must be invoked by derived classes' constructors /// - /// Excception message + /// Exception message /// Inner exception associated protected ProxyException(string message, Exception innerException) : base(message, innerException) { diff --git a/src/Titanium.Web.Proxy/ExplicitClientHandler.cs b/src/Titanium.Web.Proxy/ExplicitClientHandler.cs index d2562ff49..0d1ce0776 100644 --- a/src/Titanium.Web.Proxy/ExplicitClientHandler.cs +++ b/src/Titanium.Web.Proxy/ExplicitClientHandler.cs @@ -111,8 +111,8 @@ await clientStreamWriter.WriteResponseAsync(connectArgs.HttpClient.Response, return; } - // write back successfull CONNECT response - var response = ConnectResponse.CreateSuccessfullConnectResponse(version); + // write back successful CONNECT response + var response = ConnectResponse.CreateSuccessfulConnectResponse(version); // Set ContentLength explicitly to properly handle HTTP 1.0 response.ContentLength = 0; @@ -148,7 +148,7 @@ await clientStreamWriter.WriteResponseAsync(connectArgs.HttpClient.Response, 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); } @@ -253,7 +253,7 @@ await clientStreamWriter.WriteResponseAsync(connectArgs.HttpClient.Response, try { 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); } finally diff --git a/src/Titanium.Web.Proxy/Extensions/StreamExtensions.cs b/src/Titanium.Web.Proxy/Extensions/StreamExtensions.cs index c95545746..a8adcc89d 100644 --- a/src/Titanium.Web.Proxy/Extensions/StreamExtensions.cs +++ b/src/Titanium.Web.Proxy/Extensions/StreamExtensions.cs @@ -17,6 +17,7 @@ internal static class StreamExtensions /// /// /// + /// /// internal static Task CopyToAsync(this Stream input, Stream output, Action onCopy, IBufferPool bufferPool, int bufferSize) @@ -30,6 +31,7 @@ internal static Task CopyToAsync(this Stream input, Stream output, Action /// /// + /// /// /// internal static async Task CopyToAsync(this Stream input, Stream output, Action onCopy, diff --git a/src/Titanium.Web.Proxy/Helpers/RunTime.cs b/src/Titanium.Web.Proxy/Helpers/RunTime.cs index 66da024ad..52a1c3720 100644 --- a/src/Titanium.Web.Proxy/Helpers/RunTime.cs +++ b/src/Titanium.Web.Proxy/Helpers/RunTime.cs @@ -70,7 +70,7 @@ private class UwpHelper internal static bool IsRunningAsUwp() { - if (IsWindows7OrLower) + if (isWindows7OrLower) { return false; } @@ -87,7 +87,7 @@ internal static bool IsRunningAsUwp() } } - private static bool IsWindows7OrLower + private static bool isWindows7OrLower { get { diff --git a/src/Titanium.Web.Proxy/Helpers/SystemProxy.cs b/src/Titanium.Web.Proxy/Helpers/SystemProxy.cs index 11cd5f8f9..5e3833328 100644 --- a/src/Titanium.Web.Proxy/Helpers/SystemProxy.cs +++ b/src/Titanium.Web.Proxy/Helpers/SystemProxy.cs @@ -80,7 +80,7 @@ public SystemProxyManager() /// internal void SetProxy(string hostname, int port, ProxyProtocolType protocolType) { - using (var reg = OpenInternetSettingsKey()) + using (var reg = openInternetSettingsKey()) { if (reg == null) { @@ -127,7 +127,7 @@ internal void SetProxy(string hostname, int port, ProxyProtocolType protocolType /// internal void RemoveProxy(ProxyProtocolType protocolType, bool saveOriginalConfig = true) { - using (var reg = OpenInternetSettingsKey()) + using (var reg = openInternetSettingsKey()) { if (reg == null) { @@ -168,7 +168,7 @@ internal void RemoveProxy(ProxyProtocolType protocolType, bool saveOriginalConfi /// internal void DisableAllProxy() { - using (var reg = OpenInternetSettingsKey()) + using (var reg = openInternetSettingsKey()) { if (reg == null) { @@ -186,7 +186,7 @@ internal void DisableAllProxy() internal void SetAutoProxyUrl(string url) { - using (var reg = OpenInternetSettingsKey()) + using (var reg = openInternetSettingsKey()) { if (reg == null) { @@ -201,7 +201,7 @@ internal void SetAutoProxyUrl(string url) internal void SetProxyOverride(string proxyOverride) { - using (var reg = OpenInternetSettingsKey()) + using (var reg = openInternetSettingsKey()) { if (reg == null) { @@ -286,7 +286,7 @@ internal void RestoreOriginalSettings() internal ProxyInfo GetProxyInfoFromRegistry() { - using (var reg = OpenInternetSettingsKey()) + using (var reg = openInternetSettingsKey()) { if (reg == null) { @@ -347,7 +347,7 @@ private static void refresh() /// /// Opens the registry key with the internet settings /// - private static RegistryKey OpenInternetSettingsKey() + private static RegistryKey openInternetSettingsKey() { return Registry.CurrentUser.OpenSubKey(regKeyInternetSettings, true); } diff --git a/src/Titanium.Web.Proxy/Helpers/TcpHelper.cs b/src/Titanium.Web.Proxy/Helpers/TcpHelper.cs index f321c2e24..b16d81b58 100644 --- a/src/Titanium.Web.Proxy/Helpers/TcpHelper.cs +++ b/src/Titanium.Web.Proxy/Helpers/TcpHelper.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.IO; using System.Runtime.InteropServices; using System.Threading; @@ -96,11 +96,12 @@ private static uint toNetworkByteOrder(uint port) /// /// relays the input clientStream to the server at the specified host name and port with the given httpCmd and headers /// as prefix - /// Usefull for websocket requests + /// Useful for websocket requests /// Task-based Asynchronous Pattern /// /// /// + /// /// /// /// @@ -128,10 +129,11 @@ private static async Task sendRawTap(Stream clientStream, Stream serverStream, /// /// relays the input clientStream to the server at the specified host name and port with the given httpCmd and headers /// as prefix - /// Usefull for websocket requests + /// Useful for websocket requests /// /// /// + /// /// /// /// diff --git a/src/Titanium.Web.Proxy/Http/ConnectResponse.cs b/src/Titanium.Web.Proxy/Http/ConnectResponse.cs index 9398c7396..56748d504 100644 --- a/src/Titanium.Web.Proxy/Http/ConnectResponse.cs +++ b/src/Titanium.Web.Proxy/Http/ConnectResponse.cs @@ -12,11 +12,11 @@ public class ConnectResponse : Response public ServerHelloInfo ServerHelloInfo { get; set; } /// - /// Creates a successfull CONNECT response + /// Creates a successful CONNECT response /// /// /// - internal static ConnectResponse CreateSuccessfullConnectResponse(Version httpVersion) + internal static ConnectResponse CreateSuccessfulConnectResponse(Version httpVersion) { var response = new ConnectResponse { diff --git a/src/Titanium.Web.Proxy/Http/HeaderCollection.cs b/src/Titanium.Web.Proxy/Http/HeaderCollection.cs index e1c2fda2a..991d839fb 100644 --- a/src/Titanium.Web.Proxy/Http/HeaderCollection.cs +++ b/src/Titanium.Web.Proxy/Http/HeaderCollection.cs @@ -67,7 +67,7 @@ public bool HeaderExists(string name) /// /// Returns all headers with given name if exists - /// Returns null if does'nt exist + /// Returns null if doesn't exist /// /// /// diff --git a/src/Titanium.Web.Proxy/Http/RequestResponseBase.cs b/src/Titanium.Web.Proxy/Http/RequestResponseBase.cs index 474856326..6d00930a2 100644 --- a/src/Titanium.Web.Proxy/Http/RequestResponseBase.cs +++ b/src/Titanium.Web.Proxy/Http/RequestResponseBase.cs @@ -189,7 +189,7 @@ internal set public bool IsBodyRead { get; internal set; } /// - /// 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. /// internal bool Locked { get; set; } diff --git a/src/Titanium.Web.Proxy/Http2/Http2Helper.cs b/src/Titanium.Web.Proxy/Http2/Http2Helper.cs index e8af3fcb7..fe3c7e28e 100644 --- a/src/Titanium.Web.Proxy/Http2/Http2Helper.cs +++ b/src/Titanium.Web.Proxy/Http2/Http2Helper.cs @@ -1,4 +1,4 @@ -#if NETCOREAPP2_1 +#if NETCOREAPP2_1 using System; using System.IO; using System.Threading; @@ -22,7 +22,7 @@ internal class Http2Helper /// /// relays the input clientStream to the server at the specified host name and port with the given httpCmd and headers /// as prefix - /// Usefull for websocket requests + /// Useful for websocket requests /// Task-based Asynchronous Pattern /// /// @@ -160,4 +160,4 @@ public void AddHeader(string name, string value, bool sensitive) } } } -#endif \ No newline at end of file +#endif diff --git a/src/Titanium.Web.Proxy/Models/ExplicitProxyEndPoint.cs b/src/Titanium.Web.Proxy/Models/ExplicitProxyEndPoint.cs index 4684653f2..af4a6fb29 100644 --- a/src/Titanium.Web.Proxy/Models/ExplicitProxyEndPoint.cs +++ b/src/Titanium.Web.Proxy/Models/ExplicitProxyEndPoint.cs @@ -31,7 +31,7 @@ public ExplicitProxyEndPoint(IPAddress ipAddress, int port, bool decryptSsl = tr /// Intercept tunnel connect request. /// Valid only for explicit endpoints. /// Set the property to false if this HTTP connect request - /// should'nt be decrypted and instead be relayed. + /// shouldn't be decrypted and instead be relayed. /// public event AsyncEventHandler BeforeTunnelConnectRequest; diff --git a/src/Titanium.Web.Proxy/Models/ExternalProxy.cs b/src/Titanium.Web.Proxy/Models/ExternalProxy.cs index 865fc4bc9..d84fd88ce 100644 --- a/src/Titanium.Web.Proxy/Models/ExternalProxy.cs +++ b/src/Titanium.Web.Proxy/Models/ExternalProxy.cs @@ -70,7 +70,7 @@ public string Password public int Port { get; set; } /// - /// Get cache key for Tcp connection cahe. + /// Get cache key for Tcp connection cache. /// /// internal string GetCacheKey() diff --git a/src/Titanium.Web.Proxy/Network/CertificateManager.cs b/src/Titanium.Web.Proxy/Network/CertificateManager.cs index c7ee521e0..ab4655f31 100644 --- a/src/Titanium.Web.Proxy/Network/CertificateManager.cs +++ b/src/Titanium.Web.Proxy/Network/CertificateManager.cs @@ -49,7 +49,7 @@ private readonly ConcurrentDictionary cachedCertifica /// /// 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. /// private readonly ConcurrentDictionary> pendingCertificateCreationTasks diff --git a/src/Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs b/src/Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs index cad29767b..cea5e99f6 100644 --- a/src/Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs +++ b/src/Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs @@ -38,11 +38,11 @@ private readonly ConcurrentDictionary await clearOutdatedConnections()); } - internal ProxyServer server { get; set; } + internal ProxyServer Server { get; set; } internal string GetConnectionCacheKey(string remoteHostName, int remotePort, bool isHttps, List applicationProtocols, @@ -50,7 +50,7 @@ internal string GetConnectionCacheKey(string remoteHostName, int remotePort, { //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. - //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. var cacheKeyBuilder = new StringBuilder($"{remoteHostName}-{remotePort}-" + //when creating Tcp client isConnect won't matter @@ -232,7 +232,7 @@ private async Task createServerConnection(string remoteHost CancellationToken cancellationToken) { //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)) { throw new Exception($"A client is making HTTP request to one of the listening ports of this proxy {remoteHostName}:{remotePort}"); @@ -240,7 +240,7 @@ private async Task createServerConnection(string remoteHost 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)) { 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 @@ internal async Task Release(TcpServerConnection connection, bool close = false) return; } - if (close || connection.IsWinAuthenticated || !server.EnableConnectionPool || connection.Stream.IsClosed) + if (close || connection.IsWinAuthenticated || !Server.EnableConnectionPool || connection.Stream.IsClosed) { disposalBag.Add(connection); return; @@ -432,7 +432,7 @@ internal async Task Release(TcpServerConnection connection, bool close = false) { if (cache.TryGetValue(connection.CacheKey, out var existingConnections)) { - while (existingConnections.Count >= server.MaxCachedConnections) + while (existingConnections.Count >= Server.MaxCachedConnections) { if (existingConnections.TryDequeue(out var staleConnection)) { @@ -489,8 +489,8 @@ private async Task clearOutdatedConnections() { if (queue.TryDequeue(out var connection)) { - var cutOff = DateTime.Now.AddSeconds(-1 * server.ConnectionTimeOutSeconds); - if (!server.EnableConnectionPool + var cutOff = DateTime.Now.AddSeconds(-1 * Server.ConnectionTimeOutSeconds); + if (!Server.EnableConnectionPool || connection.LastAccess < cutOff) { disposalBag.Add(connection); @@ -530,7 +530,7 @@ private async Task clearOutdatedConnections() } 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 { diff --git a/src/Titanium.Web.Proxy/Network/WinAuth/Security/LittleEndian.cs b/src/Titanium.Web.Proxy/Network/WinAuth/Security/LittleEndian.cs index 01bb69856..7d67f1d5c 100644 --- a/src/Titanium.Web.Proxy/Network/WinAuth/Security/LittleEndian.cs +++ b/src/Titanium.Web.Proxy/Network/WinAuth/Security/LittleEndian.cs @@ -1,4 +1,4 @@ -// +// // Mono.Security.BitConverterLE.cs // Like System.BitConverter but always little endian // diff --git a/src/Titanium.Web.Proxy/ProxyServer.cs b/src/Titanium.Web.Proxy/ProxyServer.cs index dad9ac007..45d56f1f6 100644 --- a/src/Titanium.Web.Proxy/ProxyServer.cs +++ b/src/Titanium.Web.Proxy/ProxyServer.cs @@ -146,7 +146,7 @@ public ProxyServer(string rootCertificateName, string rootCertificateIssuerName, public bool EnableWinAuth { get; set; } /// - /// 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. /// public X509RevocationMode CheckCertificateRevocation { get; set; } @@ -169,7 +169,7 @@ public ProxyServer(string rootCertificateName, string rootCertificateIssuerName, /// 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 /// 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. /// public bool EnableTcpServerConnectionPrefetch { get; set; } = true; @@ -380,7 +380,7 @@ public void AddEndPoint(ProxyEndPoint endPoint) /// /// 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. /// /// The existing endpoint to remove. public void RemoveEndPoint(ProxyEndPoint endPoint) @@ -743,13 +743,11 @@ private void onAcceptConnection(IAsyncResult asyn) /// /// Change the ThreadPool.WorkerThread minThread /// - /// minimum Threads allocated in the ThreadPool + /// minimum Threads allocated in the ThreadPool private void setThreadPoolMinThread(int workerThreads) { - int minWorkerThreads, minCompletionPortThreads, maxWorkerThreads; - - ThreadPool.GetMinThreads(out minWorkerThreads, out minCompletionPortThreads); - ThreadPool.GetMaxThreads(out maxWorkerThreads, out _); + ThreadPool.GetMinThreads(out int minWorkerThreads, out int minCompletionPortThreads); + ThreadPool.GetMaxThreads(out int maxWorkerThreads, out _); minWorkerThreads = Math.Min(maxWorkerThreads, Math.Max(workerThreads, Environment.ProcessorCount)); diff --git a/src/Titanium.Web.Proxy/RequestHandler.cs b/src/Titanium.Web.Proxy/RequestHandler.cs index 1800cc2aa..e76657ade 100644 --- a/src/Titanium.Web.Proxy/RequestHandler.cs +++ b/src/Titanium.Web.Proxy/RequestHandler.cs @@ -44,7 +44,7 @@ public partial class ProxyServer /// The https hostname as appeared in CONNECT request if this is a HTTPS request from /// explicit endpoint. /// - /// The Connect request if this is a HTTPS request from explicit endpoint. + /// The Connect request if this is a HTTPS request from explicit endpoint. /// Prefetched server connection for current client using Connect/SNI headers. private async Task handleHttpSessionRequest(ProxyEndPoint endPoint, TcpClientConnection clientConnection, CustomBufferedStream clientStream, HttpResponseWriter clientStreamWriter, @@ -61,7 +61,7 @@ private async Task handleHttpSessionRequest(ProxyEndPoint endPoint, TcpClientCon { 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) while (true) { @@ -373,7 +373,7 @@ await clientStreamWriter.WriteResponseStatusAsync(response.HttpVersion, response } /// - /// 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 /// private void prepareRequestHeaders(HeaderCollection requestHeaders) { diff --git a/src/Titanium.Web.Proxy/ResponseHandler.cs b/src/Titanium.Web.Proxy/ResponseHandler.cs index c352523e0..ba9110f3c 100644 --- a/src/Titanium.Web.Proxy/ResponseHandler.cs +++ b/src/Titanium.Web.Proxy/ResponseHandler.cs @@ -14,7 +14,7 @@ namespace Titanium.Web.Proxy public partial class ProxyServer { /// - /// Called asynchronously when a request was successfull and we received the response. + /// Called asynchronously when a request was successful and we received the response. /// /// The session event arguments. /// The task. diff --git a/src/Titanium.Web.Proxy/TransparentClientHandler.cs b/src/Titanium.Web.Proxy/TransparentClientHandler.cs index a8529a1ed..b5e429be8 100644 --- a/src/Titanium.Web.Proxy/TransparentClientHandler.cs +++ b/src/Titanium.Web.Proxy/TransparentClientHandler.cs @@ -112,7 +112,7 @@ private async Task handleClient(TransparentProxyEndPoint endPoint, TcpClientConn var data = BufferPool.GetBuffer(BufferSize); 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); serverStream = connection.Stream; await serverStream.WriteAsync(data, 0, available, cancellationToken); diff --git a/src/Titanium.Web.Proxy/WinAuthHandler.cs b/src/Titanium.Web.Proxy/WinAuthHandler.cs index 05171e137..51eef6ede 100644 --- a/src/Titanium.Web.Proxy/WinAuthHandler.cs +++ b/src/Titanium.Web.Proxy/WinAuthHandler.cs @@ -150,7 +150,7 @@ private async Task handle401UnAuthorized(SessionEventArgs args) } // 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? // Let ResponseHandler send the updated request diff --git a/tests/Titanium.Web.Proxy.IntegrationTests/Helpers/HttpMessageParsing.cs b/tests/Titanium.Web.Proxy.IntegrationTests/Helpers/HttpMessageParsing.cs index e5cae16f7..e4cc05c53 100644 --- a/tests/Titanium.Web.Proxy.IntegrationTests/Helpers/HttpMessageParsing.cs +++ b/tests/Titanium.Web.Proxy.IntegrationTests/Helpers/HttpMessageParsing.cs @@ -43,7 +43,7 @@ internal static Request ParseRequest(string messageText, bool requireBody) if (!requireBody) return request as Request; - if (ParseBody(reader, ref request)) + if (parseBody(reader, ref request)) return request as Request; } catch { } @@ -84,7 +84,7 @@ internal static Response ParseResponse(string messageText) if (line?.Length != 0) return null; - if (ParseBody(reader, ref response)) + if (parseBody(reader, ref response)) return response as Response; } catch { } @@ -92,7 +92,7 @@ internal static Response ParseResponse(string messageText) return null; } - private static bool ParseBody(StringReader reader, ref RequestResponseBase obj) + private static bool parseBody(StringReader reader, ref RequestResponseBase obj) { obj.OriginalContentLength = obj.ContentLength; if (obj.ContentLength <= 0) diff --git a/tests/Titanium.Web.Proxy.UnitTests/SystemProxyTest.cs b/tests/Titanium.Web.Proxy.UnitTests/SystemProxyTest.cs index 4d8afa358..12bdd1ae1 100644 --- a/tests/Titanium.Web.Proxy.UnitTests/SystemProxyTest.cs +++ b/tests/Titanium.Web.Proxy.UnitTests/SystemProxyTest.cs @@ -11,22 +11,22 @@ namespace Titanium.Web.Proxy.UnitTests public class SystemProxyTest { [TestMethod] - public void CompareProxyAdddressReturendByWebProxyAndWinHttpProxyResolver() + public void CompareProxyAddressReturnedByWebProxyAndWinHttpProxyResolver() { var proxyManager = new SystemProxyManager(); try { - CompareUrls(); + compareUrls(); proxyManager.SetProxy("127.0.0.1", 8000, ProxyProtocolType.Http); - CompareUrls(); + compareUrls(); proxyManager.SetProxy("127.0.0.1", 8000, ProxyProtocolType.Https); - CompareUrls(); + compareUrls(); 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 //function FindProxyForURL(url, host) @@ -43,25 +43,25 @@ public void CompareProxyAdddressReturendByWebProxyAndWinHttpProxyResolver() //CompareUrls(); proxyManager.SetProxyOverride("<-loopback>"); - CompareUrls(); + compareUrls(); proxyManager.SetProxyOverride(""); - CompareUrls(); + compareUrls(); proxyManager.SetProxyOverride("yahoo.com"); - CompareUrls(); + compareUrls(); proxyManager.SetProxyOverride("*.local"); - CompareUrls(); + compareUrls(); proxyManager.SetProxyOverride("http://*.local"); - CompareUrls(); + compareUrls(); proxyManager.SetProxyOverride("<-loopback>;*.local"); - CompareUrls(); + compareUrls(); proxyManager.SetProxyOverride("<-loopback>;*.local;"); - CompareUrls(); + compareUrls(); } finally { @@ -69,7 +69,7 @@ public void CompareProxyAdddressReturendByWebProxyAndWinHttpProxyResolver() } } - private void CompareUrls() + private void compareUrls() { var webProxy = WebRequest.GetSystemWebProxy();