Skip to content
This repository was archived by the owner on Jul 9, 2023. It is now read-only.

Commit ed0800f

Browse files
authored
Merge pull request #645 from justcoding121/master
beta
2 parents ef2019e + d8dce11 commit ed0800f

File tree

79 files changed

+770
-593
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+770
-593
lines changed

src/Titanium.Web.Proxy/CertificateHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ internal bool ValidateServerCertificate(object sender, X509Certificate certifica
5353
/// <param name="remoteCertificate">The remote certificate of server.</param>
5454
/// <param name="acceptableIssuers">The acceptable issues for client certificate as listed by server.</param>
5555
/// <returns></returns>
56-
internal X509Certificate SelectClientCertificate(object sender, string targetHost,
56+
internal X509Certificate? SelectClientCertificate(object sender, string targetHost,
5757
X509CertificateCollection localCertificates,
5858
X509Certificate remoteCertificate, string[] acceptableIssuers)
5959
{
60-
X509Certificate clientCertificate = null;
60+
X509Certificate? clientCertificate = null;
6161

6262
if (acceptableIssuers != null && acceptableIssuers.Length > 0 && localCertificates != null &&
6363
localCertificates.Count > 0)

src/Titanium.Web.Proxy/Compression/CompressionFactory.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.IO;
33
using System.IO.Compression;
4-
using Titanium.Web.Proxy.Helpers;
54
using Titanium.Web.Proxy.Http;
65

76
namespace Titanium.Web.Proxy.Compression

src/Titanium.Web.Proxy/Compression/DecompressionFactory.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.IO;
33
using System.IO.Compression;
4-
using Titanium.Web.Proxy.Helpers;
54
using Titanium.Web.Proxy.Http;
65

76
namespace Titanium.Web.Proxy.Compression

src/Titanium.Web.Proxy/EventArguments/BeforeSslAuthenticateEventArgs.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,17 @@ public class BeforeSslAuthenticateEventArgs : EventArgs
1010
{
1111
internal readonly CancellationTokenSource TaskCancellationSource;
1212

13-
internal BeforeSslAuthenticateEventArgs(CancellationTokenSource taskCancellationSource)
13+
internal BeforeSslAuthenticateEventArgs(CancellationTokenSource taskCancellationSource, string sniHostName)
1414
{
1515
TaskCancellationSource = taskCancellationSource;
16+
SniHostName = sniHostName;
1617
}
1718

1819
/// <summary>
1920
/// The server name indication hostname if available. Otherwise the generic certificate hostname of
2021
/// TransparentEndPoint.
2122
/// </summary>
22-
public string SniHostName { get; internal set; }
23+
public string SniHostName { get; }
2324

2425
/// <summary>
2526
/// Should we decrypt the SSL request?

src/Titanium.Web.Proxy/EventArguments/CertificateSelectionEventArgs.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,31 @@ public class CertificateSelectionEventArgs : EventArgs
1111
/// <summary>
1212
/// The proxy server instance.
1313
/// </summary>
14-
public object Sender { get; internal set; }
14+
public object? Sender { get; internal set; }
1515

1616
/// <summary>
1717
/// The remote hostname to which we are authenticating against.
1818
/// </summary>
19-
public string TargetHost { get; internal set; }
19+
public string? TargetHost { get; internal set; }
2020

2121
/// <summary>
2222
/// Local certificates in store with matching issuers requested by TargetHost website.
2323
/// </summary>
24-
public X509CertificateCollection LocalCertificates { get; internal set; }
24+
public X509CertificateCollection? LocalCertificates { get; internal set; }
2525

2626
/// <summary>
2727
/// Certificate of the remote server.
2828
/// </summary>
29-
public X509Certificate RemoteCertificate { get; internal set; }
29+
public X509Certificate? RemoteCertificate { get; internal set; }
3030

3131
/// <summary>
3232
/// Acceptable issuers as listed by remote server.
3333
/// </summary>
34-
public string[] AcceptableIssuers { get; internal set; }
34+
public string[]? AcceptableIssuers { get; internal set; }
3535

3636
/// <summary>
3737
/// Client Certificate we selected. Set this value to override.
3838
/// </summary>
39-
public X509Certificate ClientCertificate { get; set; }
39+
public X509Certificate? ClientCertificate { get; set; }
4040
}
4141
}

src/Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ internal SessionEventArgs(ProxyServer server, ProxyEndPoint endPoint,
4343
}
4444

4545
protected SessionEventArgs(ProxyServer server, ProxyEndPoint endPoint,
46-
Request request, CancellationTokenSource cancellationTokenSource)
46+
Request? request, CancellationTokenSource cancellationTokenSource)
4747
: base(server, endPoint, cancellationTokenSource, request)
4848
{
4949
}
@@ -70,7 +70,7 @@ public bool ReRequest
7070
/// <summary>
7171
/// Occurs when multipart request part sent.
7272
/// </summary>
73-
public event EventHandler<MultipartRequestPartSentEventArgs> MultipartRequestPartSent;
73+
public event EventHandler<MultipartRequestPartSentEventArgs>? MultipartRequestPartSent;
7474

7575
private ICustomStreamReader getStreamReader(bool isRequest)
7676
{
@@ -105,7 +105,7 @@ private async Task readRequestBodyAsync(CancellationToken cancellationToken)
105105
request.ReadHttp2BodyTaskCompletionSource = tcs;
106106

107107
// signal to HTTP/2 copy frame method to continue
108-
request.ReadHttp2BeforeHandlerTaskCompletionSource.SetResult(true);
108+
request.ReadHttp2BeforeHandlerTaskCompletionSource!.SetResult(true);
109109

110110
await tcs.Task;
111111

@@ -135,11 +135,11 @@ internal async Task ClearResponse(CancellationToken cancellationToken)
135135
HttpClient.Response = new Response();
136136
}
137137

138-
internal void OnMultipartRequestPartSent(string boundary, HeaderCollection headers)
138+
internal void OnMultipartRequestPartSent(ReadOnlySpan<char> boundary, HeaderCollection headers)
139139
{
140140
try
141141
{
142-
MultipartRequestPartSent?.Invoke(this, new MultipartRequestPartSentEventArgs(boundary, headers));
142+
MultipartRequestPartSent?.Invoke(this, new MultipartRequestPartSentEventArgs(boundary.ToString(), headers));
143143
}
144144
catch (Exception ex)
145145
{
@@ -177,7 +177,7 @@ private async Task readResponseBodyAsync(CancellationToken cancellationToken)
177177
response.ReadHttp2BodyTaskCompletionSource = tcs;
178178

179179
// signal to HTTP/2 copy frame method to continue
180-
response.ReadHttp2BeforeHandlerTaskCompletionSource.SetResult(true);
180+
response.ReadHttp2BeforeHandlerTaskCompletionSource!.SetResult(true);
181181

182182
await tcs.Task;
183183

@@ -252,7 +252,7 @@ internal async Task CopyRequestBodyAsync(HttpWriter writer, TransformationMode t
252252
if (contentLength > 0 && hasMulipartEventSubscribers && request.IsMultipartFormData)
253253
{
254254
var reader = getStreamReader(true);
255-
string boundary = HttpHelper.GetBoundaryFromContentType(request.ContentType);
255+
var boundary = HttpHelper.GetBoundaryFromContentType(request.ContentType);
256256

257257
using (var copyStream = new CopyStream(reader, writer, BufferPool))
258258
{
@@ -268,7 +268,7 @@ internal async Task CopyRequestBodyAsync(HttpWriter writer, TransformationMode t
268268
{
269269
var headers = new HeaderCollection();
270270
await HeaderParser.ReadHeaders(copyStream, headers, cancellationToken);
271-
OnMultipartRequestPartSent(boundary, headers);
271+
OnMultipartRequestPartSent(boundary.Span, headers);
272272
}
273273
}
274274

@@ -286,7 +286,7 @@ internal async Task CopyResponseBodyAsync(HttpWriter writer, TransformationMode
286286
await copyBodyAsync(false, false, writer, transformation, OnDataReceived, cancellationToken);
287287
}
288288

289-
private async Task copyBodyAsync(bool isRequest, bool useOriginalHeaderValues, HttpWriter writer, TransformationMode transformation, Action<byte[], int, int> onCopy, CancellationToken cancellationToken)
289+
private async Task copyBodyAsync(bool isRequest, bool useOriginalHeaderValues, HttpWriter writer, TransformationMode transformation, Action<byte[], int, int>? onCopy, CancellationToken cancellationToken)
290290
{
291291
var stream = getStreamReader(isRequest);
292292

@@ -302,9 +302,9 @@ private async Task copyBodyAsync(bool isRequest, bool useOriginalHeaderValues, H
302302
}
303303

304304
LimitedStream limitedStream;
305-
Stream decompressStream = null;
305+
Stream? decompressStream = null;
306306

307-
string contentEncoding = useOriginalHeaderValues ? requestResponse.OriginalContentEncoding : requestResponse.ContentEncoding;
307+
string? contentEncoding = useOriginalHeaderValues ? requestResponse.OriginalContentEncoding : requestResponse.ContentEncoding;
308308

309309
Stream s = limitedStream = new LimitedStream(stream, BufferPool, isChunked, contentLength);
310310

@@ -333,7 +333,7 @@ private async Task copyBodyAsync(bool isRequest, bool useOriginalHeaderValues, H
333333
/// Read a line from the byte stream
334334
/// </summary>
335335
/// <returns></returns>
336-
private async Task<long> readUntilBoundaryAsync(ICustomStreamReader reader, long totalBytesToRead, string boundary, CancellationToken cancellationToken)
336+
private async Task<long> readUntilBoundaryAsync(ICustomStreamReader reader, long totalBytesToRead, ReadOnlyMemory<char> boundary, CancellationToken cancellationToken)
337337
{
338338
int bufferDataLength = 0;
339339

@@ -360,7 +360,7 @@ private async Task<long> readUntilBoundaryAsync(ICustomStreamReader reader, long
360360
bool ok = true;
361361
for (int i = 0; i < boundary.Length; i++)
362362
{
363-
if (buffer[startIdx + i] != boundary[i])
363+
if (buffer[startIdx + i] != boundary.Span[i])
364364
{
365365
ok = false;
366366
break;
@@ -519,7 +519,7 @@ public void SetResponseBodyString(string body)
519519
/// <param name="html">HTML content to sent.</param>
520520
/// <param name="headers">HTTP response headers.</param>
521521
/// <param name="closeServerConnection">Close the server connection used by request if any?</param>
522-
public void Ok(string html, Dictionary<string, HttpHeader> headers = null,
522+
public void Ok(string html, Dictionary<string, HttpHeader>? headers = null,
523523
bool closeServerConnection = false)
524524
{
525525
var response = new OkResponse();
@@ -541,7 +541,7 @@ public void Ok(string html, Dictionary<string, HttpHeader> headers = null,
541541
/// <param name="result">The html content bytes.</param>
542542
/// <param name="headers">The HTTP headers.</param>
543543
/// <param name="closeServerConnection">Close the server connection used by request if any?</param>
544-
public void Ok(byte[] result, Dictionary<string, HttpHeader> headers = null,
544+
public void Ok(byte[] result, Dictionary<string, HttpHeader>? headers = null,
545545
bool closeServerConnection = false)
546546
{
547547
var response = new OkResponse();
@@ -562,7 +562,7 @@ public void Ok(byte[] result, Dictionary<string, HttpHeader> headers = null,
562562
/// <param name="headers">The HTTP headers.</param>
563563
/// <param name="closeServerConnection">Close the server connection used by request if any?</param>
564564
public void GenericResponse(string html, HttpStatusCode status,
565-
Dictionary<string, HttpHeader> headers = null, bool closeServerConnection = false)
565+
Dictionary<string, HttpHeader>? headers = null, bool closeServerConnection = false)
566566
{
567567
var response = new GenericResponse(status);
568568
response.HttpVersion = HttpClient.Request.HttpVersion;

src/Titanium.Web.Proxy/EventArguments/SessionEventArgsBase.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ private SessionEventArgsBase(ProxyServer server)
4949

5050
protected SessionEventArgsBase(ProxyServer server, ProxyEndPoint endPoint,
5151
CancellationTokenSource cancellationTokenSource,
52-
Request request) : this(server)
52+
Request? request) : this(server)
5353
{
5454
CancellationTokenSource = cancellationTokenSource;
5555

@@ -70,7 +70,7 @@ protected SessionEventArgsBase(ProxyServer server, ProxyEndPoint endPoint,
7070
/// Returns a user data for this request/response session which is
7171
/// same as the user data of HttpClient.
7272
/// </summary>
73-
public object UserData
73+
public object? UserData
7474
{
7575
get => HttpClient.UserData;
7676
set => HttpClient.UserData = value;
@@ -112,7 +112,7 @@ public bool EnableWinAuth
112112
/// <summary>
113113
/// Are we using a custom upstream HTTP(S) proxy?
114114
/// </summary>
115-
public ExternalProxy CustomUpStreamProxyUsed { get; internal set; }
115+
public ExternalProxy? CustomUpStreamProxyUsed { get; internal set; }
116116

117117
/// <summary>
118118
/// Local endpoint via which we make the request.
@@ -127,7 +127,7 @@ public bool EnableWinAuth
127127
/// <summary>
128128
/// The last exception that happened.
129129
/// </summary>
130-
public Exception Exception { get; internal set; }
130+
public Exception? Exception { get; internal set; }
131131

132132
/// <summary>
133133
/// Implements cleanup here.
@@ -146,12 +146,12 @@ public virtual void Dispose()
146146
/// <summary>
147147
/// Fired when data is sent within this session to server/client.
148148
/// </summary>
149-
public event EventHandler<DataEventArgs> DataSent;
149+
public event EventHandler<DataEventArgs>? DataSent;
150150

151151
/// <summary>
152152
/// Fired when data is received within this session from client/server.
153153
/// </summary>
154-
public event EventHandler<DataEventArgs> DataReceived;
154+
public event EventHandler<DataEventArgs>? DataReceived;
155155

156156
internal void OnDataSent(byte[] buffer, int offset, int count)
157157
{

src/Titanium.Web.Proxy/EventArguments/TunnelConnectEventArgs.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ public bool IsHttpsConnect
4545
/// <summary>
4646
/// Fired when decrypted data is sent within this session to server/client.
4747
/// </summary>
48-
public event EventHandler<DataEventArgs> DecryptedDataSent;
48+
public event EventHandler<DataEventArgs>? DecryptedDataSent;
4949

5050
/// <summary>
5151
/// Fired when decrypted data is received within this session from client/server.
5252
/// </summary>
53-
public event EventHandler<DataEventArgs> DecryptedDataReceived;
53+
public event EventHandler<DataEventArgs>? DecryptedDataReceived;
5454

5555
internal void OnDecryptedDataSent(byte[] buffer, int offset, int count)
5656
{

src/Titanium.Web.Proxy/ExceptionHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22

33
namespace Titanium.Web.Proxy
44
{

src/Titanium.Web.Proxy/Exceptions/ProxyException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ protected ProxyException(string message) : base(message)
2222
/// </summary>
2323
/// <param name="message">Exception message</param>
2424
/// <param name="innerException">Inner exception associated</param>
25-
protected ProxyException(string message, Exception innerException) : base(message, innerException)
25+
protected ProxyException(string message, Exception? innerException) : base(message, innerException)
2626
{
2727
}
2828
}

src/Titanium.Web.Proxy/Exceptions/ProxyHttpException.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class ProxyHttpException : ProxyException
1414
/// <param name="message">Message for this exception</param>
1515
/// <param name="innerException">Associated inner exception</param>
1616
/// <param name="session">Instance of <see cref="EventArguments.SessionEventArgs" /> associated to the exception</param>
17-
internal ProxyHttpException(string message, Exception innerException, SessionEventArgs session) : base(
17+
internal ProxyHttpException(string message, Exception? innerException, SessionEventArgs? session) : base(
1818
message, innerException)
1919
{
2020
Session = session;
@@ -26,6 +26,6 @@ internal ProxyHttpException(string message, Exception innerException, SessionEve
2626
/// <remarks>
2727
/// This object properties should not be edited.
2828
/// </remarks>
29-
public SessionEventArgs Session { get; }
29+
public SessionEventArgs? Session { get; }
3030
}
3131
}

0 commit comments

Comments
 (0)