Commit 3114902b authored by justcoding121's avatar justcoding121

private methods => camelCase

parent 300f4f80
......@@ -41,7 +41,7 @@ namespace Titanium.Web.Proxy.EventArguments
set => throw new NotSupportedException();
}
private void GetNextChunk()
private void getNextChunk()
{
if (readChunkTrail)
{
......@@ -96,7 +96,7 @@ namespace Titanium.Web.Proxy.EventArguments
{
if (isChunked)
{
GetNextChunk();
getNextChunk();
}
else
{
......
......@@ -69,12 +69,12 @@ namespace Titanium.Web.Proxy.EventArguments
/// </summary>
public event EventHandler<MultipartRequestPartSentEventArgs> MultipartRequestPartSent;
private ICustomStreamReader GetStreamReader(bool isRequest)
private ICustomStreamReader getStreamReader(bool isRequest)
{
return isRequest ? ProxyClient.ClientStream : WebSession.ServerConnection.Stream;
}
private HttpWriter GetStreamWriter(bool isRequest)
private HttpWriter getStreamWriter(bool isRequest)
{
return isRequest ? (HttpWriter)ProxyClient.ClientStreamWriter : WebSession.ServerConnection.StreamWriter;
}
......@@ -82,7 +82,7 @@ namespace Titanium.Web.Proxy.EventArguments
/// <summary>
/// Read request body content as bytes[] for current session
/// </summary>
private async Task ReadRequestBodyAsync(CancellationToken cancellationToken)
private async Task readRequestBodyAsync(CancellationToken cancellationToken)
{
WebSession.Request.EnsureBodyAvailable(false);
......@@ -91,7 +91,7 @@ namespace Titanium.Web.Proxy.EventArguments
// If not already read (not cached yet)
if (!request.IsBodyRead)
{
var body = await ReadBodyAsync(true, cancellationToken);
var body = await readBodyAsync(true, cancellationToken);
request.Body = body;
// Now set the flag to true
......@@ -126,7 +126,7 @@ namespace Titanium.Web.Proxy.EventArguments
/// <summary>
/// Read response body as byte[] for current response
/// </summary>
private async Task ReadResponseBodyAsync(CancellationToken cancellationToken)
private async Task readResponseBodyAsync(CancellationToken cancellationToken)
{
if (!WebSession.Request.Locked)
{
......@@ -142,7 +142,7 @@ namespace Titanium.Web.Proxy.EventArguments
// If not already read (not cached yet)
if (!response.IsBodyRead)
{
var body = await ReadBodyAsync(false, cancellationToken);
var body = await readBodyAsync(false, cancellationToken);
response.Body = body;
// Now set the flag to true
......@@ -152,7 +152,7 @@ namespace Titanium.Web.Proxy.EventArguments
}
}
private async Task<byte[]> ReadBodyAsync(bool isRequest, CancellationToken cancellationToken)
private async Task<byte[]> readBodyAsync(bool isRequest, CancellationToken cancellationToken)
{
using (var bodyStream = new MemoryStream())
{
......@@ -182,7 +182,7 @@ namespace Titanium.Web.Proxy.EventArguments
using (var bodyStream = new MemoryStream())
{
var writer = new HttpWriter(bodyStream, BufferSize);
await CopyBodyAsync(isRequest, writer, TransformationMode.None, null, cancellationToken);
await copyBodyAsync(isRequest, writer, TransformationMode.None, null, cancellationToken);
}
}
......@@ -199,14 +199,14 @@ namespace Titanium.Web.Proxy.EventArguments
// send the request body bytes to server
if (contentLength > 0 && hasMulipartEventSubscribers && request.IsMultipartFormData)
{
var reader = GetStreamReader(true);
var reader = getStreamReader(true);
string boundary = HttpHelper.GetBoundaryFromContentType(request.ContentType);
using (var copyStream = new CopyStream(reader, writer, BufferSize))
{
while (contentLength > copyStream.ReadBytes)
{
long read = await ReadUntilBoundaryAsync(copyStream, contentLength, boundary, cancellationToken);
long read = await readUntilBoundaryAsync(copyStream, contentLength, boundary, cancellationToken);
if (read == 0)
{
break;
......@@ -225,18 +225,18 @@ namespace Titanium.Web.Proxy.EventArguments
}
else
{
await CopyBodyAsync(true, writer, transformation, OnDataSent, cancellationToken);
await copyBodyAsync(true, writer, transformation, OnDataSent, cancellationToken);
}
}
internal async Task CopyResponseBodyAsync(HttpWriter writer, TransformationMode transformation, CancellationToken cancellationToken)
{
await CopyBodyAsync(false, writer, transformation, OnDataReceived, cancellationToken);
await copyBodyAsync(false, writer, transformation, OnDataReceived, cancellationToken);
}
private async Task CopyBodyAsync(bool isRequest, HttpWriter writer, TransformationMode transformation, Action<byte[], int, int> onCopy, CancellationToken cancellationToken)
private async Task copyBodyAsync(bool isRequest, HttpWriter writer, TransformationMode transformation, Action<byte[], int, int> onCopy, CancellationToken cancellationToken)
{
var stream = GetStreamReader(isRequest);
var stream = getStreamReader(isRequest);
var requestResponse = isRequest ? (RequestResponseBase)WebSession.Request : WebSession.Response;
......@@ -280,7 +280,7 @@ namespace Titanium.Web.Proxy.EventArguments
/// Read a line from the byte stream
/// </summary>
/// <returns></returns>
private async Task<long> ReadUntilBoundaryAsync(ICustomStreamReader reader, long totalBytesToRead, string boundary, CancellationToken cancellationToken)
private async Task<long> readUntilBoundaryAsync(ICustomStreamReader reader, long totalBytesToRead, string boundary, CancellationToken cancellationToken)
{
int bufferDataLength = 0;
......@@ -347,7 +347,7 @@ namespace Titanium.Web.Proxy.EventArguments
{
if (!WebSession.Request.IsBodyRead)
{
await ReadRequestBodyAsync(cancellationToken);
await readRequestBodyAsync(cancellationToken);
}
return WebSession.Request.Body;
......@@ -362,7 +362,7 @@ namespace Titanium.Web.Proxy.EventArguments
{
if (!WebSession.Request.IsBodyRead)
{
await ReadRequestBodyAsync(cancellationToken);
await readRequestBodyAsync(cancellationToken);
}
return WebSession.Request.BodyString;
......@@ -407,7 +407,7 @@ namespace Titanium.Web.Proxy.EventArguments
{
if (!WebSession.Response.IsBodyRead)
{
await ReadResponseBodyAsync(cancellationToken);
await readResponseBodyAsync(cancellationToken);
}
return WebSession.Response.Body;
......@@ -422,7 +422,7 @@ namespace Titanium.Web.Proxy.EventArguments
{
if (!WebSession.Response.IsBodyRead)
{
await ReadResponseBodyAsync(cancellationToken);
await readResponseBodyAsync(cancellationToken);
}
return WebSession.Response.BodyString;
......
using System;
namespace Titanium.Web.Proxy.Exceptions
{
/// <summary>
/// The server connection was closed.
/// </summary>
public class ServerConnectionException : ProxyException
{
internal ServerConnectionException(string message) : base(message)
{
}
/// <summary>
/// Constructor.
/// </summary>
/// <param name="message"></param>
/// <param name="e"></param>
internal ServerConnectionException(string message, Exception e) : base(message, e)
{
}
}
}
......@@ -29,7 +29,7 @@ namespace Titanium.Web.Proxy
/// <param name="endPoint">The explicit endpoint.</param>
/// <param name="clientConnection">The client connection.</param>
/// <returns>The task.</returns>
private async Task HandleClient(ExplicitProxyEndPoint endPoint, TcpClientConnection clientConnection)
private async Task handleClient(ExplicitProxyEndPoint endPoint, TcpClientConnection clientConnection)
{
var cancellationTokenSource = new CancellationTokenSource();
var cancellationToken = cancellationTokenSource.Token;
......@@ -95,7 +95,7 @@ namespace Titanium.Web.Proxy
return;
}
if (await CheckAuthorization(connectArgs) == false)
if (await checkAuthorization(connectArgs) == false)
{
await endPoint.InvokeBeforeTunnectConnectResponse(this, connectArgs, ExceptionFunc);
......@@ -136,7 +136,7 @@ namespace Titanium.Web.Proxy
{
// test server HTTP/2 support
// todo: this is a hack, because Titanium does not support HTTP protocol changing currently
var connection = await GetServerConnection(connectArgs, true,
var connection = await getServerConnection(connectArgs, true,
SslExtensions.Http2ProtocolAsList, cancellationToken);
http2Supproted = connection.NegotiatedApplicationProtocol == SslApplicationProtocol.Http2;
......@@ -201,7 +201,7 @@ namespace Titanium.Web.Proxy
if (!decryptSsl || !isClientHello)
{
// create new connection
var connection = await GetServerConnection(connectArgs, true,
var connection = await getServerConnection(connectArgs, true,
clientConnection.NegotiatedApplicationProtocol, cancellationToken);
if (isClientHello)
......@@ -266,7 +266,7 @@ namespace Titanium.Web.Proxy
}
// create new connection
var connection = await GetServerConnection(connectArgs, true, SslExtensions.Http2ProtocolAsList,
var connection = await getServerConnection(connectArgs, true, SslExtensions.Http2ProtocolAsList,
cancellationToken);
await connection.StreamWriter.WriteLineAsync("PRI * HTTP/2.0", cancellationToken);
......@@ -285,24 +285,24 @@ namespace Titanium.Web.Proxy
}
// Now create the request
await HandleHttpSessionRequest(endPoint, clientConnection, clientStream, clientStreamWriter,
await handleHttpSessionRequest(endPoint, clientConnection, clientStream, clientStreamWriter,
cancellationTokenSource, connectHostname, connectArgs?.WebSession.ConnectRequest);
}
catch (ProxyException e)
{
OnException(clientStream, e);
onException(clientStream, e);
}
catch (IOException e)
{
OnException(clientStream, new Exception("Connection was aborted", e));
onException(clientStream, new Exception("Connection was aborted", e));
}
catch (SocketException e)
{
OnException(clientStream, new Exception("Could not connect", e));
onException(clientStream, new Exception("Could not connect", e));
}
catch (Exception e)
{
OnException(clientStream, new Exception("Error occured in whilst handling the client", e));
onException(clientStream, new Exception("Error occured in whilst handling the client", e));
}
finally
{
......
......@@ -13,11 +13,11 @@ namespace Titanium.Web.Proxy.Extensions
foreach (var @delegate in invocationList)
{
await InternalInvokeAsync((AsyncEventHandler<T>)@delegate, sender, args, exceptionFunc);
await internalInvokeAsync((AsyncEventHandler<T>)@delegate, sender, args, exceptionFunc);
}
}
private static async Task InternalInvokeAsync<T>(AsyncEventHandler<T> callback, object sender, T args,
private static async Task internalInvokeAsync<T>(AsyncEventHandler<T> callback, object sender, T args,
ExceptionHandler exceptionFunc)
{
try
......
......@@ -43,7 +43,7 @@ namespace Titanium.Web.Proxy.Extensions
// cancellation is not working on Socket ReadAsync
// https://github.com/dotnet/corefx/issues/15033
int num = await input.ReadAsync(buffer, 0, buffer.Length, CancellationToken.None)
.WithCancellation(cancellationToken);
.withCancellation(cancellationToken);
int bytesRead;
if ((bytesRead = num) != 0 && !cancellationToken.IsCancellationRequested)
{
......@@ -62,7 +62,7 @@ namespace Titanium.Web.Proxy.Extensions
}
}
private static async Task<T> WithCancellation<T>(this Task<T> task, CancellationToken cancellationToken)
private static async Task<T> withCancellation<T>(this Task<T> task, CancellationToken cancellationToken)
{
var tcs = new TaskCompletionSource<bool>();
using (cancellationToken.Register(s => ((TaskCompletionSource<bool>)s).TrySetResult(true), tcs))
......
......@@ -122,7 +122,7 @@ namespace Titanium.Web.Proxy.Helpers
/// <returns>1: when CONNECT, 0: when valid HTTP method, -1: otherwise</returns>
internal static Task<int> IsConnectMethod(ICustomStreamReader clientStreamReader)
{
return StartsWith(clientStreamReader, "CONNECT");
return startsWith(clientStreamReader, "CONNECT");
}
/// <summary>
......@@ -132,7 +132,7 @@ namespace Titanium.Web.Proxy.Helpers
/// <returns>1: when PRI, 0: when valid HTTP method, -1: otherwise</returns>
internal static Task<int> IsPriMethod(ICustomStreamReader clientStreamReader)
{
return StartsWith(clientStreamReader, "PRI");
return startsWith(clientStreamReader, "PRI");
}
/// <summary>
......@@ -143,7 +143,7 @@ namespace Titanium.Web.Proxy.Helpers
/// <returns>
/// 1: when starts with the given string, 0: when valid HTTP method, -1: otherwise
/// </returns>
private static async Task<int> StartsWith(ICustomStreamReader clientStreamReader, string expectedStart)
private static async Task<int> startsWith(ICustomStreamReader clientStreamReader, string expectedStart)
{
bool isExpected = true;
int legthToCheck = 10;
......
......@@ -44,10 +44,10 @@ namespace Titanium.Web.Proxy.Helpers
internal Task WriteAsync(string value, CancellationToken cancellationToken = default)
{
return WriteAsyncInternal(value, false, cancellationToken);
return writeAsyncInternal(value, false, cancellationToken);
}
private Task WriteAsyncInternal(string value, bool addNewLine, CancellationToken cancellationToken)
private Task writeAsyncInternal(string value, bool addNewLine, CancellationToken cancellationToken)
{
int newLineChars = addNewLine ? newLine.Length : 0;
int charCount = value.Length;
......@@ -91,7 +91,7 @@ namespace Titanium.Web.Proxy.Helpers
internal Task WriteLineAsync(string value, CancellationToken cancellationToken = default)
{
return WriteAsyncInternal(value, true, cancellationToken);
return writeAsyncInternal(value, true, cancellationToken);
}
/// <summary>
......@@ -149,7 +149,7 @@ namespace Titanium.Web.Proxy.Helpers
{
if (isChunked)
{
return WriteBodyChunkedAsync(data, cancellationToken);
return writeBodyChunkedAsync(data, cancellationToken);
}
return WriteAsync(data, cancellationToken: cancellationToken);
......@@ -171,7 +171,7 @@ namespace Titanium.Web.Proxy.Helpers
// For chunked request we need to read data as they arrive, until we reach a chunk end symbol
if (isChunked)
{
return CopyBodyChunkedAsync(streamReader, onCopy, cancellationToken);
return copyBodyChunkedAsync(streamReader, onCopy, cancellationToken);
}
// http 1.0 or the stream reader limits the stream
......@@ -181,7 +181,7 @@ namespace Titanium.Web.Proxy.Helpers
}
// If not chunked then its easy just read the amount of bytes mentioned in content length header
return CopyBytesFromStream(streamReader, contentLength, onCopy, cancellationToken);
return copyBytesFromStream(streamReader, contentLength, onCopy, cancellationToken);
}
/// <summary>
......@@ -190,7 +190,7 @@ namespace Titanium.Web.Proxy.Helpers
/// <param name="data"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
private async Task WriteBodyChunkedAsync(byte[] data, CancellationToken cancellationToken)
private async Task writeBodyChunkedAsync(byte[] data, CancellationToken cancellationToken)
{
var chunkHead = Encoding.ASCII.GetBytes(data.Length.ToString("x2"));
......@@ -210,7 +210,7 @@ namespace Titanium.Web.Proxy.Helpers
/// <param name="onCopy"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
private async Task CopyBodyChunkedAsync(ICustomStreamReader reader, Action<byte[], int, int> onCopy,
private async Task copyBodyChunkedAsync(ICustomStreamReader reader, Action<byte[], int, int> onCopy,
CancellationToken cancellationToken)
{
while (true)
......@@ -228,7 +228,7 @@ namespace Titanium.Web.Proxy.Helpers
if (chunkSize != 0)
{
await CopyBytesFromStream(reader, chunkSize, onCopy, cancellationToken);
await copyBytesFromStream(reader, chunkSize, onCopy, cancellationToken);
}
await WriteLineAsync(cancellationToken);
......@@ -251,7 +251,7 @@ namespace Titanium.Web.Proxy.Helpers
/// <param name="onCopy"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
private async Task CopyBytesFromStream(ICustomStreamReader reader, long count, Action<byte[], int, int> onCopy,
private async Task copyBytesFromStream(ICustomStreamReader reader, long count, Action<byte[], int, int> onCopy,
CancellationToken cancellationToken)
{
var buffer = BufferPool.GetBuffer(BufferSize);
......
......@@ -39,7 +39,7 @@ namespace Titanium.Web.Proxy.Helpers
}
else
{
overrides2.Add(BypassStringEscape(overrideHost));
overrides2.Add(bypassStringEscape(overrideHost));
}
}
......@@ -70,7 +70,7 @@ namespace Titanium.Web.Proxy.Helpers
internal string[] BypassList { get; }
private static string BypassStringEscape(string rawString)
private static string bypassStringEscape(string rawString)
{
var match =
new Regex("^(?<scheme>.*://)?(?<host>[^:]*)(?<port>:[0-9]{1,5})?$",
......@@ -91,9 +91,9 @@ namespace Titanium.Web.Proxy.Helpers
empty2 = string.Empty;
}
string str1 = ConvertRegexReservedChars(empty1);
string str2 = ConvertRegexReservedChars(rawString1);
string str3 = ConvertRegexReservedChars(empty2);
string str1 = convertRegexReservedChars(empty1);
string str2 = convertRegexReservedChars(rawString1);
string str3 = convertRegexReservedChars(empty2);
if (str1 == string.Empty)
{
str1 = "(?:.*://)?";
......@@ -107,7 +107,7 @@ namespace Titanium.Web.Proxy.Helpers
return "^" + str1 + str2 + str3 + "$";
}
private static string ConvertRegexReservedChars(string rawString)
private static string convertRegexReservedChars(string rawString)
{
if (rawString.Length == 0)
{
......@@ -171,11 +171,11 @@ namespace Titanium.Web.Proxy.Helpers
if (proxyValues.Length > 0)
{
result.AddRange(proxyValues.Select(ParseProxyValue).Where(parsedValue => parsedValue != null));
result.AddRange(proxyValues.Select(parseProxyValue).Where(parsedValue => parsedValue != null));
}
else
{
var parsedValue = ParseProxyValue(proxyServerValues);
var parsedValue = parseProxyValue(proxyServerValues);
if (parsedValue != null)
{
result.Add(parsedValue);
......@@ -190,7 +190,7 @@ namespace Titanium.Web.Proxy.Helpers
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
private static HttpSystemProxyValue ParseProxyValue(string value)
private static HttpSystemProxyValue parseProxyValue(string value)
{
string tmp = Regex.Replace(value, @"\s+", " ").Trim();
......
......@@ -84,8 +84,8 @@ namespace Titanium.Web.Proxy.Helpers
if (reg != null)
{
SaveOriginalProxyConfiguration(reg);
PrepareRegistry(reg);
saveOriginalProxyConfiguration(reg);
prepareRegistry(reg);
string exisitingContent = reg.GetValue(regProxyServer) as string;
var existingSystemProxyValues = ProxyInfo.GetSystemProxyValues(exisitingContent);
......@@ -115,7 +115,7 @@ namespace Titanium.Web.Proxy.Helpers
reg.SetValue(regProxyServer,
string.Join(";", existingSystemProxyValues.Select(x => x.ToString()).ToArray()));
Refresh();
refresh();
}
}
......@@ -129,7 +129,7 @@ namespace Titanium.Web.Proxy.Helpers
{
if (saveOriginalConfig)
{
SaveOriginalProxyConfiguration(reg);
saveOriginalProxyConfiguration(reg);
}
if (reg.GetValue(regProxyServer) != null)
......@@ -152,7 +152,7 @@ namespace Titanium.Web.Proxy.Helpers
}
}
Refresh();
refresh();
}
}
......@@ -165,12 +165,12 @@ namespace Titanium.Web.Proxy.Helpers
if (reg != null)
{
SaveOriginalProxyConfiguration(reg);
saveOriginalProxyConfiguration(reg);
reg.SetValue(regProxyEnable, 0);
reg.SetValue(regProxyServer, string.Empty);
Refresh();
refresh();
}
}
......@@ -180,9 +180,9 @@ namespace Titanium.Web.Proxy.Helpers
if (reg != null)
{
SaveOriginalProxyConfiguration(reg);
saveOriginalProxyConfiguration(reg);
reg.SetValue(regAutoConfigUrl, url);
Refresh();
refresh();
}
}
......@@ -192,9 +192,9 @@ namespace Titanium.Web.Proxy.Helpers
if (reg != null)
{
SaveOriginalProxyConfiguration(reg);
saveOriginalProxyConfiguration(reg);
reg.SetValue(regProxyOverride, proxyOverride);
Refresh();
refresh();
}
}
......@@ -247,7 +247,7 @@ namespace Titanium.Web.Proxy.Helpers
}
originalValues = null;
Refresh();
refresh();
}
}
......@@ -257,13 +257,13 @@ namespace Titanium.Web.Proxy.Helpers
if (reg != null)
{
return GetProxyInfoFromRegistry(reg);
return getProxyInfoFromRegistry(reg);
}
return null;
}
private ProxyInfo GetProxyInfoFromRegistry(RegistryKey reg)
private ProxyInfo getProxyInfoFromRegistry(RegistryKey reg)
{
var pi = new ProxyInfo(null, reg.GetValue(regAutoConfigUrl) as string, reg.GetValue(regProxyEnable) as int?,
reg.GetValue(regProxyServer) as string,
......@@ -272,21 +272,21 @@ namespace Titanium.Web.Proxy.Helpers
return pi;
}
private void SaveOriginalProxyConfiguration(RegistryKey reg)
private void saveOriginalProxyConfiguration(RegistryKey reg)
{
if (originalValues != null)
{
return;
}
originalValues = GetProxyInfoFromRegistry(reg);
originalValues = getProxyInfoFromRegistry(reg);
}
/// <summary>
/// Prepares the proxy server registry (create empty values if they don't exist)
/// </summary>
/// <param name="reg"></param>
private static void PrepareRegistry(RegistryKey reg)
private static void prepareRegistry(RegistryKey reg)
{
if (reg.GetValue(regProxyEnable) == null)
{
......@@ -302,7 +302,7 @@ namespace Titanium.Web.Proxy.Helpers
/// <summary>
/// Refresh the settings so that the system know about a change in proxy setting
/// </summary>
private void Refresh()
private static void refresh()
{
NativeMethods.InternetSetOption(IntPtr.Zero, InternetOptionSettingsChanged, IntPtr.Zero, 0);
NativeMethods.InternetSetOption(IntPtr.Zero, InternetOptionRefresh, IntPtr.Zero, 0);
......
......@@ -39,7 +39,7 @@ namespace Titanium.Web.Proxy.Helpers
0) == 0)
{
int rowCount = *(int*)tcpTable;
uint portInNetworkByteOrder = ToNetworkByteOrder((uint)localPort);
uint portInNetworkByteOrder = toNetworkByteOrder((uint)localPort);
if (ipVersion == IpVersion.Ipv4)
{
......@@ -90,7 +90,7 @@ namespace Titanium.Web.Proxy.Helpers
/// </summary>
/// <param name="port"></param>
/// <returns></returns>
private static uint ToNetworkByteOrder(uint port)
private static uint toNetworkByteOrder(uint port)
{
return ((port >> 8) & 0x00FF00FFu) | ((port << 8) & 0xFF00FF00u);
}
......@@ -122,8 +122,8 @@ namespace Titanium.Web.Proxy.Helpers
var serverBuffer = BufferPool.GetBuffer(bufferSize);
try
{
BeginRead(clientStream, serverStream, clientBuffer, onDataSend, cancellationTokenSource, exceptionFunc);
BeginRead(serverStream, clientStream, serverBuffer, onDataReceive, cancellationTokenSource,
beginRead(clientStream, serverStream, clientBuffer, onDataSend, cancellationTokenSource, exceptionFunc);
beginRead(serverStream, clientStream, serverBuffer, onDataReceive, cancellationTokenSource,
exceptionFunc);
await taskCompletionSource.Task;
}
......@@ -134,7 +134,7 @@ namespace Titanium.Web.Proxy.Helpers
}
}
private static void BeginRead(Stream inputStream, Stream outputStream, byte[] buffer,
private static void beginRead(Stream inputStream, Stream outputStream, byte[] buffer,
Action<byte[], int, int> onCopy, CancellationTokenSource cancellationTokenSource,
ExceptionHandler exceptionFunc)
{
......@@ -174,7 +174,7 @@ namespace Titanium.Web.Proxy.Helpers
try
{
outputStream.EndWrite(ar2);
BeginRead(inputStream, outputStream, buffer, onCopy, cancellationTokenSource,
beginRead(inputStream, outputStream, buffer, onCopy, cancellationTokenSource,
exceptionFunc);
}
catch (IOException ex)
......@@ -214,7 +214,7 @@ namespace Titanium.Web.Proxy.Helpers
/// <param name="cancellationTokenSource"></param>
/// <param name="exceptionFunc"></param>
/// <returns></returns>
private static async Task SendRawTap(Stream clientStream, Stream serverStream, int bufferSize,
private static async Task sendRawTap(Stream clientStream, Stream serverStream, int bufferSize,
Action<byte[], int, int> onDataSend, Action<byte[], int, int> onDataReceive,
CancellationTokenSource cancellationTokenSource,
ExceptionHandler exceptionFunc)
......@@ -250,7 +250,7 @@ namespace Titanium.Web.Proxy.Helpers
ExceptionHandler exceptionFunc)
{
// todo: fix APM mode
return SendRawTap(clientStream, serverStream, bufferSize, onDataSend, onDataReceive,
return sendRawTap(clientStream, serverStream, bufferSize, onDataSend, onDataReceive,
cancellationTokenSource,
exceptionFunc);
}
......
......@@ -19,7 +19,7 @@ namespace Titanium.Web.Proxy.Helpers.WinHttp
session = NativeMethods.WinHttp.WinHttpOpen(null, NativeMethods.WinHttp.AccessType.NoProxy, null, null, 0);
if (session == null || session.IsInvalid)
{
int lastWin32Error = GetLastWin32Error();
int lastWin32Error = getLastWin32Error();
}
else
{
......@@ -30,7 +30,7 @@ namespace Titanium.Web.Proxy.Helpers.WinHttp
return;
}
int lastWin32Error = GetLastWin32Error();
int lastWin32Error = getLastWin32Error();
}
}
......@@ -50,7 +50,7 @@ namespace Titanium.Web.Proxy.Helpers.WinHttp
public void Dispose()
{
Dispose(true);
dispose(true);
}
public bool GetAutoProxies(Uri destination, out IList<string> proxyList)
......@@ -65,8 +65,8 @@ namespace Titanium.Web.Proxy.Helpers.WinHttp
var errorCode = NativeMethods.WinHttp.ErrorCodes.AudodetectionFailed;
if (AutomaticallyDetectSettings && !autoDetectFailed)
{
errorCode = (NativeMethods.WinHttp.ErrorCodes)GetAutoProxies(destination, null, out proxyListString);
autoDetectFailed = IsErrorFatalForAutoDetect(errorCode);
errorCode = (NativeMethods.WinHttp.ErrorCodes)getAutoProxies(destination, null, out proxyListString);
autoDetectFailed = isErrorFatalForAutoDetect(errorCode);
if (errorCode == NativeMethods.WinHttp.ErrorCodes.UnrecognizedScheme)
{
state = AutoWebProxyState.UnrecognizedScheme;
......@@ -74,13 +74,13 @@ namespace Titanium.Web.Proxy.Helpers.WinHttp
}
}
if (AutomaticConfigurationScript != null && IsRecoverableAutoProxyError(errorCode))
if (AutomaticConfigurationScript != null && isRecoverableAutoProxyError(errorCode))
{
errorCode = (NativeMethods.WinHttp.ErrorCodes)GetAutoProxies(destination, AutomaticConfigurationScript,
errorCode = (NativeMethods.WinHttp.ErrorCodes)getAutoProxies(destination, AutomaticConfigurationScript,
out proxyListString);
}
state = GetStateFromErrorCode(errorCode);
state = getStateFromErrorCode(errorCode);
if (state != AutoWebProxyState.Completed)
{
return false;
......@@ -88,7 +88,7 @@ namespace Titanium.Web.Proxy.Helpers.WinHttp
if (!string.IsNullOrEmpty(proxyListString))
{
proxyListString = RemoveWhitespaces(proxyListString);
proxyListString = removeWhitespaces(proxyListString);
proxyList = proxyListString.Split(';');
}
......@@ -149,7 +149,7 @@ namespace Titanium.Web.Proxy.Helpers.WinHttp
public void LoadFromIE()
{
var pi = GetProxyInfo();
var pi = getProxyInfo();
ProxyInfo = pi;
AutomaticallyDetectSettings = pi.AutoDetect == true;
AutomaticConfigurationScript = pi.AutoConfigUrl == null ? null : new Uri(pi.AutoConfigUrl);
......@@ -158,7 +158,7 @@ namespace Titanium.Web.Proxy.Helpers.WinHttp
proxy = new WebProxy(new Uri("http://localhost"), BypassOnLocal, pi.BypassList);
}
private ProxyInfo GetProxyInfo()
private ProxyInfo getProxyInfo()
{
var proxyConfig = new NativeMethods.WinHttp.WINHTTP_CURRENT_USER_IE_PROXY_CONFIG();
RuntimeHelpers.PrepareConstrainedRegions();
......@@ -200,7 +200,7 @@ namespace Titanium.Web.Proxy.Helpers.WinHttp
autoDetectFailed = false;
}
private void Dispose(bool disposing)
private void dispose(bool disposing)
{
if (!disposing || session == null || session.IsInvalid)
{
......@@ -210,7 +210,7 @@ namespace Titanium.Web.Proxy.Helpers.WinHttp
session.Close();
}
private int GetAutoProxies(Uri destination, Uri scriptLocation, out string proxyListString)
private int getAutoProxies(Uri destination, Uri scriptLocation, out string proxyListString)
{
int num = 0;
var autoProxyOptions = new NativeMethods.WinHttp.WINHTTP_AUTOPROXY_OPTIONS();
......@@ -229,16 +229,16 @@ namespace Titanium.Web.Proxy.Helpers.WinHttp
autoProxyOptions.AutoDetectFlags = NativeMethods.WinHttp.AutoDetectType.None;
}
if (!WinHttpGetProxyForUrl(destination.ToString(), ref autoProxyOptions, out proxyListString))
if (!winHttpGetProxyForUrl(destination.ToString(), ref autoProxyOptions, out proxyListString))
{
num = GetLastWin32Error();
num = getLastWin32Error();
if (num == (int)NativeMethods.WinHttp.ErrorCodes.LoginFailure && Credentials != null)
{
autoProxyOptions.AutoLogonIfChallenged = true;
if (!WinHttpGetProxyForUrl(destination.ToString(), ref autoProxyOptions, out proxyListString))
if (!winHttpGetProxyForUrl(destination.ToString(), ref autoProxyOptions, out proxyListString))
{
num = GetLastWin32Error();
num = getLastWin32Error();
}
}
}
......@@ -246,7 +246,7 @@ namespace Titanium.Web.Proxy.Helpers.WinHttp
return num;
}
private bool WinHttpGetProxyForUrl(string destination,
private bool winHttpGetProxyForUrl(string destination,
ref NativeMethods.WinHttp.WINHTTP_AUTOPROXY_OPTIONS autoProxyOptions, out string proxyListString)
{
proxyListString = null;
......@@ -271,7 +271,7 @@ namespace Titanium.Web.Proxy.Helpers.WinHttp
return flag;
}
private static int GetLastWin32Error()
private static int getLastWin32Error()
{
int lastWin32Error = Marshal.GetLastWin32Error();
if (lastWin32Error == 8)
......@@ -282,7 +282,7 @@ namespace Titanium.Web.Proxy.Helpers.WinHttp
return lastWin32Error;
}
private static bool IsRecoverableAutoProxyError(NativeMethods.WinHttp.ErrorCodes errorCode)
private static bool isRecoverableAutoProxyError(NativeMethods.WinHttp.ErrorCodes errorCode)
{
switch (errorCode)
{
......@@ -300,7 +300,7 @@ namespace Titanium.Web.Proxy.Helpers.WinHttp
}
}
private static AutoWebProxyState GetStateFromErrorCode(NativeMethods.WinHttp.ErrorCodes errorCode)
private static AutoWebProxyState getStateFromErrorCode(NativeMethods.WinHttp.ErrorCodes errorCode)
{
if (errorCode == 0L)
{
......@@ -324,7 +324,7 @@ namespace Titanium.Web.Proxy.Helpers.WinHttp
}
}
private static string RemoveWhitespaces(string value)
private static string removeWhitespaces(string value)
{
var stringBuilder = new StringBuilder();
foreach (char c in value)
......@@ -338,7 +338,7 @@ namespace Titanium.Web.Proxy.Helpers.WinHttp
return stringBuilder.ToString();
}
private static bool IsErrorFatalForAutoDetect(NativeMethods.WinHttp.ErrorCodes errorCode)
private static bool isErrorFatalForAutoDetect(NativeMethods.WinHttp.ErrorCodes errorCode)
{
switch (errorCode)
{
......
......@@ -24,7 +24,7 @@ namespace Titanium.Web.Proxy.Http
/// </summary>
/// <param name="buffer"></param>
/// <param name="size"></param>
private static void ResizeBuffer(ref byte[] buffer, long size)
private static void resizeBuffer(ref byte[] buffer, long size)
{
var newBuffer = new byte[size];
Buffer.BlockCopy(buffer, 0, newBuffer, 0, buffer.Length);
......
......@@ -4,6 +4,7 @@ using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Titanium.Web.Proxy.Exceptions;
using Titanium.Web.Proxy.Extensions;
using Titanium.Web.Proxy.Models;
using Titanium.Web.Proxy.Network.Tcp;
......@@ -160,7 +161,7 @@ namespace Titanium.Web.Proxy.Http
string httpStatus = await ServerConnection.Stream.ReadLineAsync(cancellationToken);
if (httpStatus == null)
{
throw new IOException();
throw new ServerConnectionException("Server connection was closed.");
}
if (httpStatus == string.Empty)
......
......@@ -199,7 +199,7 @@ namespace Titanium.Web.Proxy.Http
// Find the request Verb
httpMethod = httpCmdSplit[0];
if (!IsAllUpper(httpMethod))
if (!isAllUpper(httpMethod))
{
httpMethod = httpMethod.ToUpper();
}
......@@ -219,7 +219,7 @@ namespace Titanium.Web.Proxy.Http
}
}
private static bool IsAllUpper(string input)
private static bool isAllUpper(string input)
{
for (int i = 0; i < input.Length; i++)
{
......
......@@ -49,7 +49,7 @@ namespace Titanium.Web.Proxy.Network.Certificate
/// <returns>X509Certificate2 instance.</returns>
public X509Certificate2 MakeCertificate(string sSubjectCn, bool isRoot, X509Certificate2 signingCert = null)
{
return MakeCertificateInternal(sSubjectCn, isRoot, true, signingCert);
return makeCertificateInternal(sSubjectCn, isRoot, true, signingCert);
}
/// <summary>
......@@ -65,7 +65,7 @@ namespace Titanium.Web.Proxy.Network.Certificate
/// <param name="hostName">The host name</param>
/// <returns>X509Certificate2 instance.</returns>
/// <exception cref="PemException">Malformed sequence in RSA private key</exception>
private static X509Certificate2 GenerateCertificate(string hostName,
private static X509Certificate2 generateCertificate(string hostName,
string subjectName,
string issuerName, DateTime validFrom,
DateTime validTo, int keyStrength = 2048,
......@@ -145,7 +145,7 @@ namespace Titanium.Web.Proxy.Network.Certificate
var x509Certificate = new X509Certificate2(certificate.GetEncoded());
x509Certificate.PrivateKey = DotNetUtilities.ToRSA(rsaparams);
#else
var x509Certificate = WithPrivateKey(certificate, rsaparams);
var x509Certificate = withPrivateKey(certificate, rsaparams);
x509Certificate.FriendlyName = subjectName;
#endif
......@@ -164,7 +164,7 @@ namespace Titanium.Web.Proxy.Network.Certificate
return x509Certificate;
}
private static X509Certificate2 WithPrivateKey(X509Certificate certificate, AsymmetricKeyParameter privateKey)
private static X509Certificate2 withPrivateKey(X509Certificate certificate, AsymmetricKeyParameter privateKey)
{
const string password = "password";
var store = new Pkcs12Store();
......@@ -194,7 +194,7 @@ namespace Titanium.Web.Proxy.Network.Certificate
/// You must specify a Signing Certificate if and only if you are not creating a
/// root.
/// </exception>
private X509Certificate2 MakeCertificateInternal(bool isRoot,
private X509Certificate2 makeCertificateInternal(bool isRoot,
string hostName, string subjectName,
DateTime validFrom, DateTime validTo, X509Certificate2 signingCertificate)
{
......@@ -207,11 +207,11 @@ namespace Titanium.Web.Proxy.Network.Certificate
if (isRoot)
{
return GenerateCertificate(null, subjectName, subjectName, validFrom, validTo);
return generateCertificate(null, subjectName, subjectName, validFrom, validTo);
}
var kp = DotNetUtilities.GetKeyPair(signingCertificate.PrivateKey);
return GenerateCertificate(hostName, subjectName, signingCertificate.Subject, validFrom, validTo,
return generateCertificate(hostName, subjectName, signingCertificate.Subject, validFrom, validTo,
issuerPrivateKey: kp.Private);
}
......@@ -224,7 +224,7 @@ namespace Titanium.Web.Proxy.Network.Certificate
/// <param name="signingCert">The signing cert.</param>
/// <param name="cancellationToken">Task cancellation token</param>
/// <returns>X509Certificate2.</returns>
private X509Certificate2 MakeCertificateInternal(string subject, bool isRoot,
private X509Certificate2 makeCertificateInternal(string subject, bool isRoot,
bool switchToMtaIfNeeded, X509Certificate2 signingCert = null,
CancellationToken cancellationToken = default)
{
......@@ -238,7 +238,7 @@ namespace Titanium.Web.Proxy.Network.Certificate
{
try
{
certificate = MakeCertificateInternal(subject, isRoot, false, signingCert);
certificate = makeCertificateInternal(subject, isRoot, false, signingCert);
}
catch (Exception ex)
{
......@@ -258,7 +258,7 @@ namespace Titanium.Web.Proxy.Network.Certificate
}
#endif
return MakeCertificateInternal(isRoot, subject, $"CN={subject}",
return makeCertificateInternal(isRoot, subject, $"CN={subject}",
DateTime.UtcNow.AddDays(-certificateGraceDays), DateTime.UtcNow.AddDays(certificateValidDays),
isRoot ? null : signingCert);
}
......
......@@ -80,10 +80,10 @@ namespace Titanium.Web.Proxy.Network.Certificate
/// <returns></returns>
public X509Certificate2 MakeCertificate(string sSubjectCN, bool isRoot, X509Certificate2 signingCert = null)
{
return MakeCertificateInternal(sSubjectCN, isRoot, true, signingCert);
return makeCertificateInternal(sSubjectCN, isRoot, true, signingCert);
}
private X509Certificate2 MakeCertificate(bool isRoot, string subject, string fullSubject,
private X509Certificate2 makeCertificate(bool isRoot, string subject, string fullSubject,
int privateKeyLength, string hashAlg, DateTime validFrom, DateTime validTo,
X509Certificate2 signingCertificate)
{
......@@ -274,13 +274,13 @@ namespace Titanium.Web.Proxy.Network.Certificate
return new X509Certificate2(Convert.FromBase64String(empty), string.Empty, X509KeyStorageFlags.Exportable);
}
private X509Certificate2 MakeCertificateInternal(string sSubjectCN, bool isRoot,
private X509Certificate2 makeCertificateInternal(string sSubjectCN, bool isRoot,
bool switchToMTAIfNeeded, X509Certificate2 signingCert = null,
CancellationToken cancellationToken = default)
{
if (switchToMTAIfNeeded && Thread.CurrentThread.GetApartmentState() != ApartmentState.MTA)
{
return Task.Run(() => MakeCertificateInternal(sSubjectCN, isRoot, false, signingCert),
return Task.Run(() => makeCertificateInternal(sSubjectCN, isRoot, false, signingCert),
cancellationToken).Result;
}
......@@ -301,7 +301,7 @@ namespace Titanium.Web.Proxy.Network.Certificate
var graceTime = DateTime.Now.AddDays(graceDays);
var now = DateTime.Now;
var certificate = MakeCertificate(isRoot, sSubjectCN, fullSubject, keyLength, hashAlgo, graceTime,
var certificate = makeCertificate(isRoot, sSubjectCN, fullSubject, keyLength, hashAlgo, graceTime,
now.AddDays(validDays), isRoot ? null : signingCert);
return certificate;
}
......
......@@ -239,7 +239,7 @@ namespace Titanium.Web.Proxy.Network
{
}
private string GetRootCertificateDirectory()
private string getRootCertificateDirectory()
{
string assemblyLocation = Assembly.GetExecutingAssembly().Location;
......@@ -258,9 +258,9 @@ namespace Titanium.Web.Proxy.Network
return path;
}
private string GetCertificatePath()
private string getCertificatePath()
{
string path = GetRootCertificateDirectory();
string path = getRootCertificateDirectory();
string certPath = Path.Combine(path, "crts");
if (!Directory.Exists(certPath))
......@@ -271,9 +271,9 @@ namespace Titanium.Web.Proxy.Network
return certPath;
}
private string GetRootCertificatePath()
private string getRootCertificatePath()
{
string path = GetRootCertificateDirectory();
string path = getRootCertificateDirectory();
string fileName = PfxFilePath;
if (fileName == string.Empty)
......@@ -290,15 +290,15 @@ namespace Titanium.Web.Proxy.Network
/// </summary>
/// <param name="storeLocation"></param>
/// <returns></returns>
private bool RootCertificateInstalled(StoreLocation storeLocation)
private bool rootCertificateInstalled(StoreLocation storeLocation)
{
string value = $"{RootCertificate.Issuer}";
return FindCertificates(StoreName.Root, storeLocation, value).Count > 0
return findCertificates(StoreName.Root, storeLocation, value).Count > 0
&& (CertificateEngine != CertificateEngine.DefaultWindows
|| FindCertificates(StoreName.My, storeLocation, value).Count > 0);
|| findCertificates(StoreName.My, storeLocation, value).Count > 0);
}
private X509Certificate2Collection FindCertificates(StoreName storeName, StoreLocation storeLocation,
private static X509Certificate2Collection findCertificates(StoreName storeName, StoreLocation storeLocation,
string findValue)
{
var x509Store = new X509Store(storeName, storeLocation);
......@@ -318,7 +318,7 @@ namespace Titanium.Web.Proxy.Network
/// </summary>
/// <param name="storeName"></param>
/// <param name="storeLocation"></param>
private void InstallCertificate(StoreName storeName, StoreLocation storeLocation)
private void installCertificate(StoreName storeName, StoreLocation storeLocation)
{
if (RootCertificate == null)
{
......@@ -354,7 +354,7 @@ namespace Titanium.Web.Proxy.Network
/// <param name="storeName"></param>
/// <param name="storeLocation"></param>
/// <param name="certificate"></param>
private void UninstallCertificate(StoreName storeName, StoreLocation storeLocation,
private void uninstallCertificate(StoreName storeName, StoreLocation storeLocation,
X509Certificate2 certificate)
{
if (certificate == null)
......@@ -383,7 +383,7 @@ namespace Titanium.Web.Proxy.Network
}
}
private X509Certificate2 MakeCertificate(string certificateName, bool isRootCertificate)
private X509Certificate2 makeCertificate(string certificateName, bool isRootCertificate)
{
if (!isRootCertificate && RootCertificate == null)
{
......@@ -394,7 +394,7 @@ namespace Titanium.Web.Proxy.Network
if (CertificateEngine == CertificateEngine.DefaultWindows)
{
Task.Run(() => UninstallCertificate(StoreName.My, StoreLocation.CurrentUser, certificate));
Task.Run(() => uninstallCertificate(StoreName.My, StoreLocation.CurrentUser, certificate));
}
return certificate;
......@@ -413,14 +413,14 @@ namespace Titanium.Web.Proxy.Network
{
if (!isRootCertificate && SaveFakeCertificates)
{
string path = GetCertificatePath();
string path = getCertificatePath();
string subjectName = ProxyConstants.CNRemoverRegex.Replace(certificateName, string.Empty);
subjectName = subjectName.Replace("*", "$x$");
string certificatePath = Path.Combine(path, subjectName + ".pfx");
if (!File.Exists(certificatePath))
{
certificate = MakeCertificate(certificateName, false);
certificate = makeCertificate(certificateName, false);
// store as cache
Task.Run(() =>
......@@ -444,13 +444,13 @@ namespace Titanium.Web.Proxy.Network
catch
{
// if load failed create again
certificate = MakeCertificate(certificateName, false);
certificate = makeCertificate(certificateName, false);
}
}
}
else
{
certificate = MakeCertificate(certificateName, isRootCertificate);
certificate = makeCertificate(certificateName, isRootCertificate);
}
}
catch (Exception e)
......@@ -574,14 +574,14 @@ namespace Titanium.Web.Proxy.Network
{
try
{
Directory.Delete(GetCertificatePath(), true);
Directory.Delete(getCertificatePath(), true);
}
catch
{
// ignore
}
string fileName = GetRootCertificatePath();
string fileName = getRootCertificatePath();
File.WriteAllBytes(fileName, RootCertificate.Export(X509ContentType.Pkcs12, PfxPassword));
}
catch (Exception e)
......@@ -599,7 +599,7 @@ namespace Titanium.Web.Proxy.Network
/// <returns></returns>
public X509Certificate2 LoadRootCertificate()
{
string fileName = GetRootCertificatePath();
string fileName = getRootCertificatePath();
pfxFileExists = File.Exists(fileName);
if (!pfxFileExists)
{
......@@ -653,20 +653,20 @@ namespace Titanium.Web.Proxy.Network
public void TrustRootCertificate(bool machineTrusted = false)
{
// currentUser\personal
InstallCertificate(StoreName.My, StoreLocation.CurrentUser);
installCertificate(StoreName.My, StoreLocation.CurrentUser);
if (!machineTrusted)
{
// currentUser\Root
InstallCertificate(StoreName.Root, StoreLocation.CurrentUser);
installCertificate(StoreName.Root, StoreLocation.CurrentUser);
}
else
{
// current system
InstallCertificate(StoreName.My, StoreLocation.LocalMachine);
installCertificate(StoreName.My, StoreLocation.LocalMachine);
// this adds to both currentUser\Root & currentMachine\Root
InstallCertificate(StoreName.Root, StoreLocation.LocalMachine);
installCertificate(StoreName.Root, StoreLocation.LocalMachine);
}
}
......@@ -683,7 +683,7 @@ namespace Titanium.Web.Proxy.Network
}
// currentUser\Personal
InstallCertificate(StoreName.My, StoreLocation.CurrentUser);
installCertificate(StoreName.My, StoreLocation.CurrentUser);
string pfxFileName = Path.GetTempFileName();
File.WriteAllBytes(pfxFileName, RootCertificate.Export(X509ContentType.Pkcs12, PfxPassword));
......@@ -778,7 +778,7 @@ namespace Titanium.Web.Proxy.Network
/// </summary>
public bool IsRootCertificateUserTrusted()
{
return RootCertificateInstalled(StoreLocation.CurrentUser) || IsRootCertificateMachineTrusted();
return rootCertificateInstalled(StoreLocation.CurrentUser) || IsRootCertificateMachineTrusted();
}
/// <summary>
......@@ -786,7 +786,7 @@ namespace Titanium.Web.Proxy.Network
/// </summary>
public bool IsRootCertificateMachineTrusted()
{
return RootCertificateInstalled(StoreLocation.LocalMachine);
return rootCertificateInstalled(StoreLocation.LocalMachine);
}
/// <summary>
......@@ -797,20 +797,20 @@ namespace Titanium.Web.Proxy.Network
public void RemoveTrustedRootCertificate(bool machineTrusted = false)
{
// currentUser\personal
UninstallCertificate(StoreName.My, StoreLocation.CurrentUser, RootCertificate);
uninstallCertificate(StoreName.My, StoreLocation.CurrentUser, RootCertificate);
if (!machineTrusted)
{
// currentUser\Root
UninstallCertificate(StoreName.Root, StoreLocation.CurrentUser, RootCertificate);
uninstallCertificate(StoreName.Root, StoreLocation.CurrentUser, RootCertificate);
}
else
{
// current system
UninstallCertificate(StoreName.My, StoreLocation.LocalMachine, RootCertificate);
uninstallCertificate(StoreName.My, StoreLocation.LocalMachine, RootCertificate);
// this adds to both currentUser\Root & currentMachine\Root
UninstallCertificate(StoreName.Root, StoreLocation.LocalMachine, RootCertificate);
uninstallCertificate(StoreName.Root, StoreLocation.LocalMachine, RootCertificate);
}
}
......@@ -826,7 +826,7 @@ namespace Titanium.Web.Proxy.Network
}
// currentUser\Personal
UninstallCertificate(StoreName.My, StoreLocation.CurrentUser, RootCertificate);
uninstallCertificate(StoreName.My, StoreLocation.CurrentUser, RootCertificate);
var infos = new List<ProcessStartInfo>();
if (!machineTrusted)
......
using System;
using System.IO;
using System.Net;
using System.Net.Security;
using System.Net.Sockets;
using Titanium.Web.Proxy.Extensions;
......
......@@ -40,7 +40,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
internal TcpConnectionFactory(ProxyServer server)
{
this.server = server;
Task.Run(async () => await ClearOutdatedConnections());
Task.Run(async () => await clearOutdatedConnections());
}
/// <summary>
......@@ -88,7 +88,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
var cutOff = DateTime.Now.AddSeconds(-1 * proxyServer.ConnectionTimeOutSeconds + 3);
if (recentConnection.LastAccess > cutOff
&& IsGoodConnection(recentConnection.TcpClient))
&& isGoodConnection(recentConnection.TcpClient))
{
return recentConnection;
}
......@@ -99,7 +99,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
}
}
var connection = await CreateClient(remoteHostName, remotePort, httpVersion, isHttps,
var connection = await createClient(remoteHostName, remotePort, httpVersion, isHttps,
applicationProtocols, isConnect, proxyServer, upStreamEndPoint, externalProxy, cancellationToken);
connection.CacheKey = cacheKey;
......@@ -121,7 +121,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
/// <param name="externalProxy">The external proxy to make request via.</param>
/// <param name="cancellationToken">The cancellation token for this async task.</param>
/// <returns></returns>
private async Task<TcpServerConnection> CreateClient(string remoteHostName, int remotePort,
private async Task<TcpServerConnection> createClient(string remoteHostName, int remotePort,
Version httpVersion, bool isHttps, List<SslApplicationProtocol> applicationProtocols, bool isConnect,
ProxyServer proxyServer, IPEndPoint upStreamEndPoint, ExternalProxy externalProxy,
CancellationToken cancellationToken)
......@@ -280,7 +280,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
@lock.Release();
}
private async Task ClearOutdatedConnections()
private async Task clearOutdatedConnections()
{
while (runCleanUpTask)
{
......@@ -326,7 +326,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
/// </summary>
/// <param name="client"></param>
/// <returns></returns>
private static bool IsGoodConnection(TcpClient client)
private static bool isGoodConnection(TcpClient client)
{
var socket = client.Client;
......
......@@ -18,7 +18,7 @@ namespace Titanium.Web.Proxy
/// </summary>
/// <param name="session">The session event arguments.</param>
/// <returns>True if authorized.</returns>
private async Task<bool> CheckAuthorization(SessionEventArgsBase session)
private async Task<bool> checkAuthorization(SessionEventArgsBase session)
{
// If we are not authorizing clients return true
if (AuthenticateUserFunc == null)
......@@ -33,7 +33,7 @@ namespace Titanium.Web.Proxy
var header = httpHeaders.GetFirstHeader(KnownHeaders.ProxyAuthorization);
if (header == null)
{
session.WebSession.Response = CreateAuthentication407Response("Proxy Authentication Required");
session.WebSession.Response = createAuthentication407Response("Proxy Authentication Required");
return false;
}
......@@ -42,7 +42,7 @@ namespace Titanium.Web.Proxy
!headerValueParts[0].EqualsIgnoreCase(KnownHeaders.ProxyAuthorizationBasic))
{
// Return not authorized
session.WebSession.Response = CreateAuthentication407Response("Proxy Authentication Invalid");
session.WebSession.Response = createAuthentication407Response("Proxy Authentication Invalid");
return false;
}
......@@ -51,7 +51,7 @@ namespace Titanium.Web.Proxy
if (colonIndex == -1)
{
// Return not authorized
session.WebSession.Response = CreateAuthentication407Response("Proxy Authentication Invalid");
session.WebSession.Response = createAuthentication407Response("Proxy Authentication Invalid");
return false;
}
......@@ -60,7 +60,7 @@ namespace Titanium.Web.Proxy
bool authenticated = await AuthenticateUserFunc(username, password);
if (!authenticated)
{
session.WebSession.Response = CreateAuthentication407Response("Proxy Authentication Invalid");
session.WebSession.Response = createAuthentication407Response("Proxy Authentication Invalid");
}
return authenticated;
......@@ -71,7 +71,7 @@ namespace Titanium.Web.Proxy
httpHeaders));
// Return not authorized
session.WebSession.Response = CreateAuthentication407Response("Proxy Authentication Invalid");
session.WebSession.Response = createAuthentication407Response("Proxy Authentication Invalid");
return false;
}
}
......@@ -81,7 +81,7 @@ namespace Titanium.Web.Proxy
/// </summary>
/// <param name="description">Response description.</param>
/// <returns></returns>
private Response CreateAuthentication407Response(string description)
private Response createAuthentication407Response(string description)
{
var response = new Response
{
......
......@@ -314,7 +314,7 @@ namespace Titanium.Web.Proxy
if (ProxyRunning)
{
Listen(endPoint);
listen(endPoint);
}
}
......@@ -334,7 +334,7 @@ namespace Titanium.Web.Proxy
if (ProxyRunning)
{
QuitListen(endPoint);
quitListen(endPoint);
}
}
......@@ -368,7 +368,7 @@ namespace Titanium.Web.Proxy
throw new Exception("Mono Runtime do not support system proxy settings.");
}
ValidateEndPointAsSystemProxy(endPoint);
validateEndPointAsSystemProxy(endPoint);
bool isHttp = (protocolType & ProxyProtocolType.Http) > 0;
bool isHttps = (protocolType & ProxyProtocolType.Https) > 0;
......@@ -523,7 +523,7 @@ namespace Titanium.Web.Proxy
systemProxyResolver = new WinHttpWebProxyFinder();
systemProxyResolver.LoadFromIE();
GetCustomUpStreamProxyFunc = GetSystemUpStreamProxy;
GetCustomUpStreamProxyFunc = getSystemUpStreamProxy;
}
ProxyRunning = true;
......@@ -532,7 +532,7 @@ namespace Titanium.Web.Proxy
foreach (var endPoint in ProxyEndPoints)
{
Listen(endPoint);
listen(endPoint);
}
}
......@@ -559,7 +559,7 @@ namespace Titanium.Web.Proxy
foreach (var endPoint in ProxyEndPoints)
{
QuitListen(endPoint);
quitListen(endPoint);
}
ProxyEndPoints.Clear();
......@@ -574,7 +574,7 @@ namespace Titanium.Web.Proxy
/// Listen on given end point of local machine.
/// </summary>
/// <param name="endPoint">The end point to listen.</param>
private void Listen(ProxyEndPoint endPoint)
private void listen(ProxyEndPoint endPoint)
{
endPoint.Listener = new TcpListener(endPoint.IpAddress, endPoint.Port);
try
......@@ -584,7 +584,7 @@ namespace Titanium.Web.Proxy
endPoint.Port = ((IPEndPoint)endPoint.Listener.LocalEndpoint).Port;
// accept clients asynchronously
endPoint.Listener.BeginAcceptTcpClient(OnAcceptConnection, endPoint);
endPoint.Listener.BeginAcceptTcpClient(onAcceptConnection, endPoint);
}
catch (SocketException ex)
{
......@@ -600,7 +600,7 @@ namespace Titanium.Web.Proxy
/// Verify if its safe to set this end point as system proxy.
/// </summary>
/// <param name="endPoint">The end point to validate.</param>
private void ValidateEndPointAsSystemProxy(ExplicitProxyEndPoint endPoint)
private void validateEndPointAsSystemProxy(ExplicitProxyEndPoint endPoint)
{
if (endPoint == null)
{
......@@ -623,7 +623,7 @@ namespace Titanium.Web.Proxy
/// </summary>
/// <param name="sessionEventArgs">The session.</param>
/// <returns>The external proxy as task result.</returns>
private Task<ExternalProxy> GetSystemUpStreamProxy(SessionEventArgsBase sessionEventArgs)
private Task<ExternalProxy> getSystemUpStreamProxy(SessionEventArgsBase sessionEventArgs)
{
var proxy = systemProxyResolver.GetProxy(sessionEventArgs.WebSession.Request.RequestUri);
return Task.FromResult(proxy);
......@@ -632,7 +632,7 @@ namespace Titanium.Web.Proxy
/// <summary>
/// Act when a connection is received from client.
/// </summary>
private void OnAcceptConnection(IAsyncResult asyn)
private void onAcceptConnection(IAsyncResult asyn)
{
var endPoint = (ProxyEndPoint)asyn.AsyncState;
......@@ -657,11 +657,11 @@ namespace Titanium.Web.Proxy
if (tcpClient != null)
{
Task.Run(async () => { await HandleClient(tcpClient, endPoint); });
Task.Run(async () => { await handleClient(tcpClient, endPoint); });
}
// Get the listener that handles the client request.
endPoint.Listener.BeginAcceptTcpClient(OnAcceptConnection, endPoint);
endPoint.Listener.BeginAcceptTcpClient(onAcceptConnection, endPoint);
}
/// <summary>
......@@ -670,7 +670,7 @@ namespace Titanium.Web.Proxy
/// <param name="tcpClient">The client.</param>
/// <param name="endPoint">The proxy endpoint.</param>
/// <returns>The task.</returns>
private async Task HandleClient(TcpClient tcpClient, ProxyEndPoint endPoint)
private async Task handleClient(TcpClient tcpClient, ProxyEndPoint endPoint)
{
tcpClient.ReceiveTimeout = ConnectionTimeOutSeconds * 1000;
tcpClient.SendTimeout = ConnectionTimeOutSeconds * 1000;
......@@ -683,11 +683,11 @@ namespace Titanium.Web.Proxy
{
if (endPoint is TransparentProxyEndPoint tep)
{
await HandleClient(tep, clientConnection);
await handleClient(tep, clientConnection);
}
else
{
await HandleClient((ExplicitProxyEndPoint)endPoint, clientConnection);
await handleClient((ExplicitProxyEndPoint)endPoint, clientConnection);
}
}
}
......@@ -697,7 +697,7 @@ namespace Titanium.Web.Proxy
/// </summary>
/// <param name="clientStream">The client stream.</param>
/// <param name="exception">The exception.</param>
private void OnException(CustomBufferedStream clientStream, Exception exception)
private void onException(CustomBufferedStream clientStream, Exception exception)
{
#if DEBUG
if (clientStream is DebugCustomBufferedStream debugStream)
......@@ -712,7 +712,7 @@ namespace Titanium.Web.Proxy
/// <summary>
/// Quit listening on the given end point.
/// </summary>
private void QuitListen(ProxyEndPoint endPoint)
private void quitListen(ProxyEndPoint endPoint)
{
endPoint.Listener.Stop();
endPoint.Listener.Server.Dispose();
......
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
......@@ -49,7 +50,7 @@ namespace Titanium.Web.Proxy
/// explicit endpoint.
/// </param>
/// <param name="connectRequest">The Connect request if this is a HTTPS request from explicit endpoint.</param>
private async Task HandleHttpSessionRequest(ProxyEndPoint endPoint, TcpClientConnection clientConnection,
private async Task handleHttpSessionRequest(ProxyEndPoint endPoint, TcpClientConnection clientConnection,
CustomBufferedStream clientStream, HttpResponseWriter clientStreamWriter,
CancellationTokenSource cancellationTokenSource, string httpsConnectHostname, ConnectRequest connectRequest)
{
......@@ -133,9 +134,9 @@ namespace Titanium.Web.Proxy
if (!args.IsTransparent)
{
// proxy authorization check
if (httpsConnectHostname == null && await CheckAuthorization(args) == false)
if (httpsConnectHostname == null && await checkAuthorization(args) == false)
{
await InvokeBeforeResponse(args);
await invokeBeforeResponse(args);
// send the response
await clientStreamWriter.WriteResponseAsync(args.WebSession.Response,
......@@ -143,7 +144,7 @@ namespace Titanium.Web.Proxy
return;
}
PrepareRequestHeaders(request.Headers);
prepareRequestHeaders(request.Headers);
request.Host = request.RequestUri.Authority;
}
......@@ -158,7 +159,7 @@ namespace Titanium.Web.Proxy
request.OriginalHasBody = request.HasBody;
// If user requested interception do it
await InvokeBeforeRequest(args);
await invokeBeforeRequest(args);
var response = args.WebSession.Response;
......@@ -167,7 +168,7 @@ namespace Titanium.Web.Proxy
// syphon out the request body from client before setting the new body
await args.SyphonOutBodyAsync(true, cancellationToken);
await HandleHttpSessionResponse(args);
await handleHttpSessionResponse(args);
if (!response.KeepAlive)
{
......@@ -187,52 +188,48 @@ namespace Titanium.Web.Proxy
serverConnection = null;
}
var connectionChanged = false;
if (serverConnection == null)
{
serverConnection = await GetServerConnection(args, false, clientConnection.NegotiatedApplicationProtocol, cancellationToken);
serverConnection = await getServerConnection(args, false, clientConnection.NegotiatedApplicationProtocol, cancellationToken);
connectionChanged = true;
}
var attemt = 0;
//for connection pool retry
while (attemt < 3)
{
try
{
// if upgrading to websocket then relay the requet without reading the contents
if (request.UpgradeToWebSocket)
{
// prepare the prefix content
await serverConnection.StreamWriter.WriteLineAsync(httpCmd, cancellationToken);
await serverConnection.StreamWriter.WriteHeadersAsync(request.Headers,
cancellationToken: cancellationToken);
string httpStatus = await serverConnection.Stream.ReadLineAsync(cancellationToken);
Response.ParseResponseLine(httpStatus, out var responseVersion,
out int responseStatusCode,
out string responseStatusDescription);
response.HttpVersion = responseVersion;
response.StatusCode = responseStatusCode;
response.StatusDescription = responseStatusDescription;
await HeaderParser.ReadHeaders(serverConnection.Stream, response.Headers,
cancellationToken);
if (!args.IsTransparent)
{
await clientStreamWriter.WriteResponseAsync(response,
cancellationToken: cancellationToken);
await handleWebSocketUpgrade(httpCmd, args, request,
response, clientStream, clientStreamWriter,
serverConnection, cancellationTokenSource, cancellationToken);
return;
}
// If user requested call back then do it
if (!args.WebSession.Response.Locked)
// construct the web request that we are going to issue on behalf of the client.
await handleHttpSessionRequestInternal(serverConnection, args);
}
//connection pool retry
catch (ServerConnectionException)
{
if (!connectionChanged || !EnableConnectionPool || attemt == 3)
{
await InvokeBeforeResponse(args);
throw;
}
await TcpHelper.SendRaw(clientStream, serverConnection.Stream, BufferSize,
(buffer, offset, count) => { args.OnDataSent(buffer, offset, count); },
(buffer, offset, count) => { args.OnDataReceived(buffer, offset, count); },
cancellationTokenSource, ExceptionFunc);
return;
//get new connection from pool
tcpConnectionFactory.Release(serverConnection, true);
serverConnection = await getServerConnection(args, false, clientConnection.NegotiatedApplicationProtocol, cancellationToken);
attemt++;
continue;
}
// construct the web request that we are going to issue on behalf of the client.
await HandleHttpSessionRequestInternal(serverConnection, args);
break;
}
if (args.WebSession.ServerConnection == null)
{
......@@ -264,7 +261,7 @@ namespace Titanium.Web.Proxy
}
finally
{
await InvokeAfterResponse(args);
await invokeAfterResponse(args);
args.Dispose();
}
}
......@@ -281,9 +278,7 @@ namespace Titanium.Web.Proxy
/// <param name="serverConnection">The tcp connection.</param>
/// <param name="args">The session event arguments.</param>
/// <returns></returns>
private async Task HandleHttpSessionRequestInternal(TcpServerConnection serverConnection, SessionEventArgs args)
{
try
private async Task handleHttpSessionRequestInternal(TcpServerConnection serverConnection, SessionEventArgs args)
{
var cancellationToken = args.CancellationTokenSource.Token;
var request = args.WebSession.Request;
......@@ -351,13 +346,9 @@ namespace Titanium.Web.Proxy
// If not expectation failed response was returned by server then parse response
if (!request.ExpectationFailed)
{
await HandleHttpSessionResponse(args);
}
}
catch (Exception e) when (!(e is ProxyHttpException))
{
throw new ProxyHttpException("Error occured whilst handling session request (internal)", e, args);
await handleHttpSessionResponse(args);
}
}
/// <summary>
......@@ -368,7 +359,7 @@ namespace Titanium.Web.Proxy
/// <param name="applicationProtocol"></param>
/// <param name="cancellationToken">The cancellation token for this async task.</param>
/// <returns></returns>
private Task<TcpServerConnection> GetServerConnection(SessionEventArgsBase args, bool isConnect,
private Task<TcpServerConnection> getServerConnection(SessionEventArgsBase args, bool isConnect,
SslApplicationProtocol applicationProtocol, CancellationToken cancellationToken)
{
List<SslApplicationProtocol> applicationProtocols = null;
......@@ -377,7 +368,7 @@ namespace Titanium.Web.Proxy
applicationProtocols = new List<SslApplicationProtocol> { applicationProtocol };
}
return GetServerConnection(args, isConnect, applicationProtocols, cancellationToken);
return getServerConnection(args, isConnect, applicationProtocols, cancellationToken);
}
/// <summary>
......@@ -388,7 +379,7 @@ namespace Titanium.Web.Proxy
/// <param name="applicationProtocols"></param>
/// <param name="cancellationToken">The cancellation token for this async task.</param>
/// <returns></returns>
private async Task<TcpServerConnection> GetServerConnection(SessionEventArgsBase args, bool isConnect,
private async Task<TcpServerConnection> getServerConnection(SessionEventArgsBase args, bool isConnect,
List<SslApplicationProtocol> applicationProtocols, CancellationToken cancellationToken)
{
ExternalProxy customUpStreamProxy = null;
......@@ -414,7 +405,7 @@ namespace Titanium.Web.Proxy
/// <summary>
/// Prepare the request headers so that we can avoid encodings not parsable by this proxy
/// </summary>
private void PrepareRequestHeaders(HeaderCollection requestHeaders)
private void prepareRequestHeaders(HeaderCollection requestHeaders)
{
var acceptEncoding = requestHeaders.GetHeaderValueOrNull(KnownHeaders.AcceptEncoding);
......@@ -436,12 +427,69 @@ namespace Titanium.Web.Proxy
requestHeaders.FixProxyHeaders();
}
/// <summary>
/// Handle upgrade to websocket
/// </summary>
private async Task handleWebSocketUpgrade(string httpCmd,
SessionEventArgs args, Request request, Response response,
CustomBufferedStream clientStream, HttpResponseWriter clientStreamWriter,
TcpServerConnection serverConnection,
CancellationTokenSource cancellationTokenSource, CancellationToken cancellationToken)
{
// prepare the prefix content
await serverConnection.StreamWriter.WriteLineAsync(httpCmd, cancellationToken);
await serverConnection.StreamWriter.WriteHeadersAsync(request.Headers,
cancellationToken: cancellationToken);
string httpStatus;
try
{
httpStatus = await serverConnection.Stream.ReadLineAsync(cancellationToken);
if (httpStatus == null)
{
throw new ServerConnectionException("Server connection was closed.");
}
}
catch (Exception e) when (!(e is ServerConnectionException))
{
throw new ServerConnectionException("Server connection was closed.", e);
}
Response.ParseResponseLine(httpStatus, out var responseVersion,
out int responseStatusCode,
out string responseStatusDescription);
response.HttpVersion = responseVersion;
response.StatusCode = responseStatusCode;
response.StatusDescription = responseStatusDescription;
await HeaderParser.ReadHeaders(serverConnection.Stream, response.Headers,
cancellationToken);
if (!args.IsTransparent)
{
await clientStreamWriter.WriteResponseAsync(response,
cancellationToken: cancellationToken);
}
// If user requested call back then do it
if (!args.WebSession.Response.Locked)
{
await invokeBeforeResponse(args);
}
await TcpHelper.SendRaw(clientStream, serverConnection.Stream, BufferSize,
(buffer, offset, count) => { args.OnDataSent(buffer, offset, count); },
(buffer, offset, count) => { args.OnDataReceived(buffer, offset, count); },
cancellationTokenSource, ExceptionFunc);
}
/// <summary>
/// Invoke before request handler if it is set.
/// </summary>
/// <param name="args">The session event arguments.</param>
/// <returns></returns>
private async Task InvokeBeforeRequest(SessionEventArgs args)
private async Task invokeBeforeRequest(SessionEventArgs args)
{
if (BeforeRequest != null)
{
......
using System;
using System.Net;
using System.Net;
using System.Threading.Tasks;
using Titanium.Web.Proxy.EventArguments;
using Titanium.Web.Proxy.Exceptions;
using Titanium.Web.Proxy.Extensions;
using Titanium.Web.Proxy.Network.WinAuth.Security;
......@@ -18,10 +16,9 @@ namespace Titanium.Web.Proxy
/// </summary>
/// <param name="args">The session event arguments.</param>
/// <returns> The task.</returns>
private async Task HandleHttpSessionResponse(SessionEventArgs args)
{
try
private async Task handleHttpSessionResponse(SessionEventArgs args)
{
var cancellationToken = args.CancellationTokenSource.Token;
// read response & headers from server
......@@ -35,7 +32,7 @@ namespace Titanium.Web.Proxy
{
if (response.StatusCode == (int)HttpStatusCode.Unauthorized)
{
await Handle401UnAuthorized(args);
await handle401UnAuthorized(args);
}
else
{
......@@ -48,7 +45,7 @@ namespace Titanium.Web.Proxy
// if user requested call back then do it
if (!response.Locked)
{
await InvokeBeforeResponse(args);
await invokeBeforeResponse(args);
}
// it may changed in the user event
......@@ -80,7 +77,7 @@ namespace Titanium.Web.Proxy
{
// clear current response
await args.ClearResponse(cancellationToken);
await HandleHttpSessionRequestInternal(args.WebSession.ServerConnection, args);
await handleHttpSessionRequestInternal(args.WebSession.ServerConnection, args);
return;
}
......@@ -123,11 +120,7 @@ namespace Titanium.Web.Proxy
cancellationToken);
}
}
}
catch (Exception e) when (!(e is ProxyHttpException))
{
throw new ProxyHttpException("Error occured whilst handling session response", e, args);
}
}
/// <summary>
......@@ -135,7 +128,7 @@ namespace Titanium.Web.Proxy
/// </summary>
/// <param name="args"></param>
/// <returns></returns>
private async Task InvokeBeforeResponse(SessionEventArgs args)
private async Task invokeBeforeResponse(SessionEventArgs args)
{
if (BeforeResponse != null)
{
......@@ -148,7 +141,7 @@ namespace Titanium.Web.Proxy
/// </summary>
/// <param name="args"></param>
/// <returns></returns>
private async Task InvokeAfterResponse(SessionEventArgs args)
private async Task invokeAfterResponse(SessionEventArgs args)
{
if (AfterResponse != null)
{
......
using System;
using System.Collections.Generic;
using System.IO;
using System.Net.Security;
using System.Net.Sockets;
......@@ -27,7 +26,7 @@ namespace Titanium.Web.Proxy
/// <param name="endPoint">The transparent endpoint.</param>
/// <param name="clientConnection">The client connection.</param>
/// <returns></returns>
private async Task HandleClient(TransparentProxyEndPoint endPoint, TcpClientConnection clientConnection)
private async Task handleClient(TransparentProxyEndPoint endPoint, TcpClientConnection clientConnection)
{
var cancellationTokenSource = new CancellationTokenSource();
var cancellationToken = cancellationTokenSource.Token;
......@@ -125,24 +124,24 @@ namespace Titanium.Web.Proxy
// HTTPS server created - we can now decrypt the client's traffic
// Now create the request
await HandleHttpSessionRequest(endPoint, clientConnection, clientStream, clientStreamWriter,
await handleHttpSessionRequest(endPoint, clientConnection, clientStream, clientStreamWriter,
cancellationTokenSource, isHttps ? httpsHostName : null, null);
}
catch (ProxyException e)
{
OnException(clientStream, e);
onException(clientStream, e);
}
catch (IOException e)
{
OnException(clientStream, new Exception("Connection was aborted", e));
onException(clientStream, new Exception("Connection was aborted", e));
}
catch (SocketException e)
{
OnException(clientStream, new Exception("Could not connect", e));
onException(clientStream, new Exception("Could not connect", e));
}
catch (Exception e)
{
OnException(clientStream, new Exception("Error occured in whilst handling the client", e));
onException(clientStream, new Exception("Error occured in whilst handling the client", e));
}
finally
{
......
......@@ -45,7 +45,7 @@ namespace Titanium.Web.Proxy
/// User to server to authenticate requests.
/// To disable this set ProxyServer.EnableWinAuth to false.
/// </summary>
internal async Task Handle401UnAuthorized(SessionEventArgs args)
private async Task handle401UnAuthorized(SessionEventArgs args)
{
string headerName = null;
HttpHeader authHeader = null;
......@@ -99,7 +99,7 @@ namespace Titanium.Web.Proxy
if (!WinAuthEndPoint.ValidateWinAuthState(args.WebSession.Data, expectedAuthState))
{
// Invalid state, create proper error message to client
await RewriteUnauthorizedResponse(args);
await rewriteUnauthorizedResponse(args);
return;
}
......@@ -163,7 +163,7 @@ namespace Titanium.Web.Proxy
/// </summary>
/// <param name="args"></param>
/// <returns></returns>
internal async Task RewriteUnauthorizedResponse(SessionEventArgs args)
private async Task rewriteUnauthorizedResponse(SessionEventArgs args)
{
var response = args.WebSession.Response;
......
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