Commit ae0844b2 authored by justcoding121's avatar justcoding121

resharper code cleanup

parent 6f166dbb
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
namespace Titanium.Web.Proxy.EventArguments namespace Titanium.Web.Proxy.EventArguments
{ {
/// <summary> /// <summary>
/// A generic asynchronous event handler used by the proxy. /// A generic asynchronous event handler used by the proxy.
/// </summary> /// </summary>
/// <typeparam name="TEventArgs">Event argument type.</typeparam> /// <typeparam name="TEventArgs">Event argument type.</typeparam>
/// <param name="sender">The proxy server instance.</param> /// <param name="sender">The proxy server instance.</param>
......
...@@ -4,7 +4,7 @@ using System.Threading; ...@@ -4,7 +4,7 @@ using System.Threading;
namespace Titanium.Web.Proxy.EventArguments namespace Titanium.Web.Proxy.EventArguments
{ {
/// <summary> /// <summary>
/// This is used in transparent endpoint before authenticating client. /// This is used in transparent endpoint before authenticating client.
/// </summary> /// </summary>
public class BeforeSslAuthenticateEventArgs : EventArgs public class BeforeSslAuthenticateEventArgs : EventArgs
{ {
...@@ -16,19 +16,20 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -16,19 +16,20 @@ namespace Titanium.Web.Proxy.EventArguments
} }
/// <summary> /// <summary>
/// The server name indication hostname if available. Otherwise the generic certificate hostname of TransparentEndPoint. /// The server name indication hostname if available. Otherwise the generic certificate hostname of
/// TransparentEndPoint.
/// </summary> /// </summary>
public string SniHostName { get; internal set; } public string SniHostName { get; internal set; }
/// <summary> /// <summary>
/// Should we decrypt the SSL request? /// Should we decrypt the SSL request?
/// If true we decrypt with fake certificate. /// If true we decrypt with fake certificate.
/// If false we relay the connection to the hostname mentioned in SniHostname. /// If false we relay the connection to the hostname mentioned in SniHostname.
/// </summary> /// </summary>
public bool DecryptSsl { get; set; } = true; public bool DecryptSsl { get; set; } = true;
/// <summary> /// <summary>
/// Terminate the request abruptly by closing client/server connections. /// Terminate the request abruptly by closing client/server connections.
/// </summary> /// </summary>
public void TerminateSession() public void TerminateSession()
{ {
......
...@@ -3,7 +3,7 @@ using System; ...@@ -3,7 +3,7 @@ using System;
namespace Titanium.Web.Proxy.EventArguments namespace Titanium.Web.Proxy.EventArguments
{ {
/// <summary> /// <summary>
/// Wraps the data sent/received by a proxy server instance. /// Wraps the data sent/received by a proxy server instance.
/// </summary> /// </summary>
public class DataEventArgs : EventArgs public class DataEventArgs : EventArgs
{ {
...@@ -15,17 +15,17 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -15,17 +15,17 @@ namespace Titanium.Web.Proxy.EventArguments
} }
/// <summary> /// <summary>
/// The buffer with data. /// The buffer with data.
/// </summary> /// </summary>
public byte[] Buffer { get; } public byte[] Buffer { get; }
/// <summary> /// <summary>
/// Offset in buffer from which valid data begins. /// Offset in buffer from which valid data begins.
/// </summary> /// </summary>
public int Offset { get; } public int Offset { get; }
/// <summary> /// <summary>
/// Length from offset in buffer with valid data. /// Length from offset in buffer with valid data.
/// </summary> /// </summary>
public int Count { get; } public int Count { get; }
} }
......
...@@ -4,7 +4,7 @@ using Titanium.Web.Proxy.Http; ...@@ -4,7 +4,7 @@ using Titanium.Web.Proxy.Http;
namespace Titanium.Web.Proxy.EventArguments namespace Titanium.Web.Proxy.EventArguments
{ {
/// <summary> /// <summary>
/// Class that wraps the multipart sent request arguments. /// Class that wraps the multipart sent request arguments.
/// </summary> /// </summary>
public class MultipartRequestPartSentEventArgs : EventArgs public class MultipartRequestPartSentEventArgs : EventArgs
{ {
...@@ -15,12 +15,12 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -15,12 +15,12 @@ namespace Titanium.Web.Proxy.EventArguments
} }
/// <summary> /// <summary>
/// Boundary. /// Boundary.
/// </summary> /// </summary>
public string Boundary { get; } public string Boundary { get; }
/// <summary> /// <summary>
/// The header collection. /// The header collection.
/// </summary> /// </summary>
public HeaderCollection Headers { get; } public HeaderCollection Headers { get; }
} }
......
...@@ -554,7 +554,7 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -554,7 +554,7 @@ namespace Titanium.Web.Proxy.EventArguments
Respond(response); Respond(response);
} }
/// <summary> /// <summary>
/// Respond with given response object to client. /// Respond with given response object to client.
/// </summary> /// </summary>
/// <param name="response">The response object.</param> /// <param name="response">The response object.</param>
......
...@@ -21,10 +21,10 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -21,10 +21,10 @@ namespace Titanium.Web.Proxy.EventArguments
/// </summary> /// </summary>
protected readonly int BufferSize; protected readonly int BufferSize;
protected readonly ExceptionHandler ExceptionFunc;
internal readonly CancellationTokenSource CancellationTokenSource; internal readonly CancellationTokenSource CancellationTokenSource;
protected readonly ExceptionHandler ExceptionFunc;
/// <summary> /// <summary>
/// Constructor to initialize the proxy /// Constructor to initialize the proxy
/// </summary> /// </summary>
...@@ -100,17 +100,17 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -100,17 +100,17 @@ namespace Titanium.Web.Proxy.EventArguments
public ExternalProxy CustomUpStreamProxyUsed { get; internal set; } public ExternalProxy CustomUpStreamProxyUsed { get; internal set; }
/// <summary> /// <summary>
/// Local endpoint via which we make the request. /// Local endpoint via which we make the request.
/// </summary> /// </summary>
public ProxyEndPoint LocalEndPoint { get; } public ProxyEndPoint LocalEndPoint { get; }
/// <summary> /// <summary>
/// Is this a transparent endpoint? /// Is this a transparent endpoint?
/// </summary> /// </summary>
public bool IsTransparent => LocalEndPoint is TransparentProxyEndPoint; public bool IsTransparent => LocalEndPoint is TransparentProxyEndPoint;
/// <summary> /// <summary>
/// The last exception that happened. /// The last exception that happened.
/// </summary> /// </summary>
public Exception Exception { get; internal set; } public Exception Exception { get; internal set; }
...@@ -129,12 +129,12 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -129,12 +129,12 @@ namespace Titanium.Web.Proxy.EventArguments
} }
/// <summary> /// <summary>
/// Fired when data is sent within this session to server/client. /// Fired when data is sent within this session to server/client.
/// </summary> /// </summary>
public event EventHandler<DataEventArgs> DataSent; public event EventHandler<DataEventArgs> DataSent;
/// <summary> /// <summary>
/// Fired when data is received within this session from client/server. /// Fired when data is received within this session from client/server.
/// </summary> /// </summary>
public event EventHandler<DataEventArgs> DataReceived; public event EventHandler<DataEventArgs> DataReceived;
......
...@@ -6,7 +6,7 @@ using Titanium.Web.Proxy.Models; ...@@ -6,7 +6,7 @@ using Titanium.Web.Proxy.Models;
namespace Titanium.Web.Proxy.EventArguments namespace Titanium.Web.Proxy.EventArguments
{ {
/// <summary> /// <summary>
/// A class that wraps the state when a tunnel connect event happen for Explicit endpoints. /// A class that wraps the state when a tunnel connect event happen for Explicit endpoints.
/// </summary> /// </summary>
public class TunnelConnectSessionEventArgs : SessionEventArgsBase public class TunnelConnectSessionEventArgs : SessionEventArgsBase
{ {
...@@ -20,8 +20,8 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -20,8 +20,8 @@ namespace Titanium.Web.Proxy.EventArguments
} }
/// <summary> /// <summary>
/// Should we decrypt the Ssl or relay it to server? /// Should we decrypt the Ssl or relay it to server?
/// Default is true. /// Default is true.
/// </summary> /// </summary>
public bool DecryptSsl { get; set; } = true; public bool DecryptSsl { get; set; } = true;
...@@ -31,11 +31,12 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -31,11 +31,12 @@ namespace Titanium.Web.Proxy.EventArguments
public bool DenyConnect { get; set; } public bool DenyConnect { get; set; }
/// <summary> /// <summary>
/// Is this a connect request to secure HTTP server? Or is it to someother protocol. /// Is this a connect request to secure HTTP server? Or is it to someother protocol.
/// </summary> /// </summary>
public bool IsHttpsConnect public bool IsHttpsConnect
{ {
get => isHttpsConnect ?? throw new Exception("The value of this property is known in the BeforeTunnectConnectResponse event"); get => isHttpsConnect ??
throw new Exception("The value of this property is known in the BeforeTunnectConnectResponse event");
internal set => isHttpsConnect = value; internal set => isHttpsConnect = value;
} }
} }
......
...@@ -3,7 +3,7 @@ using System; ...@@ -3,7 +3,7 @@ using System;
namespace Titanium.Web.Proxy namespace Titanium.Web.Proxy
{ {
/// <summary> /// <summary>
/// A delegate to catch exceptions occuring in proxy. /// A delegate to catch exceptions occuring in proxy.
/// </summary> /// </summary>
/// <param name="exception">The exception occurred in proxy.</param> /// <param name="exception">The exception occurred in proxy.</param>
public delegate void ExceptionHandler(Exception exception); public delegate void ExceptionHandler(Exception exception);
......
...@@ -25,7 +25,7 @@ namespace Titanium.Web.Proxy.Exceptions ...@@ -25,7 +25,7 @@ namespace Titanium.Web.Proxy.Exceptions
} }
/// <summary> /// <summary>
/// The current session within which this error happened. /// The current session within which this error happened.
/// </summary> /// </summary>
public SessionEventArgsBase Session { get; } public SessionEventArgsBase Session { get; }
......
using System; using System;
using System.IO; using System.IO;
using System.Linq;
using System.Net; using System.Net;
using System.Net.Security; using System.Net.Security;
using System.Net.Sockets; using System.Net.Sockets;
...@@ -90,7 +89,8 @@ namespace Titanium.Web.Proxy ...@@ -90,7 +89,8 @@ namespace Titanium.Web.Proxy
} }
//send the response //send the response
await clientStreamWriter.WriteResponseAsync(connectArgs.WebSession.Response, cancellationToken: cancellationToken); await clientStreamWriter.WriteResponseAsync(connectArgs.WebSession.Response,
cancellationToken: cancellationToken);
return; return;
} }
...@@ -99,13 +99,14 @@ namespace Titanium.Web.Proxy ...@@ -99,13 +99,14 @@ namespace Titanium.Web.Proxy
await endPoint.InvokeBeforeTunnectConnectResponse(this, connectArgs, ExceptionFunc); await endPoint.InvokeBeforeTunnectConnectResponse(this, connectArgs, ExceptionFunc);
//send the response //send the response
await clientStreamWriter.WriteResponseAsync(connectArgs.WebSession.Response, cancellationToken: cancellationToken); await clientStreamWriter.WriteResponseAsync(connectArgs.WebSession.Response,
cancellationToken: cancellationToken);
return; return;
} }
//write back successfull CONNECT response //write back successfull CONNECT response
var response = ConnectResponse.CreateSuccessfullConnectResponse(version); var response = ConnectResponse.CreateSuccessfullConnectResponse(version);
// Set ContentLength explicitly to properly handle HTTP 1.0 // Set ContentLength explicitly to properly handle HTTP 1.0
response.ContentLength = 0; response.ContentLength = 0;
response.Headers.FixProxyHeaders(); response.Headers.FixProxyHeaders();
...@@ -212,7 +213,8 @@ namespace Titanium.Web.Proxy ...@@ -212,7 +213,8 @@ namespace Titanium.Web.Proxy
{ {
// clientStream.Available sbould be at most BufferSize because it is using the same buffer size // clientStream.Available sbould be at most BufferSize because it is using the same buffer size
await clientStream.ReadAsync(data, 0, available, cancellationToken); await clientStream.ReadAsync(data, 0, available, cancellationToken);
await connection.StreamWriter.WriteAsync(data, 0, available, true, cancellationToken); await connection.StreamWriter.WriteAsync(data, 0, available, true,
cancellationToken);
} }
finally finally
{ {
...@@ -220,7 +222,8 @@ namespace Titanium.Web.Proxy ...@@ -220,7 +222,8 @@ namespace Titanium.Web.Proxy
} }
} }
var serverHelloInfo = await SslTools.PeekServerHello(connection.Stream, cancellationToken); var serverHelloInfo =
await SslTools.PeekServerHello(connection.Stream, cancellationToken);
((ConnectResponse)connectArgs.WebSession.Response).ServerHelloInfo = serverHelloInfo; ((ConnectResponse)connectArgs.WebSession.Response).ServerHelloInfo = serverHelloInfo;
} }
...@@ -242,13 +245,22 @@ namespace Titanium.Web.Proxy ...@@ -242,13 +245,22 @@ namespace Titanium.Web.Proxy
{ {
// HTTP/2 Connection Preface // HTTP/2 Connection Preface
string line = await clientStreamReader.ReadLineAsync(cancellationToken); string line = await clientStreamReader.ReadLineAsync(cancellationToken);
if (line != string.Empty) throw new Exception($"HTTP/2 Protocol violation. Empty string expected, '{line}' received"); if (line != string.Empty)
{
throw new Exception($"HTTP/2 Protocol violation. Empty string expected, '{line}' received");
}
line = await clientStreamReader.ReadLineAsync(cancellationToken); line = await clientStreamReader.ReadLineAsync(cancellationToken);
if (line != "SM") throw new Exception($"HTTP/2 Protocol violation. 'SM' expected, '{line}' received"); if (line != "SM")
{
throw new Exception($"HTTP/2 Protocol violation. 'SM' expected, '{line}' received");
}
line = await clientStreamReader.ReadLineAsync(cancellationToken); line = await clientStreamReader.ReadLineAsync(cancellationToken);
if (line != string.Empty) throw new Exception($"HTTP/2 Protocol violation. Empty string expected, '{line}' received"); if (line != string.Empty)
{
throw new Exception($"HTTP/2 Protocol violation. Empty string expected, '{line}' received");
}
//create new connection //create new connection
using (var connection = await GetServerConnection(connectArgs, true, cancellationToken)) using (var connection = await GetServerConnection(connectArgs, true, cancellationToken))
...@@ -268,7 +280,8 @@ namespace Titanium.Web.Proxy ...@@ -268,7 +280,8 @@ namespace Titanium.Web.Proxy
//Now create the request //Now create the request
await HandleHttpSessionRequest(endPoint, tcpClient, clientStream, clientStreamReader, await HandleHttpSessionRequest(endPoint, tcpClient, clientStream, clientStreamReader,
clientStreamWriter, cancellationTokenSource, connectHostname, connectArgs?.WebSession.ConnectRequest); clientStreamWriter, cancellationTokenSource, connectHostname,
connectArgs?.WebSession.ConnectRequest);
} }
catch (ProxyHttpException e) catch (ProxyHttpException e)
{ {
......
using System; using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using System.Net.Security; using System.Net.Security;
using System.Security.Authentication; using System.Security.Authentication;
using System.Security.Cryptography.X509Certificates; using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using StreamExtended; using StreamExtended;
...@@ -13,7 +10,8 @@ namespace Titanium.Web.Proxy.Extensions ...@@ -13,7 +10,8 @@ namespace Titanium.Web.Proxy.Extensions
{ {
internal static class SslExtensions internal static class SslExtensions
{ {
internal static readonly List<SslApplicationProtocol> Http11ProtocolAsList = new List<SslApplicationProtocol> { SslApplicationProtocol.Http11 }; internal static readonly List<SslApplicationProtocol> Http11ProtocolAsList =
new List<SslApplicationProtocol> { SslApplicationProtocol.Http11 };
internal static string GetServerName(this ClientHelloInfo clientHelloInfo) internal static string GetServerName(this ClientHelloInfo clientHelloInfo)
{ {
...@@ -60,14 +58,18 @@ namespace Titanium.Web.Proxy.Extensions ...@@ -60,14 +58,18 @@ namespace Titanium.Web.Proxy.Extensions
return Http11ProtocolAsList; return Http11ProtocolAsList;
} }
internal static Task AuthenticateAsClientAsync(this SslStream sslStream, SslClientAuthenticationOptions option, CancellationToken token) internal static Task AuthenticateAsClientAsync(this SslStream sslStream, SslClientAuthenticationOptions option,
CancellationToken token)
{ {
return sslStream.AuthenticateAsClientAsync(option.TargetHost, option.ClientCertificates, option.EnabledSslProtocols, option.CertificateRevocationCheckMode != X509RevocationMode.NoCheck); return sslStream.AuthenticateAsClientAsync(option.TargetHost, option.ClientCertificates,
option.EnabledSslProtocols, option.CertificateRevocationCheckMode != X509RevocationMode.NoCheck);
} }
internal static Task AuthenticateAsServerAsync(this SslStream sslStream, SslServerAuthenticationOptions options, CancellationToken token) internal static Task AuthenticateAsServerAsync(this SslStream sslStream, SslServerAuthenticationOptions options,
CancellationToken token)
{ {
return sslStream.AuthenticateAsServerAsync(options.ServerCertificate, options.ClientCertificateRequired, options.EnabledSslProtocols, options.CertificateRevocationCheckMode != X509RevocationMode.NoCheck); return sslStream.AuthenticateAsServerAsync(options.ServerCertificate, options.ClientCertificateRequired,
options.EnabledSslProtocols, options.CertificateRevocationCheckMode != X509RevocationMode.NoCheck);
} }
#endif #endif
} }
...@@ -75,7 +77,8 @@ namespace Titanium.Web.Proxy.Extensions ...@@ -75,7 +77,8 @@ namespace Titanium.Web.Proxy.Extensions
#if !NETCOREAPP2_1 #if !NETCOREAPP2_1
internal enum SslApplicationProtocol internal enum SslApplicationProtocol
{ {
Http11, Http2 Http11,
Http2
} }
internal class SslClientAuthenticationOptions internal class SslClientAuthenticationOptions
......
...@@ -141,7 +141,7 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -141,7 +141,7 @@ namespace Titanium.Web.Proxy.Helpers
/// <param name="clientStream">The client stream.</param> /// <param name="clientStream">The client stream.</param>
/// <param name="expectedStart">The expected start.</param> /// <param name="expectedStart">The expected start.</param>
/// <returns> /// <returns>
/// 1: when starts with the given string, 0: when valid HTTP method, -1: otherwise /// 1: when starts with the given string, 0: when valid HTTP method, -1: otherwise
/// </returns> /// </returns>
private static async Task<int> StartsWith(CustomBufferedStream clientStream, string expectedStart) private static async Task<int> StartsWith(CustomBufferedStream clientStream, string expectedStart)
{ {
......
...@@ -35,7 +35,8 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -35,7 +35,8 @@ namespace Titanium.Web.Proxy.Helpers
/// <param name="description">The HTTP status description.</param> /// <param name="description">The HTTP status description.</param>
/// <param name="cancellationToken">Optional cancellation token for this async task.</param> /// <param name="cancellationToken">Optional cancellation token for this async task.</param>
/// <returns>The Task.</returns> /// <returns>The Task.</returns>
internal Task WriteResponseStatusAsync(Version version, int code, string description, CancellationToken cancellationToken) internal Task WriteResponseStatusAsync(Version version, int code, string description,
CancellationToken cancellationToken)
{ {
return WriteLineAsync(Response.CreateResponseLine(version, code, description), cancellationToken); return WriteLineAsync(Response.CreateResponseLine(version, code, description), cancellationToken);
} }
......
...@@ -30,7 +30,7 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -30,7 +30,7 @@ namespace Titanium.Web.Proxy.Helpers
internal int BufferSize { get; } internal int BufferSize { get; }
/// <summary> /// <summary>
/// Writes a line async /// Writes a line async
/// </summary> /// </summary>
/// <param name="cancellationToken">Optional cancellation token for this async task.</param> /// <param name="cancellationToken">Optional cancellation token for this async task.</param>
/// <returns></returns> /// <returns></returns>
...@@ -98,7 +98,8 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -98,7 +98,8 @@ namespace Titanium.Web.Proxy.Helpers
/// <param name="flush"></param> /// <param name="flush"></param>
/// <param name="cancellationToken"></param> /// <param name="cancellationToken"></param>
/// <returns></returns> /// <returns></returns>
internal async Task WriteHeadersAsync(HeaderCollection headers, bool flush = true, CancellationToken cancellationToken = default) internal async Task WriteHeadersAsync(HeaderCollection headers, bool flush = true,
CancellationToken cancellationToken = default)
{ {
foreach (var header in headers) foreach (var header in headers)
{ {
...@@ -121,7 +122,8 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -121,7 +122,8 @@ namespace Titanium.Web.Proxy.Helpers
} }
} }
internal async Task WriteAsync(byte[] data, int offset, int count, bool flush, CancellationToken cancellationToken = default) internal async Task WriteAsync(byte[] data, int offset, int count, bool flush,
CancellationToken cancellationToken = default)
{ {
await WriteAsync(data, offset, count, cancellationToken); await WriteAsync(data, offset, count, cancellationToken);
if (flush) if (flush)
...@@ -202,7 +204,8 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -202,7 +204,8 @@ namespace Titanium.Web.Proxy.Helpers
/// <param name="onCopy"></param> /// <param name="onCopy"></param>
/// <param name="cancellationToken"></param> /// <param name="cancellationToken"></param>
/// <returns></returns> /// <returns></returns>
private async Task CopyBodyChunkedAsync(CustomBinaryReader reader, Action<byte[], int, int> onCopy, CancellationToken cancellationToken) private async Task CopyBodyChunkedAsync(CustomBinaryReader reader, Action<byte[], int, int> onCopy,
CancellationToken cancellationToken)
{ {
while (true) while (true)
{ {
...@@ -242,7 +245,8 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -242,7 +245,8 @@ namespace Titanium.Web.Proxy.Helpers
/// <param name="onCopy"></param> /// <param name="onCopy"></param>
/// <param name="cancellationToken"></param> /// <param name="cancellationToken"></param>
/// <returns></returns> /// <returns></returns>
private async Task CopyBytesFromStream(CustomBinaryReader reader, long count, Action<byte[], int, int> onCopy, CancellationToken cancellationToken) private async Task CopyBytesFromStream(CustomBinaryReader reader, long count, Action<byte[], int, int> onCopy,
CancellationToken cancellationToken)
{ {
var buffer = reader.Buffer; var buffer = reader.Buffer;
long remainingBytes = count; long remainingBytes = count;
...@@ -276,7 +280,8 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -276,7 +280,8 @@ namespace Titanium.Web.Proxy.Helpers
/// <param name="flush"></param> /// <param name="flush"></param>
/// <param name="cancellationToken"></param> /// <param name="cancellationToken"></param>
/// <returns></returns> /// <returns></returns>
protected async Task WriteAsync(RequestResponseBase requestResponse, bool flush = true, CancellationToken cancellationToken = default) protected async Task WriteAsync(RequestResponseBase requestResponse, bool flush = true,
CancellationToken cancellationToken = default)
{ {
var body = requestResponse.CompressBodyAndUpdateContentLength(); var body = requestResponse.CompressBodyAndUpdateContentLength();
await WriteHeadersAsync(requestResponse.Headers, flush, cancellationToken); await WriteHeadersAsync(requestResponse.Headers, flush, cancellationToken);
......
...@@ -44,7 +44,7 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -44,7 +44,7 @@ namespace Titanium.Web.Proxy.Helpers
} }
/// <summary> /// <summary>
/// <see href="https://msdn.microsoft.com/en-us/library/aa366896.aspx"/> /// <see href="https://msdn.microsoft.com/en-us/library/aa366896.aspx" />
/// </summary> /// </summary>
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
internal unsafe struct Tcp6Row internal unsafe struct Tcp6Row
......
using System; namespace Titanium.Web.Proxy.Helpers
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Titanium.Web.Proxy.Helpers
{ {
internal class Ref<T> internal class Ref<T>
{ {
...@@ -21,7 +15,7 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -21,7 +15,7 @@ namespace Titanium.Web.Proxy.Helpers
public override string ToString() public override string ToString()
{ {
T value = Value; var value = Value;
return value == null ? string.Empty : value.ToString(); return value == null ? string.Empty : value.ToString();
} }
......
using System; using System;
using System.Runtime.InteropServices;
namespace Titanium.Web.Proxy.Helpers namespace Titanium.Web.Proxy.Helpers
{ {
...@@ -19,7 +18,8 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -19,7 +18,8 @@ namespace Titanium.Web.Proxy.Helpers
/// cache for Windows platform check /// cache for Windows platform check
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
private static readonly Lazy<bool> isRunningOnWindows = new Lazy<bool>(() => RuntimeInformation.IsOSPlatform(OSPlatform.Windows)); private static readonly Lazy<bool> isRunningOnWindows =
new Lazy<bool>(() => RuntimeInformation.IsOSPlatform(OSPlatform.Windows));
#endif #endif
......
...@@ -41,7 +41,7 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -41,7 +41,7 @@ namespace Titanium.Web.Proxy.Helpers
if (ipVersion == IpVersion.Ipv4) if (ipVersion == IpVersion.Ipv4)
{ {
NativeMethods.TcpRow* rowPtr = (NativeMethods.TcpRow*)(tcpTable + 4); var rowPtr = (NativeMethods.TcpRow*)(tcpTable + 4);
for (int i = 0; i < rowCount; ++i) for (int i = 0; i < rowCount; ++i)
{ {
...@@ -55,7 +55,7 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -55,7 +55,7 @@ namespace Titanium.Web.Proxy.Helpers
} }
else else
{ {
NativeMethods.Tcp6Row* rowPtr = (NativeMethods.Tcp6Row*)(tcpTable + 4); var rowPtr = (NativeMethods.Tcp6Row*)(tcpTable + 4);
for (int i = 0; i < rowCount; ++i) for (int i = 0; i < rowCount; ++i)
{ {
...@@ -82,9 +82,9 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -82,9 +82,9 @@ namespace Titanium.Web.Proxy.Helpers
} }
/// <summary> /// <summary>
/// Converts 32-bit integer from native byte order (little-endian) /// Converts 32-bit integer from native byte order (little-endian)
/// to network byte order for port, /// to network byte order for port,
/// switches 0th and 1st bytes, and 2nd and 3rd bytes /// switches 0th and 1st bytes, and 2nd and 3rd bytes
/// </summary> /// </summary>
/// <param name="port"></param> /// <param name="port"></param>
/// <returns></returns> /// <returns></returns>
...@@ -276,9 +276,11 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -276,9 +276,11 @@ namespace Titanium.Web.Proxy.Helpers
//Now async relay all server=>client & client=>server data //Now async relay all server=>client & client=>server data
var sendRelay = var sendRelay =
CopyHttp2FrameAsync(clientStream, serverStream, onDataSend, bufferSize, connectionId, cancellationTokenSource.Token); CopyHttp2FrameAsync(clientStream, serverStream, onDataSend, bufferSize, connectionId,
cancellationTokenSource.Token);
var receiveRelay = var receiveRelay =
CopyHttp2FrameAsync(serverStream, clientStream, onDataReceive, bufferSize, connectionId, cancellationTokenSource.Token); CopyHttp2FrameAsync(serverStream, clientStream, onDataReceive, bufferSize, connectionId,
cancellationTokenSource.Token);
await Task.WhenAny(sendRelay, receiveRelay); await Task.WhenAny(sendRelay, receiveRelay);
cancellationTokenSource.Cancel(); cancellationTokenSource.Cancel();
...@@ -302,7 +304,8 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -302,7 +304,8 @@ namespace Titanium.Web.Proxy.Helpers
int length = (headerBuffer[0] << 16) + (headerBuffer[1] << 8) + headerBuffer[2]; int length = (headerBuffer[0] << 16) + (headerBuffer[1] << 8) + headerBuffer[2];
byte type = headerBuffer[3]; byte type = headerBuffer[3];
byte flags = headerBuffer[4]; byte flags = headerBuffer[4];
int streamId = ((headerBuffer[5] & 0x7f) << 24) + (headerBuffer[6] << 16) + (headerBuffer[7] << 8) + headerBuffer[8]; int streamId = ((headerBuffer[5] & 0x7f) << 24) + (headerBuffer[6] << 16) + (headerBuffer[7] << 8) +
headerBuffer[8];
read = await ForceRead(input, buffer, 0, length, cancellationToken); read = await ForceRead(input, buffer, 0, length, cancellationToken);
if (read != length) if (read != length)
...@@ -321,7 +324,8 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -321,7 +324,8 @@ namespace Titanium.Web.Proxy.Helpers
} }
} }
private static async Task<int> ForceRead(Stream input, byte[] buffer, int offset, int bytesToRead, CancellationToken cancellationToken) private static async Task<int> ForceRead(Stream input, byte[] buffer, int offset, int bytesToRead,
CancellationToken cancellationToken)
{ {
int totalRead = 0; int totalRead = 0;
while (bytesToRead > 0) while (bytesToRead > 0)
......
...@@ -8,7 +8,8 @@ namespace Titanium.Web.Proxy.Http ...@@ -8,7 +8,8 @@ namespace Titanium.Web.Proxy.Http
{ {
internal static class HeaderParser internal static class HeaderParser
{ {
internal static async Task ReadHeaders(CustomBinaryReader reader, HeaderCollection headerCollection, CancellationToken cancellationToken) internal static async Task ReadHeaders(CustomBinaryReader reader, HeaderCollection headerCollection,
CancellationToken cancellationToken)
{ {
string tmpLine; string tmpLine;
while (!string.IsNullOrEmpty(tmpLine = await reader.ReadLineAsync(cancellationToken))) while (!string.IsNullOrEmpty(tmpLine = await reader.ReadLineAsync(cancellationToken)))
......
...@@ -80,7 +80,8 @@ namespace Titanium.Web.Proxy.Http ...@@ -80,7 +80,8 @@ namespace Titanium.Web.Proxy.Http
/// Prepare and send the http(s) request /// Prepare and send the http(s) request
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
internal async Task SendRequest(bool enable100ContinueBehaviour, bool isTransparent, CancellationToken cancellationToken) internal async Task SendRequest(bool enable100ContinueBehaviour, bool isTransparent,
CancellationToken cancellationToken)
{ {
var upstreamProxy = ServerConnection.UpStreamProxy; var upstreamProxy = ServerConnection.UpStreamProxy;
......
...@@ -89,7 +89,7 @@ namespace Titanium.Web.Proxy.Http ...@@ -89,7 +89,7 @@ namespace Titanium.Web.Proxy.Http
} }
/// <summary> /// <summary>
/// Does this request contain multipart/form-data? /// Does this request contain multipart/form-data?
/// </summary> /// </summary>
public bool IsMultipartFormData => ContentType?.StartsWith("multipart/form-data") == true; public bool IsMultipartFormData => ContentType?.StartsWith("multipart/form-data") == true;
......
...@@ -120,7 +120,7 @@ namespace Titanium.Web.Proxy.Http ...@@ -120,7 +120,7 @@ namespace Titanium.Web.Proxy.Http
} }
/// <summary> /// <summary>
/// The header text. /// The header text.
/// </summary> /// </summary>
public abstract string HeaderText { get; } public abstract string HeaderText { get; }
......
...@@ -13,7 +13,7 @@ namespace Titanium.Web.Proxy.Models ...@@ -13,7 +13,7 @@ namespace Titanium.Web.Proxy.Models
public class ExplicitProxyEndPoint : ProxyEndPoint public class ExplicitProxyEndPoint : ProxyEndPoint
{ {
/// <summary> /// <summary>
/// Constructor. /// Constructor.
/// </summary> /// </summary>
/// <param name="ipAddress">Listening IP address.</param> /// <param name="ipAddress">Listening IP address.</param>
/// <param name="port">Listening port.</param> /// <param name="port">Listening port.</param>
......
...@@ -70,7 +70,7 @@ namespace Titanium.Web.Proxy.Models ...@@ -70,7 +70,7 @@ namespace Titanium.Web.Proxy.Models
public int Port { get; set; } public int Port { get; set; }
/// <summary> /// <summary>
/// returns data in Hostname:port format. /// returns data in Hostname:port format.
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public override string ToString() public override string ToString()
......
...@@ -22,11 +22,11 @@ namespace Titanium.Web.Proxy.Models ...@@ -22,11 +22,11 @@ namespace Titanium.Web.Proxy.Models
internal static readonly HttpHeader ProxyConnectionKeepAlive = new HttpHeader("Proxy-Connection", "keep-alive"); internal static readonly HttpHeader ProxyConnectionKeepAlive = new HttpHeader("Proxy-Connection", "keep-alive");
/// <summary> /// <summary>
/// Initialize a new instance. /// Initialize a new instance.
/// </summary> /// </summary>
/// <param name="name">Header name.</param> /// <param name="name">Header name.</param>
/// <param name="value">Header value.</param> /// <param name="value">Header value.</param>
public HttpHeader(string name, string value) public HttpHeader(string name, string value)
{ {
if (string.IsNullOrEmpty(name)) if (string.IsNullOrEmpty(name))
......
...@@ -12,7 +12,7 @@ namespace Titanium.Web.Proxy.Models ...@@ -12,7 +12,7 @@ namespace Titanium.Web.Proxy.Models
public class TransparentProxyEndPoint : ProxyEndPoint public class TransparentProxyEndPoint : ProxyEndPoint
{ {
/// <summary> /// <summary>
/// Initialize a new instance. /// Initialize a new instance.
/// </summary> /// </summary>
/// <param name="ipAddress">Listening Ip address.</param> /// <param name="ipAddress">Listening Ip address.</param>
/// <param name="port">Listening port.</param> /// <param name="port">Listening port.</param>
......
...@@ -60,13 +60,18 @@ namespace Titanium.Web.Proxy.Network ...@@ -60,13 +60,18 @@ namespace Titanium.Web.Proxy.Network
/// <summary> /// <summary>
///
/// </summary> /// </summary>
/// <param name="rootCertificateName"></param> /// <param name="rootCertificateName"></param>
/// <param name="rootCertificateIssuerName"></param> /// <param name="rootCertificateIssuerName"></param>
/// <param name="userTrustRootCertificate">Should fake HTTPS certificate be trusted by this machine's user certificate store?</param> /// <param name="userTrustRootCertificate">
/// Should fake HTTPS certificate be trusted by this machine's user certificate
/// store?
/// </param>
/// <param name="machineTrustRootCertificate">Should fake HTTPS certificate be trusted by this machine's certificate store?</param> /// <param name="machineTrustRootCertificate">Should fake HTTPS certificate be trusted by this machine's certificate store?</param>
/// <param name="trustRootCertificateAsAdmin">Should we attempt to trust certificates with elevated permissions by prompting for UAC if required?</param> /// <param name="trustRootCertificateAsAdmin">
/// Should we attempt to trust certificates with elevated permissions by
/// prompting for UAC if required?
/// </param>
/// <param name="exceptionFunc"></param> /// <param name="exceptionFunc"></param>
internal CertificateManager(string rootCertificateName, string rootCertificateIssuerName, internal CertificateManager(string rootCertificateName, string rootCertificateIssuerName,
bool userTrustRootCertificate, bool machineTrustRootCertificate, bool trustRootCertificateAsAdmin, bool userTrustRootCertificate, bool machineTrustRootCertificate, bool trustRootCertificateAsAdmin,
...@@ -639,7 +644,10 @@ namespace Titanium.Web.Proxy.Network ...@@ -639,7 +644,10 @@ namespace Titanium.Web.Proxy.Network
/// named as "rootCert.pfx" (and will be saved in proxy dll directory). /// named as "rootCert.pfx" (and will be saved in proxy dll directory).
/// </param> /// </param>
/// <param name="password">Set a password for the .pfx file.</param> /// <param name="password">Set a password for the .pfx file.</param>
/// <param name="overwritePfXFile">true : replace an existing .pfx file if password is incorect or if RootCertificate==null.</param> /// <param name="overwritePfXFile">
/// true : replace an existing .pfx file if password is incorect or if
/// RootCertificate==null.
/// </param>
/// <param name="storageFlag"></param> /// <param name="storageFlag"></param>
/// <returns> /// <returns>
/// true if succeeded, else false. /// true if succeeded, else false.
...@@ -765,9 +773,15 @@ namespace Titanium.Web.Proxy.Network ...@@ -765,9 +773,15 @@ namespace Titanium.Web.Proxy.Network
/// Also makes root certificate trusted based on provided parameters. /// Also makes root certificate trusted based on provided parameters.
/// Note:setting machineTrustRootCertificate to true will force userTrustRootCertificate to true. /// Note:setting machineTrustRootCertificate to true will force userTrustRootCertificate to true.
/// </summary> /// </summary>
/// <param name="userTrustRootCertificate">Should fake HTTPS certificate be trusted by this machine's user certificate store?</param> /// <param name="userTrustRootCertificate">
/// Should fake HTTPS certificate be trusted by this machine's user certificate
/// store?
/// </param>
/// <param name="machineTrustRootCertificate">Should fake HTTPS certificate be trusted by this machine's certificate store?</param> /// <param name="machineTrustRootCertificate">Should fake HTTPS certificate be trusted by this machine's certificate store?</param>
/// <param name="trustRootCertificateAsAdmin">Should we attempt to trust certificates with elevated permissions by prompting for UAC if required?</param> /// <param name="trustRootCertificateAsAdmin">
/// Should we attempt to trust certificates with elevated permissions by
/// prompting for UAC if required?
/// </param>
public void EnsureRootCertificate(bool userTrustRootCertificate, public void EnsureRootCertificate(bool userTrustRootCertificate,
bool machineTrustRootCertificate, bool trustRootCertificateAsAdmin = false) bool machineTrustRootCertificate, bool trustRootCertificateAsAdmin = false)
{ {
...@@ -907,7 +921,7 @@ namespace Titanium.Web.Proxy.Network ...@@ -907,7 +921,7 @@ namespace Titanium.Web.Proxy.Network
} }
/// <summary> /// <summary>
/// Clear the root certificate and cache. /// Clear the root certificate and cache.
/// </summary> /// </summary>
public void ClearRootCertificate() public void ClearRootCertificate()
{ {
......
...@@ -3,7 +3,6 @@ using System.Collections.Generic; ...@@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.Net; using System.Net;
using System.Net.Security; using System.Net.Security;
using System.Net.Sockets; using System.Net.Sockets;
using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using StreamExtended.Network; using StreamExtended.Network;
...@@ -33,9 +32,10 @@ namespace Titanium.Web.Proxy.Network.Tcp ...@@ -33,9 +32,10 @@ namespace Titanium.Web.Proxy.Network.Tcp
/// <param name="externalProxy"></param> /// <param name="externalProxy"></param>
/// <param name="cancellationToken"></param> /// <param name="cancellationToken"></param>
/// <returns></returns> /// <returns></returns>
internal async Task<TcpConnection> CreateClient(string remoteHostName, int remotePort, internal async Task<TcpConnection> CreateClient(string remoteHostName, int remotePort,
List<SslApplicationProtocol> applicationProtocols, Version httpVersion, bool decryptSsl, bool isConnect, List<SslApplicationProtocol> applicationProtocols, Version httpVersion, bool decryptSsl, bool isConnect,
ProxyServer proxyServer, IPEndPoint upStreamEndPoint, ExternalProxy externalProxy, CancellationToken cancellationToken) ProxyServer proxyServer, IPEndPoint upStreamEndPoint, ExternalProxy externalProxy,
CancellationToken cancellationToken)
{ {
bool useUpstreamProxy = false; bool useUpstreamProxy = false;
...@@ -79,7 +79,7 @@ namespace Titanium.Web.Proxy.Network.Tcp ...@@ -79,7 +79,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
var connectRequest = new ConnectRequest var connectRequest = new ConnectRequest
{ {
OriginalUrl = $"{remoteHostName}:{remotePort}", OriginalUrl = $"{remoteHostName}:{remotePort}",
HttpVersion = httpVersion, HttpVersion = httpVersion
}; };
connectRequest.Headers.AddHeader(KnownHeaders.Connection, KnownHeaders.ConnectionKeepAlive); connectRequest.Headers.AddHeader(KnownHeaders.Connection, KnownHeaders.ConnectionKeepAlive);
...@@ -87,7 +87,8 @@ namespace Titanium.Web.Proxy.Network.Tcp ...@@ -87,7 +87,8 @@ namespace Titanium.Web.Proxy.Network.Tcp
if (!string.IsNullOrEmpty(externalProxy.UserName) && externalProxy.Password != null) if (!string.IsNullOrEmpty(externalProxy.UserName) && externalProxy.Password != null)
{ {
connectRequest.Headers.AddHeader(HttpHeader.ProxyConnectionKeepAlive); connectRequest.Headers.AddHeader(HttpHeader.ProxyConnectionKeepAlive);
connectRequest.Headers.AddHeader(HttpHeader.GetProxyAuthorizationHeader(externalProxy.UserName, externalProxy.Password)); connectRequest.Headers.AddHeader(
HttpHeader.GetProxyAuthorizationHeader(externalProxy.UserName, externalProxy.Password));
} }
await writer.WriteRequestAsync(connectRequest, cancellationToken: cancellationToken); await writer.WriteRequestAsync(connectRequest, cancellationToken: cancellationToken);
......
...@@ -20,14 +20,15 @@ namespace Titanium.Web.Proxy ...@@ -20,14 +20,15 @@ namespace Titanium.Web.Proxy
{ {
/// <summary> /// <summary>
/// This object is the backbone of proxy. One can create as many instances as needed. /// This object is the backbone of proxy. One can create as many instances as needed.
/// However care should be taken to avoid using the same listening ports across multiple instances. /// However care should be taken to avoid using the same listening ports across multiple instances.
/// </summary> /// </summary>
public partial class ProxyServer : IDisposable public partial class ProxyServer : IDisposable
{ {
/// <summary> /// <summary>
/// HTTP & HTTPS scheme shorthands. /// HTTP & HTTPS scheme shorthands.
/// </summary> /// </summary>
internal static readonly string UriSchemeHttp = Uri.UriSchemeHttp; internal static readonly string UriSchemeHttp = Uri.UriSchemeHttp;
internal static readonly string UriSchemeHttps = Uri.UriSchemeHttps; internal static readonly string UriSchemeHttps = Uri.UriSchemeHttps;
/// <summary> /// <summary>
...@@ -56,11 +57,17 @@ namespace Titanium.Web.Proxy ...@@ -56,11 +57,17 @@ namespace Titanium.Web.Proxy
private WinHttpWebProxyFinder systemProxyResolver; private WinHttpWebProxyFinder systemProxyResolver;
/// <summary> /// <summary>
/// Initializes a new instance of ProxyServer class with provided parameters. /// Initializes a new instance of ProxyServer class with provided parameters.
/// </summary> /// </summary>
/// <param name="userTrustRootCertificate">Should fake HTTPS certificate be trusted by this machine's user certificate store?</param> /// <param name="userTrustRootCertificate">
/// Should fake HTTPS certificate be trusted by this machine's user certificate
/// store?
/// </param>
/// <param name="machineTrustRootCertificate">Should fake HTTPS certificate be trusted by this machine's certificate store?</param> /// <param name="machineTrustRootCertificate">Should fake HTTPS certificate be trusted by this machine's certificate store?</param>
/// <param name="trustRootCertificateAsAdmin">Should we attempt to trust certificates with elevated permissions by prompting for UAC if required?</param> /// <param name="trustRootCertificateAsAdmin">
/// Should we attempt to trust certificates with elevated permissions by
/// prompting for UAC if required?
/// </param>
public ProxyServer(bool userTrustRootCertificate = true, bool machineTrustRootCertificate = false, public ProxyServer(bool userTrustRootCertificate = true, bool machineTrustRootCertificate = false,
bool trustRootCertificateAsAdmin = false) : this(null, null, userTrustRootCertificate, bool trustRootCertificateAsAdmin = false) : this(null, null, userTrustRootCertificate,
machineTrustRootCertificate, trustRootCertificateAsAdmin) machineTrustRootCertificate, trustRootCertificateAsAdmin)
...@@ -68,13 +75,19 @@ namespace Titanium.Web.Proxy ...@@ -68,13 +75,19 @@ namespace Titanium.Web.Proxy
} }
/// <summary> /// <summary>
/// Initializes a new instance of ProxyServer class with provided parameters. /// Initializes a new instance of ProxyServer class with provided parameters.
/// </summary> /// </summary>
/// <param name="rootCertificateName">Name of the root certificate.</param> /// <param name="rootCertificateName">Name of the root certificate.</param>
/// <param name="rootCertificateIssuerName">Name of the root certificate issuer.</param> /// <param name="rootCertificateIssuerName">Name of the root certificate issuer.</param>
/// <param name="userTrustRootCertificate">Should fake HTTPS certificate be trusted by this machine's user certificate store?</param> /// <param name="userTrustRootCertificate">
/// Should fake HTTPS certificate be trusted by this machine's user certificate
/// store?
/// </param>
/// <param name="machineTrustRootCertificate">Should fake HTTPS certificate be trusted by this machine's certificate store?</param> /// <param name="machineTrustRootCertificate">Should fake HTTPS certificate be trusted by this machine's certificate store?</param>
/// <param name="trustRootCertificateAsAdmin">Should we attempt to trust certificates with elevated permissions by prompting for UAC if required?</param> /// <param name="trustRootCertificateAsAdmin">
/// Should we attempt to trust certificates with elevated permissions by
/// prompting for UAC if required?
/// </param>
public ProxyServer(string rootCertificateName, string rootCertificateIssuerName, public ProxyServer(string rootCertificateName, string rootCertificateIssuerName,
bool userTrustRootCertificate = true, bool machineTrustRootCertificate = false, bool userTrustRootCertificate = true, bool machineTrustRootCertificate = false,
bool trustRootCertificateAsAdmin = false) bool trustRootCertificateAsAdmin = false)
...@@ -590,7 +603,7 @@ namespace Titanium.Web.Proxy ...@@ -590,7 +603,7 @@ namespace Titanium.Web.Proxy
} }
/// <summary> /// <summary>
/// Gets the system up stream proxy. /// Gets the system up stream proxy.
/// </summary> /// </summary>
private Task<ExternalProxy> GetSystemUpStreamProxy(SessionEventArgsBase sessionEventArgs) private Task<ExternalProxy> GetSystemUpStreamProxy(SessionEventArgsBase sessionEventArgs)
{ {
...@@ -599,7 +612,7 @@ namespace Titanium.Web.Proxy ...@@ -599,7 +612,7 @@ namespace Titanium.Web.Proxy
} }
/// <summary> /// <summary>
/// Act when a connection is received from client. /// Act when a connection is received from client.
/// </summary> /// </summary>
private void OnAcceptConnection(IAsyncResult asyn) private void OnAcceptConnection(IAsyncResult asyn)
{ {
......
...@@ -290,7 +290,8 @@ namespace Titanium.Web.Proxy ...@@ -290,7 +290,8 @@ namespace Titanium.Web.Proxy
if (request.ExpectContinue) if (request.ExpectContinue)
{ {
args.WebSession.SetConnection(connection); args.WebSession.SetConnection(connection);
await args.WebSession.SendRequest(Enable100ContinueBehaviour, args.IsTransparent, cancellationToken); await args.WebSession.SendRequest(Enable100ContinueBehaviour, args.IsTransparent,
cancellationToken);
} }
//If 100 continue was the response inform that to the client //If 100 continue was the response inform that to the client
...@@ -316,7 +317,8 @@ namespace Titanium.Web.Proxy ...@@ -316,7 +317,8 @@ namespace Titanium.Web.Proxy
if (!request.ExpectContinue) if (!request.ExpectContinue)
{ {
args.WebSession.SetConnection(connection); args.WebSession.SetConnection(connection);
await args.WebSession.SendRequest(Enable100ContinueBehaviour, args.IsTransparent, cancellationToken); await args.WebSession.SendRequest(Enable100ContinueBehaviour, args.IsTransparent,
cancellationToken);
} }
//check if content-length is > 0 //check if content-length is > 0
...@@ -359,7 +361,8 @@ namespace Titanium.Web.Proxy ...@@ -359,7 +361,8 @@ namespace Titanium.Web.Proxy
/// <param name="isConnect"></param> /// <param name="isConnect"></param>
/// <param name="cancellationToken"></param> /// <param name="cancellationToken"></param>
/// <returns></returns> /// <returns></returns>
private async Task<TcpConnection> GetServerConnection(SessionEventArgsBase args, bool isConnect, CancellationToken cancellationToken) private async Task<TcpConnection> GetServerConnection(SessionEventArgsBase args, bool isConnect,
CancellationToken cancellationToken)
{ {
ExternalProxy customUpStreamProxy = null; ExternalProxy customUpStreamProxy = null;
......
...@@ -118,7 +118,8 @@ namespace Titanium.Web.Proxy ...@@ -118,7 +118,8 @@ namespace Titanium.Web.Proxy
//Write body if exists //Write body if exists
if (response.HasBody) if (response.HasBody)
{ {
await args.CopyResponseBodyAsync(clientStreamWriter, TransformationMode.None, cancellationToken); await args.CopyResponseBodyAsync(clientStreamWriter, TransformationMode.None,
cancellationToken);
} }
} }
} }
......
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