Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
T
Titanium-Web-Proxy
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Titanium-Web-Proxy
Commits
d8dce115
Commit
d8dce115
authored
Oct 13, 2019
by
Honfika
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Nullable fixes
parent
8a0244ba
Hide whitespace changes
Inline
Side-by-side
Showing
26 changed files
with
80 additions
and
89 deletions
+80
-89
TunnelConnectEventArgs.cs
...tanium.Web.Proxy/EventArguments/TunnelConnectEventArgs.cs
+2
-2
ExplicitClientHandler.cs
src/Titanium.Web.Proxy/ExplicitClientHandler.cs
+3
-5
SslExtensions.cs
src/Titanium.Web.Proxy/Extensions/SslExtensions.cs
+6
-2
StreamExtensions.cs
src/Titanium.Web.Proxy/Extensions/StreamExtensions.cs
+1
-1
HttpHelper.cs
src/Titanium.Web.Proxy/Helpers/HttpHelper.cs
+8
-10
HttpWriter.cs
src/Titanium.Web.Proxy/Helpers/HttpWriter.cs
+2
-3
ProxyInfo.cs
src/Titanium.Web.Proxy/Helpers/ProxyInfo.cs
+2
-2
HeaderParser.cs
src/Titanium.Web.Proxy/Http/HeaderParser.cs
+2
-2
HttpWebClient.cs
src/Titanium.Web.Proxy/Http/HttpWebClient.cs
+5
-7
Http2Helper.cs
src/Titanium.Web.Proxy/Http2/Http2Helper.cs
+5
-0
CertificateManager.cs
src/Titanium.Web.Proxy/Network/CertificateManager.cs
+4
-5
ICertificateCache.cs
src/Titanium.Web.Proxy/Network/ICertificateCache.cs
+2
-2
RetryPolicy.cs
src/Titanium.Web.Proxy/Network/RetryPolicy.cs
+3
-5
TcpClientConnection.cs
src/Titanium.Web.Proxy/Network/Tcp/TcpClientConnection.cs
+0
-2
TcpConnectionFactory.cs
src/Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs
+5
-5
TcpServerConnection.cs
src/Titanium.Web.Proxy/Network/Tcp/TcpServerConnection.cs
+2
-4
Message.cs
src/Titanium.Web.Proxy/Network/WinAuth/Security/Message.cs
+2
-2
ProxyAuthorizationHandler.cs
src/Titanium.Web.Proxy/ProxyAuthorizationHandler.cs
+1
-1
ProxyServer.cs
src/Titanium.Web.Proxy/ProxyServer.cs
+8
-8
RequestHandler.cs
src/Titanium.Web.Proxy/RequestHandler.cs
+5
-9
CopyStream.cs
src/Titanium.Web.Proxy/StreamExtended/Network/CopyStream.cs
+2
-2
CustomBufferedPeekStream.cs
....Proxy/StreamExtended/Network/CustomBufferedPeekStream.cs
+2
-2
CustomBufferedStream.cs
....Web.Proxy/StreamExtended/Network/CustomBufferedStream.cs
+4
-4
ICustomStreamReader.cs
...m.Web.Proxy/StreamExtended/Network/ICustomStreamReader.cs
+2
-2
Titanium.Web.Proxy.csproj
src/Titanium.Web.Proxy/Titanium.Web.Proxy.csproj
+1
-0
WinAuthHandler.cs
src/Titanium.Web.Proxy/WinAuthHandler.cs
+1
-2
No files found.
src/Titanium.Web.Proxy/EventArguments/TunnelConnectEventArgs.cs
View file @
d8dce115
...
@@ -45,12 +45,12 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -45,12 +45,12 @@ namespace Titanium.Web.Proxy.EventArguments
/// <summary>
/// <summary>
/// Fired when decrypted data is sent within this session to server/client.
/// Fired when decrypted data is sent within this session to server/client.
/// </summary>
/// </summary>
public
event
EventHandler
<
DataEventArgs
>
DecryptedDataSent
;
public
event
EventHandler
<
DataEventArgs
>
?
DecryptedDataSent
;
/// <summary>
/// <summary>
/// Fired when decrypted data is received within this session from client/server.
/// Fired when decrypted data is received within this session from client/server.
/// </summary>
/// </summary>
public
event
EventHandler
<
DataEventArgs
>
DecryptedDataReceived
;
public
event
EventHandler
<
DataEventArgs
>
?
DecryptedDataReceived
;
internal
void
OnDecryptedDataSent
(
byte
[]
buffer
,
int
offset
,
int
count
)
internal
void
OnDecryptedDataSent
(
byte
[]
buffer
,
int
offset
,
int
count
)
{
{
...
...
src/Titanium.Web.Proxy/ExplicitClientHandler.cs
View file @
d8dce115
...
@@ -309,7 +309,7 @@ namespace Titanium.Web.Proxy
...
@@ -309,7 +309,7 @@ namespace Titanium.Web.Proxy
connectArgs
.
HttpClient
.
ConnectRequest
!.
TunnelType
=
TunnelType
.
Http2
;
connectArgs
.
HttpClient
.
ConnectRequest
!.
TunnelType
=
TunnelType
.
Http2
;
// HTTP/2 Connection Preface
// HTTP/2 Connection Preface
string
line
=
await
clientStream
.
ReadLineAsync
(
cancellationToken
);
string
?
line
=
await
clientStream
.
ReadLineAsync
(
cancellationToken
);
if
(
line
!=
string
.
Empty
)
if
(
line
!=
string
.
Empty
)
{
{
throw
new
Exception
(
$"HTTP/2 Protocol violation. Empty string expected, '
{
line
}
' received"
);
throw
new
Exception
(
$"HTTP/2 Protocol violation. Empty string expected, '
{
line
}
' received"
);
...
@@ -332,11 +332,9 @@ namespace Titanium.Web.Proxy
...
@@ -332,11 +332,9 @@ namespace Titanium.Web.Proxy
noCache
:
true
,
cancellationToken
:
cancellationToken
);
noCache
:
true
,
cancellationToken
:
cancellationToken
);
try
try
{
{
await
connection
.
StreamWriter
.
WriteLineAsync
(
"PRI * HTTP/2.0"
,
cancellationToken
);
await
connection
.
StreamWriter
.
WriteLineAsync
(
cancellationToken
);
await
connection
.
StreamWriter
.
WriteLineAsync
(
"SM"
,
cancellationToken
);
await
connection
.
StreamWriter
.
WriteLineAsync
(
cancellationToken
);
#if NETSTANDARD2_1
#if NETSTANDARD2_1
var
connectionPreface
=
new
ReadOnlyMemory
<
byte
>(
Http2Helper
.
ConnectionPreface
);
await
connection
.
StreamWriter
.
WriteAsync
(
connectionPreface
,
cancellationToken
);
await
Http2Helper
.
SendHttp2
(
clientStream
,
connection
.
Stream
,
await
Http2Helper
.
SendHttp2
(
clientStream
,
connection
.
Stream
,
()
=>
new
SessionEventArgs
(
this
,
endPoint
,
cancellationTokenSource
)
()
=>
new
SessionEventArgs
(
this
,
endPoint
,
cancellationTokenSource
)
{
{
...
...
src/Titanium.Web.Proxy/Extensions/SslExtensions.cs
View file @
d8dce115
...
@@ -77,15 +77,19 @@ namespace Titanium.Web.Proxy.Extensions
...
@@ -77,15 +77,19 @@ namespace Titanium.Web.Proxy.Extensions
}
}
#endif
#endif
}
}
}
#if !NETSTANDARD2_1
#if !NETSTANDARD2_1
namespace
System.Net.Security
{
internal
enum
SslApplicationProtocol
internal
enum
SslApplicationProtocol
{
{
Http11
,
Http11
,
Http2
Http2
}
}
[
SuppressMessage
(
"StyleCop.CSharp.MaintainabilityRules"
,
"SA1402:FileMayOnlyContainASingleType"
,
Justification
=
"Reviewed."
)]
[
SuppressMessage
(
"StyleCop.CSharp.MaintainabilityRules"
,
"SA1402:FileMayOnlyContainASingleType"
,
Justification
=
"Reviewed."
)]
internal
class
SslClientAuthenticationOptions
internal
class
SslClientAuthenticationOptions
{
{
internal
bool
AllowRenegotiation
{
get
;
set
;
}
internal
bool
AllowRenegotiation
{
get
;
set
;
}
...
@@ -125,5 +129,5 @@ namespace Titanium.Web.Proxy.Extensions
...
@@ -125,5 +129,5 @@ namespace Titanium.Web.Proxy.Extensions
internal
EncryptionPolicy
EncryptionPolicy
{
get
;
set
;
}
internal
EncryptionPolicy
EncryptionPolicy
{
get
;
set
;
}
}
}
#endif
}
}
#endif
src/Titanium.Web.Proxy/Extensions/StreamExtensions.cs
View file @
d8dce115
...
@@ -32,7 +32,7 @@ namespace Titanium.Web.Proxy.Extensions
...
@@ -32,7 +32,7 @@ namespace Titanium.Web.Proxy.Extensions
/// <param name="onCopy"></param>
/// <param name="onCopy"></param>
/// <param name="bufferPool"></param>
/// <param name="bufferPool"></param>
/// <param name="cancellationToken"></param>
/// <param name="cancellationToken"></param>
internal
static
async
Task
CopyToAsync
(
this
Stream
input
,
Stream
output
,
Action
<
byte
[],
int
,
int
>
onCopy
,
internal
static
async
Task
CopyToAsync
(
this
Stream
input
,
Stream
output
,
Action
<
byte
[],
int
,
int
>
?
onCopy
,
IBufferPool
bufferPool
,
CancellationToken
cancellationToken
)
IBufferPool
bufferPool
,
CancellationToken
cancellationToken
)
{
{
var
buffer
=
bufferPool
.
GetBuffer
();
var
buffer
=
bufferPool
.
GetBuffer
();
...
...
src/Titanium.Web.Proxy/Helpers/HttpHelper.cs
View file @
d8dce115
...
@@ -66,7 +66,7 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -66,7 +66,7 @@ namespace Titanium.Web.Proxy.Helpers
/// </summary>
/// </summary>
/// <param name="contentType"></param>
/// <param name="contentType"></param>
/// <returns></returns>
/// <returns></returns>
internal
static
Encoding
GetEncodingFromContentType
(
string
contentType
)
internal
static
Encoding
GetEncodingFromContentType
(
string
?
contentType
)
{
{
try
try
{
{
...
@@ -108,7 +108,7 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -108,7 +108,7 @@ namespace Titanium.Web.Proxy.Helpers
return
defaultEncoding
;
return
defaultEncoding
;
}
}
internal
static
ReadOnlyMemory
<
char
>
GetBoundaryFromContentType
(
string
contentType
)
internal
static
ReadOnlyMemory
<
char
>
GetBoundaryFromContentType
(
string
?
contentType
)
{
{
if
(
contentType
!=
null
)
if
(
contentType
!=
null
)
{
{
...
@@ -196,16 +196,14 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -196,16 +196,14 @@ namespace Titanium.Web.Proxy.Helpers
private
static
async
Task
<
int
>
startsWith
(
ICustomStreamReader
clientStreamReader
,
IBufferPool
bufferPool
,
string
expectedStart
,
CancellationToken
cancellationToken
=
default
)
private
static
async
Task
<
int
>
startsWith
(
ICustomStreamReader
clientStreamReader
,
IBufferPool
bufferPool
,
string
expectedStart
,
CancellationToken
cancellationToken
=
default
)
{
{
const
int
lengthToCheck
=
10
;
const
int
lengthToCheck
=
10
;
byte
[]?
buffer
=
null
;
if
(
bufferPool
.
BufferSize
<
lengthToCheck
)
try
{
{
if
(
bufferPool
.
BufferSize
<
lengthToCheck
)
throw
new
Exception
(
$"Buffer is too small. Minimum size is
{
lengthToCheck
}
bytes"
);
{
}
throw
new
Exception
(
$"Buffer is too small. Minimum size is
{
lengthToCheck
}
bytes"
);
}
buffer
=
bufferPool
.
GetBuffer
(
bufferPool
.
BufferSize
);
byte
[]
buffer
=
bufferPool
.
GetBuffer
(
bufferPool
.
BufferSize
);
try
{
bool
isExpected
=
true
;
bool
isExpected
=
true
;
int
i
=
0
;
int
i
=
0
;
while
(
i
<
lengthToCheck
)
while
(
i
<
lengthToCheck
)
...
...
src/Titanium.Web.Proxy/Helpers/HttpWriter.cs
View file @
d8dce115
...
@@ -192,8 +192,7 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -192,8 +192,7 @@ 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
(
ICustomStreamReader
reader
,
Action
<
byte
[],
int
,
int
>
onCopy
,
private
async
Task
copyBodyChunkedAsync
(
ICustomStreamReader
reader
,
Action
<
byte
[],
int
,
int
>?
onCopy
,
CancellationToken
cancellationToken
)
CancellationToken
cancellationToken
)
{
{
while
(
true
)
while
(
true
)
{
{
...
@@ -233,7 +232,7 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -233,7 +232,7 @@ 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
(
ICustomStreamReader
reader
,
long
count
,
Action
<
byte
[],
int
,
int
>
onCopy
,
private
async
Task
copyBytesFromStream
(
ICustomStreamReader
reader
,
long
count
,
Action
<
byte
[],
int
,
int
>
?
onCopy
,
CancellationToken
cancellationToken
)
CancellationToken
cancellationToken
)
{
{
var
buffer
=
bufferPool
.
GetBuffer
();
var
buffer
=
bufferPool
.
GetBuffer
();
...
...
src/Titanium.Web.Proxy/Helpers/ProxyInfo.cs
View file @
d8dce115
...
@@ -158,7 +158,7 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -158,7 +158,7 @@ namespace Titanium.Web.Proxy.Helpers
/// </summary>
/// </summary>
/// <param name="proxyServerValues"></param>
/// <param name="proxyServerValues"></param>
/// <returns></returns>
/// <returns></returns>
internal
static
List
<
HttpSystemProxyValue
>
GetSystemProxyValues
(
string
proxyServerValues
)
internal
static
List
<
HttpSystemProxyValue
>
GetSystemProxyValues
(
string
?
proxyServerValues
)
{
{
var
result
=
new
List
<
HttpSystemProxyValue
>();
var
result
=
new
List
<
HttpSystemProxyValue
>();
...
@@ -167,7 +167,7 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -167,7 +167,7 @@ namespace Titanium.Web.Proxy.Helpers
return
result
;
return
result
;
}
}
var
proxyValues
=
proxyServerValues
.
Split
(
';'
);
var
proxyValues
=
proxyServerValues
!
.
Split
(
';'
);
if
(
proxyValues
.
Length
>
0
)
if
(
proxyValues
.
Length
>
0
)
{
{
...
...
src/Titanium.Web.Proxy/Http/HeaderParser.cs
View file @
d8dce115
...
@@ -10,10 +10,10 @@ namespace Titanium.Web.Proxy.Http
...
@@ -10,10 +10,10 @@ namespace Titanium.Web.Proxy.Http
internal
static
async
Task
ReadHeaders
(
ICustomStreamReader
reader
,
HeaderCollection
headerCollection
,
internal
static
async
Task
ReadHeaders
(
ICustomStreamReader
reader
,
HeaderCollection
headerCollection
,
CancellationToken
cancellationToken
)
CancellationToken
cancellationToken
)
{
{
string
tmpLine
;
string
?
tmpLine
;
while
(!
string
.
IsNullOrEmpty
(
tmpLine
=
await
reader
.
ReadLineAsync
(
cancellationToken
)))
while
(!
string
.
IsNullOrEmpty
(
tmpLine
=
await
reader
.
ReadLineAsync
(
cancellationToken
)))
{
{
int
colonIndex
=
tmpLine
.
IndexOf
(
':'
);
int
colonIndex
=
tmpLine
!
.
IndexOf
(
':'
);
if
(
colonIndex
==
-
1
)
if
(
colonIndex
==
-
1
)
{
{
throw
new
Exception
(
"Header line should contain a colon character."
);
throw
new
Exception
(
"Header line should contain a colon character."
);
...
...
src/Titanium.Web.Proxy/Http/HttpWebClient.cs
View file @
d8dce115
...
@@ -60,7 +60,7 @@ namespace Titanium.Web.Proxy.Http
...
@@ -60,7 +60,7 @@ namespace Titanium.Web.Proxy.Http
/// <summary>
/// <summary>
/// Override UpStreamEndPoint for this request; Local NIC via request is made
/// Override UpStreamEndPoint for this request; Local NIC via request is made
/// </summary>
/// </summary>
public
IPEndPoint
UpStreamEndPoint
{
get
;
set
;
}
public
IPEndPoint
?
UpStreamEndPoint
{
get
;
set
;
}
/// <summary>
/// <summary>
/// Headers passed with Connect.
/// Headers passed with Connect.
...
@@ -182,11 +182,8 @@ namespace Titanium.Web.Proxy.Http
...
@@ -182,11 +182,8 @@ namespace Titanium.Web.Proxy.Http
string
httpStatus
;
string
httpStatus
;
try
try
{
{
httpStatus
=
await
Connection
.
Stream
.
ReadLineAsync
(
cancellationToken
);
httpStatus
=
await
Connection
.
Stream
.
ReadLineAsync
(
cancellationToken
)
??
if
(
httpStatus
==
null
)
throw
new
ServerConnectionException
(
"Server connection was closed."
);
{
throw
new
ServerConnectionException
(
"Server connection was closed."
);
}
}
}
catch
(
Exception
e
)
when
(!(
e
is
ServerConnectionException
))
catch
(
Exception
e
)
when
(!(
e
is
ServerConnectionException
))
{
{
...
@@ -195,7 +192,8 @@ namespace Titanium.Web.Proxy.Http
...
@@ -195,7 +192,8 @@ namespace Titanium.Web.Proxy.Http
if
(
httpStatus
==
string
.
Empty
)
if
(
httpStatus
==
string
.
Empty
)
{
{
httpStatus
=
await
Connection
.
Stream
.
ReadLineAsync
(
cancellationToken
);
httpStatus
=
await
Connection
.
Stream
.
ReadLineAsync
(
cancellationToken
)
??
throw
new
ServerConnectionException
(
"Server connection was closed."
);
}
}
Response
.
ParseResponseLine
(
httpStatus
,
out
var
version
,
out
int
statusCode
,
out
string
statusDescription
);
Response
.
ParseResponseLine
(
httpStatus
,
out
var
version
,
out
int
statusCode
,
out
string
statusDescription
);
...
...
src/Titanium.Web.Proxy/Http2/Http2Helper.cs
View file @
d8dce115
...
@@ -5,6 +5,7 @@ using System.Collections.Generic;
...
@@ -5,6 +5,7 @@ using System.Collections.Generic;
using
System.Diagnostics
;
using
System.Diagnostics
;
using
System.IO
;
using
System.IO
;
using
System.Net
;
using
System.Net
;
using
System.Text
;
using
System.Threading
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
using
Titanium.Web.Proxy.Compression
;
using
Titanium.Web.Proxy.Compression
;
...
@@ -12,11 +13,15 @@ using Titanium.Web.Proxy.EventArguments;
...
@@ -12,11 +13,15 @@ using Titanium.Web.Proxy.EventArguments;
using
Titanium.Web.Proxy.Exceptions
;
using
Titanium.Web.Proxy.Exceptions
;
using
Titanium.Web.Proxy.Http
;
using
Titanium.Web.Proxy.Http
;
using
Titanium.Web.Proxy.Http2.Hpack
;
using
Titanium.Web.Proxy.Http2.Hpack
;
using
Decoder
=
Titanium
.
Web
.
Proxy
.
Http2
.
Hpack
.
Decoder
;
using
Encoder
=
Titanium
.
Web
.
Proxy
.
Http2
.
Hpack
.
Encoder
;
namespace
Titanium.Web.Proxy.Http2
namespace
Titanium.Web.Proxy.Http2
{
{
internal
class
Http2Helper
internal
class
Http2Helper
{
{
public
static
readonly
byte
[]
ConnectionPreface
=
Encoding
.
ASCII
.
GetBytes
(
"PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n"
);
/// <summary>
/// <summary>
/// relays the input clientStream to the server at the specified host name and port with the given httpCmd and headers
/// relays the input clientStream to the server at the specified host name and port with the given httpCmd and headers
/// as prefix
/// as prefix
...
...
src/Titanium.Web.Proxy/Network/CertificateManager.cs
View file @
d8dce115
...
@@ -52,8 +52,8 @@ namespace Titanium.Web.Proxy.Network
...
@@ -52,8 +52,8 @@ namespace Titanium.Web.Proxy.Network
/// Useful to prevent multiple threads working on same certificate generation
/// Useful to prevent multiple threads working on same certificate generation
/// when burst certificate generation requests happen for same certificate.
/// when burst certificate generation requests happen for same certificate.
/// </summary>
/// </summary>
private
readonly
ConcurrentDictionary
<
string
,
Task
<
X509Certificate2
>>
pendingCertificateCreationTasks
private
readonly
ConcurrentDictionary
<
string
,
Task
<
X509Certificate2
?
>>
pendingCertificateCreationTasks
=
new
ConcurrentDictionary
<
string
,
Task
<
X509Certificate2
>>();
=
new
ConcurrentDictionary
<
string
,
Task
<
X509Certificate2
?
>>();
private
readonly
CancellationTokenSource
clearCertificatesTokenSource
private
readonly
CancellationTokenSource
clearCertificatesTokenSource
=
new
CancellationTokenSource
();
=
new
CancellationTokenSource
();
...
@@ -334,8 +334,7 @@ namespace Titanium.Web.Proxy.Network
...
@@ -334,8 +334,7 @@ namespace Titanium.Web.Proxy.Network
/// <param name="storeName"></param>
/// <param name="storeName"></param>
/// <param name="storeLocation"></param>
/// <param name="storeLocation"></param>
/// <param name="certificate"></param>
/// <param name="certificate"></param>
private
void
uninstallCertificate
(
StoreName
storeName
,
StoreLocation
storeLocation
,
private
void
uninstallCertificate
(
StoreName
storeName
,
StoreLocation
storeLocation
,
X509Certificate2
?
certificate
)
X509Certificate2
certificate
)
{
{
if
(
certificate
==
null
)
if
(
certificate
==
null
)
{
{
...
@@ -447,7 +446,7 @@ namespace Titanium.Web.Proxy.Network
...
@@ -447,7 +446,7 @@ namespace Titanium.Web.Proxy.Network
/// </summary>
/// </summary>
/// <param name="certificateName"></param>
/// <param name="certificateName"></param>
/// <returns></returns>
/// <returns></returns>
public
async
Task
<
X509Certificate2
>
CreateServerCertificate
(
string
certificateName
)
public
async
Task
<
X509Certificate2
?
>
CreateServerCertificate
(
string
certificateName
)
{
{
// check in cache first
// check in cache first
if
(
cachedCertificates
.
TryGetValue
(
certificateName
,
out
var
cached
))
if
(
cachedCertificates
.
TryGetValue
(
certificateName
,
out
var
cached
))
...
...
src/Titanium.Web.Proxy/Network/ICertificateCache.cs
View file @
d8dce115
...
@@ -7,7 +7,7 @@ namespace Titanium.Web.Proxy.Network
...
@@ -7,7 +7,7 @@ namespace Titanium.Web.Proxy.Network
/// <summary>
/// <summary>
/// Loads the root certificate from the storage.
/// Loads the root certificate from the storage.
/// </summary>
/// </summary>
X509Certificate2
LoadRootCertificate
(
string
pathOrName
,
string
password
,
X509KeyStorageFlags
storageFlags
);
X509Certificate2
?
LoadRootCertificate
(
string
pathOrName
,
string
password
,
X509KeyStorageFlags
storageFlags
);
/// <summary>
/// <summary>
/// Saves the root certificate to the storage.
/// Saves the root certificate to the storage.
...
@@ -17,7 +17,7 @@ namespace Titanium.Web.Proxy.Network
...
@@ -17,7 +17,7 @@ namespace Titanium.Web.Proxy.Network
/// <summary>
/// <summary>
/// Loads certificate from the storage. Returns true if certificate does not exist.
/// Loads certificate from the storage. Returns true if certificate does not exist.
/// </summary>
/// </summary>
X509Certificate2
LoadCertificate
(
string
subjectName
,
X509KeyStorageFlags
storageFlags
);
X509Certificate2
?
LoadCertificate
(
string
subjectName
,
X509KeyStorageFlags
storageFlags
);
/// <summary>
/// <summary>
/// Stores certificate into the storage.
/// Stores certificate into the storage.
...
...
src/Titanium.Web.Proxy/Network/RetryPolicy.cs
View file @
d8dce115
...
@@ -25,7 +25,7 @@ namespace Titanium.Web.Proxy.Network
...
@@ -25,7 +25,7 @@ namespace Titanium.Web.Proxy.Network
/// <param name="initialConnection">Initial Tcp connection to use.</param>
/// <param name="initialConnection">Initial Tcp connection to use.</param>
/// <returns>Returns the latest connection used and the latest exception if any.</returns>
/// <returns>Returns the latest connection used and the latest exception if any.</returns>
internal
async
Task
<
RetryResult
>
ExecuteAsync
(
Func
<
TcpServerConnection
,
Task
<
bool
>>
action
,
internal
async
Task
<
RetryResult
>
ExecuteAsync
(
Func
<
TcpServerConnection
,
Task
<
bool
>>
action
,
Func
<
Task
<
TcpServerConnection
>>
generator
,
TcpServerConnection
initialConnection
)
Func
<
Task
<
TcpServerConnection
>>
generator
,
TcpServerConnection
?
initialConnection
)
{
{
currentConnection
=
initialConnection
;
currentConnection
=
initialConnection
;
bool
@continue
=
true
;
bool
@continue
=
true
;
...
@@ -79,15 +79,13 @@ namespace Titanium.Web.Proxy.Network
...
@@ -79,15 +79,13 @@ namespace Titanium.Web.Proxy.Network
internal
class
RetryResult
internal
class
RetryResult
{
{
internal
bool
IsSuccess
=>
Exception
==
null
;
internal
TcpServerConnection
?
LatestConnection
{
get
;
}
internal
TcpServerConnection
LatestConnection
{
get
;
}
internal
Exception
?
Exception
{
get
;
}
internal
Exception
?
Exception
{
get
;
}
internal
bool
Continue
{
get
;
}
internal
bool
Continue
{
get
;
}
internal
RetryResult
(
TcpServerConnection
lastConnection
,
Exception
?
exception
,
bool
@continue
)
internal
RetryResult
(
TcpServerConnection
?
lastConnection
,
Exception
?
exception
,
bool
@continue
)
{
{
LatestConnection
=
lastConnection
;
LatestConnection
=
lastConnection
;
Exception
=
exception
;
Exception
=
exception
;
...
...
src/Titanium.Web.Proxy/Network/Tcp/TcpClientConnection.cs
View file @
d8dce115
using
System
;
using
System
;
using
System.IO
;
using
System.IO
;
using
System.Net
;
using
System.Net
;
#if NETSTANDARD2_1
using
System.Net.Security
;
using
System.Net.Security
;
#endif
using
System.Net.Sockets
;
using
System.Net.Sockets
;
using
System.Security.Authentication
;
using
System.Security.Authentication
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
...
...
src/Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs
View file @
d8dce115
...
@@ -48,7 +48,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
...
@@ -48,7 +48,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
internal
string
GetConnectionCacheKey
(
string
remoteHostName
,
int
remotePort
,
internal
string
GetConnectionCacheKey
(
string
remoteHostName
,
int
remotePort
,
bool
isHttps
,
List
<
SslApplicationProtocol
>?
applicationProtocols
,
bool
isHttps
,
List
<
SslApplicationProtocol
>?
applicationProtocols
,
IPEndPoint
upStreamEndPoint
,
ExternalProxy
externalProxy
)
IPEndPoint
upStreamEndPoint
,
ExternalProxy
?
externalProxy
)
{
{
// http version is ignored since its an application level decision b/w HTTP 1.0/1.1
// http version is ignored since its an application level decision b/w HTTP 1.0/1.1
// also when doing connect request MS Edge browser sends http 1.0 but uses 1.1 after server sends 1.1 its response.
// also when doing connect request MS Edge browser sends http 1.0 but uses 1.1 after server sends 1.1 its response.
...
@@ -180,7 +180,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
...
@@ -180,7 +180,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
/// <returns></returns>
/// <returns></returns>
internal
async
Task
<
TcpServerConnection
>
GetServerConnection
(
string
remoteHostName
,
int
remotePort
,
internal
async
Task
<
TcpServerConnection
>
GetServerConnection
(
string
remoteHostName
,
int
remotePort
,
Version
httpVersion
,
bool
isHttps
,
List
<
SslApplicationProtocol
>?
applicationProtocols
,
bool
isConnect
,
Version
httpVersion
,
bool
isHttps
,
List
<
SslApplicationProtocol
>?
applicationProtocols
,
bool
isConnect
,
ProxyServer
proxyServer
,
SessionEventArgsBase
?
session
,
IPEndPoint
upStreamEndPoint
,
ExternalProxy
externalProxy
,
ProxyServer
proxyServer
,
SessionEventArgsBase
?
session
,
IPEndPoint
upStreamEndPoint
,
ExternalProxy
?
externalProxy
,
bool
noCache
,
CancellationToken
cancellationToken
)
bool
noCache
,
CancellationToken
cancellationToken
)
{
{
var
sslProtocol
=
session
?.
ProxyClient
.
Connection
.
SslProtocol
??
SslProtocols
.
None
;
var
sslProtocol
=
session
?.
ProxyClient
.
Connection
.
SslProtocol
??
SslProtocols
.
None
;
...
@@ -234,8 +234,8 @@ namespace Titanium.Web.Proxy.Network.Tcp
...
@@ -234,8 +234,8 @@ namespace Titanium.Web.Proxy.Network.Tcp
/// <param name="cancellationToken">The cancellation token for this async task.</param>
/// <param name="cancellationToken">The cancellation token for this async task.</param>
/// <returns></returns>
/// <returns></returns>
private
async
Task
<
TcpServerConnection
>
createServerConnection
(
string
remoteHostName
,
int
remotePort
,
private
async
Task
<
TcpServerConnection
>
createServerConnection
(
string
remoteHostName
,
int
remotePort
,
Version
httpVersion
,
bool
isHttps
,
SslProtocols
sslProtocol
,
List
<
SslApplicationProtocol
>
applicationProtocols
,
bool
isConnect
,
Version
httpVersion
,
bool
isHttps
,
SslProtocols
sslProtocol
,
List
<
SslApplicationProtocol
>
?
applicationProtocols
,
bool
isConnect
,
ProxyServer
proxyServer
,
SessionEventArgsBase
session
,
IPEndPoint
upStreamEndPoint
,
ExternalProxy
externalProxy
,
ProxyServer
proxyServer
,
SessionEventArgsBase
?
session
,
IPEndPoint
upStreamEndPoint
,
ExternalProxy
?
externalProxy
,
CancellationToken
cancellationToken
)
CancellationToken
cancellationToken
)
{
{
// deny connection to proxy end points to avoid infinite connection loop.
// deny connection to proxy end points to avoid infinite connection loop.
...
@@ -482,7 +482,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
...
@@ -482,7 +482,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
}
}
}
}
internal
async
Task
Release
(
Task
<
TcpServerConnection
>
connectionCreateTask
,
bool
closeServerConnection
)
internal
async
Task
Release
(
Task
<
TcpServerConnection
>
?
connectionCreateTask
,
bool
closeServerConnection
)
{
{
if
(
connectionCreateTask
!=
null
)
if
(
connectionCreateTask
!=
null
)
{
{
...
...
src/Titanium.Web.Proxy/Network/Tcp/TcpServerConnection.cs
View file @
d8dce115
using
System
;
using
System
;
using
System.Net
;
using
System.Net
;
#if NETSTANDARD2_1
using
System.Net.Security
;
using
System.Net.Security
;
#endif
using
System.Net.Sockets
;
using
System.Net.Sockets
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
using
Titanium.Web.Proxy.Extensions
;
using
Titanium.Web.Proxy.Extensions
;
...
@@ -49,7 +47,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
...
@@ -49,7 +47,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
/// <summary>
/// <summary>
/// Http version
/// Http version
/// </summary>
/// </summary>
internal
Version
Version
{
get
;
set
;
}
internal
Version
Version
{
get
;
set
;
}
=
HttpHeader
.
VersionUnknown
;
private
readonly
TcpClient
tcpClient
;
private
readonly
TcpClient
tcpClient
;
...
@@ -66,7 +64,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
...
@@ -66,7 +64,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
/// <summary>
/// <summary>
/// Server stream
/// Server stream
/// </summary>
/// </summary>
internal
CustomBufferedStream
Stream
{
get
;
set
;
}
internal
CustomBufferedStream
?
Stream
{
get
;
set
;
}
/// <summary>
/// <summary>
/// Last time this connection was used
/// Last time this connection was used
...
...
src/Titanium.Web.Proxy/Network/WinAuth/Security/Message.cs
View file @
d8dce115
//
//
// Nancy.Authentication.Ntlm.Protocol.Type3Message - Authentication
// Nancy.Authentication.Ntlm.Protocol.Type3Message - Authentication
//
//
// Author:
// Author:
...
@@ -58,7 +58,7 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
...
@@ -58,7 +58,7 @@ namespace Titanium.Web.Proxy.Network.WinAuth.Security
/// <summary>
/// <summary>
/// Username
/// Username
/// </summary>
/// </summary>
internal
string
Username
{
get
;
private
set
;
}
internal
string
?
Username
{
get
;
private
set
;
}
internal
Common
.
NtlmFlags
Flags
{
get
;
set
;
}
internal
Common
.
NtlmFlags
Flags
{
get
;
set
;
}
...
...
src/Titanium.Web.Proxy/ProxyAuthorizationHandler.cs
View file @
d8dce115
...
@@ -128,7 +128,7 @@ namespace Titanium.Web.Proxy
...
@@ -128,7 +128,7 @@ namespace Titanium.Web.Proxy
if
(!
string
.
IsNullOrWhiteSpace
(
continuation
))
if
(!
string
.
IsNullOrWhiteSpace
(
continuation
))
{
{
return
createContinuationResponse
(
response
,
continuation
);
return
createContinuationResponse
(
response
,
continuation
!
);
}
}
if
(
ProxyBasicAuthenticateFunc
!=
null
)
if
(
ProxyBasicAuthenticateFunc
!=
null
)
...
...
src/Titanium.Web.Proxy/ProxyServer.cs
View file @
d8dce115
...
@@ -115,7 +115,7 @@ namespace Titanium.Web.Proxy
...
@@ -115,7 +115,7 @@ namespace Titanium.Web.Proxy
/// <summary>
/// <summary>
/// Manage system proxy settings.
/// Manage system proxy settings.
/// </summary>
/// </summary>
private
SystemProxyManager
systemProxySettingsManager
{
get
;
}
private
SystemProxyManager
?
systemProxySettingsManager
{
get
;
}
/// <summary>
/// <summary>
/// Number of exception retries when connection pool is enabled.
/// Number of exception retries when connection pool is enabled.
...
@@ -249,18 +249,18 @@ namespace Titanium.Web.Proxy
...
@@ -249,18 +249,18 @@ namespace Titanium.Web.Proxy
/// <summary>
/// <summary>
/// External proxy used for Http requests.
/// External proxy used for Http requests.
/// </summary>
/// </summary>
public
ExternalProxy
UpStreamHttpProxy
{
get
;
set
;
}
public
ExternalProxy
?
UpStreamHttpProxy
{
get
;
set
;
}
/// <summary>
/// <summary>
/// External proxy used for Https requests.
/// External proxy used for Https requests.
/// </summary>
/// </summary>
public
ExternalProxy
UpStreamHttpsProxy
{
get
;
set
;
}
public
ExternalProxy
?
UpStreamHttpsProxy
{
get
;
set
;
}
/// <summary>
/// <summary>
/// Local adapter/NIC endpoint where proxy makes request via.
/// Local adapter/NIC endpoint where proxy makes request via.
/// Defaults via any IP addresses of this machine.
/// Defaults via any IP addresses of this machine.
/// </summary>
/// </summary>
public
IPEndPoint
UpStreamEndPoint
{
get
;
set
;
}
public
IPEndPoint
?
UpStreamEndPoint
{
get
;
set
;
}
/// <summary>
/// <summary>
/// A list of IpAddress and port this proxy is listening to.
/// A list of IpAddress and port this proxy is listening to.
...
@@ -271,7 +271,7 @@ namespace Titanium.Web.Proxy
...
@@ -271,7 +271,7 @@ namespace Titanium.Web.Proxy
/// A callback to provide authentication credentials for up stream proxy this proxy is using for HTTP(S) requests.
/// A callback to provide authentication credentials for up stream proxy this proxy is using for HTTP(S) requests.
/// User should return the ExternalProxy object with valid credentials.
/// User should return the ExternalProxy object with valid credentials.
/// </summary>
/// </summary>
public
Func
<
SessionEventArgsBase
,
Task
<
ExternalProxy
>>
GetCustomUpStreamProxyFunc
{
get
;
set
;
}
public
Func
<
SessionEventArgsBase
,
Task
<
ExternalProxy
?>>?
GetCustomUpStreamProxyFunc
{
get
;
set
;
}
/// <summary>
/// <summary>
/// Callback for error events in this proxy instance.
/// Callback for error events in this proxy instance.
...
@@ -344,12 +344,12 @@ namespace Titanium.Web.Proxy
...
@@ -344,12 +344,12 @@ namespace Titanium.Web.Proxy
/// <summary>
/// <summary>
/// Customize TcpClient used for client connection upon create.
/// Customize TcpClient used for client connection upon create.
/// </summary>
/// </summary>
public
event
AsyncEventHandler
<
TcpClient
>
OnClientConnectionCreate
;
public
event
AsyncEventHandler
<
TcpClient
>
?
OnClientConnectionCreate
;
/// <summary>
/// <summary>
/// Customize TcpClient used for server connection upon create.
/// Customize TcpClient used for server connection upon create.
/// </summary>
/// </summary>
public
event
AsyncEventHandler
<
TcpClient
>
OnServerConnectionCreate
;
public
event
AsyncEventHandler
<
TcpClient
>
?
OnServerConnectionCreate
;
/// <summary>
/// <summary>
/// Customize the minimum ThreadPool size (increase it on a server)
/// Customize the minimum ThreadPool size (increase it on a server)
...
@@ -706,7 +706,7 @@ namespace Titanium.Web.Proxy
...
@@ -706,7 +706,7 @@ namespace Titanium.Web.Proxy
/// </summary>
/// </summary>
/// <param name="sessionEventArgs">The session.</param>
/// <param name="sessionEventArgs">The session.</param>
/// <returns>The external proxy as task result.</returns>
/// <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
.
HttpClient
.
Request
.
RequestUri
);
var
proxy
=
systemProxyResolver
.
GetProxy
(
sessionEventArgs
.
HttpClient
.
Request
.
RequestUri
);
return
Task
.
FromResult
(
proxy
);
return
Task
.
FromResult
(
proxy
);
...
...
src/Titanium.Web.Proxy/RequestHandler.cs
View file @
d8dce115
using
System
;
using
System
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Linq
;
using
System.Net.Sockets
;
#if NETSTANDARD2_1
using
System.Net.Security
;
using
System.Net.Security
;
#endif
using
System.Net.Sockets
;
using
System.Threading
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
using
Titanium.Web.Proxy.EventArguments
;
using
Titanium.Web.Proxy.EventArguments
;
...
@@ -84,8 +82,7 @@ namespace Titanium.Web.Proxy
...
@@ -84,8 +82,7 @@ namespace Titanium.Web.Proxy
{
{
try
try
{
{
Request
.
ParseRequestLine
(
httpCmd
,
out
string
httpMethod
,
out
string
httpUrl
,
Request
.
ParseRequestLine
(
httpCmd
,
out
string
httpMethod
,
out
string
httpUrl
,
out
var
version
);
out
var
version
);
// Read the request headers in to unique and non-unique header collections
// Read the request headers in to unique and non-unique header collections
await
HeaderParser
.
ReadHeaders
(
clientStream
,
args
.
HttpClient
.
Request
.
Headers
,
await
HeaderParser
.
ReadHeaders
(
clientStream
,
args
.
HttpClient
.
Request
.
Headers
,
...
@@ -224,7 +221,7 @@ namespace Titanium.Web.Proxy
...
@@ -224,7 +221,7 @@ namespace Titanium.Web.Proxy
closeServerConnection
=
!
result
.
Continue
;
closeServerConnection
=
!
result
.
Continue
;
// throw if exception happened
// throw if exception happened
if
(
!
result
.
IsSuccess
)
if
(
result
.
Exception
!=
null
)
{
{
throw
result
.
Exception
;
throw
result
.
Exception
;
}
}
...
@@ -347,7 +344,6 @@ namespace Titanium.Web.Proxy
...
@@ -347,7 +344,6 @@ namespace Titanium.Web.Proxy
var
clientStreamWriter
=
args
.
ProxyClient
.
ClientStreamWriter
;
var
clientStreamWriter
=
args
.
ProxyClient
.
ClientStreamWriter
;
var
response
=
args
.
HttpClient
.
Response
;
var
response
=
args
.
HttpClient
.
Response
;
var
headerBuilder
=
new
HeaderBuilder
();
var
headerBuilder
=
new
HeaderBuilder
();
headerBuilder
.
WriteResponseLine
(
response
.
HttpVersion
,
response
.
StatusCode
,
response
.
StatusDescription
);
headerBuilder
.
WriteResponseLine
(
response
.
HttpVersion
,
response
.
StatusCode
,
response
.
StatusDescription
);
headerBuilder
.
WriteHeaders
(
response
.
Headers
);
headerBuilder
.
WriteHeaders
(
response
.
Headers
);
...
@@ -362,12 +358,12 @@ namespace Titanium.Web.Proxy
...
@@ -362,12 +358,12 @@ namespace Titanium.Web.Proxy
if
(
request
.
IsBodyRead
)
if
(
request
.
IsBodyRead
)
{
{
var
writer
=
args
.
HttpClient
.
Connection
.
StreamWriter
;
var
writer
=
args
.
HttpClient
.
Connection
.
StreamWriter
;
await
writer
.
WriteBodyAsync
(
body
,
request
.
IsChunked
,
cancellationToken
);
await
writer
.
WriteBodyAsync
(
body
!
,
request
.
IsChunked
,
cancellationToken
);
}
}
else
if
(!
request
.
ExpectationFailed
)
else
if
(!
request
.
ExpectationFailed
)
{
{
// get the request body unless an unsuccessful 100 continue request was made
// get the request body unless an unsuccessful 100 continue request was made
HttpWriter
writer
=
args
.
HttpClient
.
Connection
.
StreamWriter
;
HttpWriter
writer
=
args
.
HttpClient
.
Connection
.
StreamWriter
!
;
await
args
.
CopyRequestBodyAsync
(
writer
,
TransformationMode
.
None
,
cancellationToken
);
await
args
.
CopyRequestBodyAsync
(
writer
,
TransformationMode
.
None
,
cancellationToken
);
}
}
}
}
...
...
src/Titanium.Web.Proxy/StreamExtended/Network/CopyStream.cs
View file @
d8dce115
...
@@ -37,7 +37,7 @@ namespace Titanium.Web.Proxy.StreamExtended.Network
...
@@ -37,7 +37,7 @@ namespace Titanium.Web.Proxy.StreamExtended.Network
this
.
bufferPool
=
bufferPool
;
this
.
bufferPool
=
bufferPool
;
}
}
public
async
Task
<
bool
>
FillBufferAsync
(
CancellationToken
cancellationToken
=
default
)
public
async
Value
Task
<
bool
>
FillBufferAsync
(
CancellationToken
cancellationToken
=
default
)
{
{
await
FlushAsync
(
cancellationToken
);
await
FlushAsync
(
cancellationToken
);
return
await
reader
.
FillBufferAsync
(
cancellationToken
);
return
await
reader
.
FillBufferAsync
(
cancellationToken
);
...
@@ -124,7 +124,7 @@ namespace Titanium.Web.Proxy.StreamExtended.Network
...
@@ -124,7 +124,7 @@ namespace Titanium.Web.Proxy.StreamExtended.Network
return
result
;
return
result
;
}
}
public
Task
<
string
>
ReadLineAsync
(
CancellationToken
cancellationToken
=
default
)
public
Task
<
string
?
>
ReadLineAsync
(
CancellationToken
cancellationToken
=
default
)
{
{
return
CustomBufferedStream
.
ReadLineInternalAsync
(
this
,
bufferPool
,
cancellationToken
);
return
CustomBufferedStream
.
ReadLineInternalAsync
(
this
,
bufferPool
,
cancellationToken
);
}
}
...
...
src/Titanium.Web.Proxy/StreamExtended/Network/CustomBufferedPeekStream.cs
View file @
d8dce115
...
@@ -69,7 +69,7 @@ namespace Titanium.Web.Proxy.StreamExtended.Network
...
@@ -69,7 +69,7 @@ namespace Titanium.Web.Proxy.StreamExtended.Network
/// Fills the buffer asynchronous.
/// Fills the buffer asynchronous.
/// </summary>
/// </summary>
/// <returns></returns>
/// <returns></returns>
Task
<
bool
>
ICustomStreamReader
.
FillBufferAsync
(
CancellationToken
cancellationToken
)
Value
Task
<
bool
>
ICustomStreamReader
.
FillBufferAsync
(
CancellationToken
cancellationToken
)
{
{
return
baseStream
.
FillBufferAsync
(
cancellationToken
);
return
baseStream
.
FillBufferAsync
(
cancellationToken
);
}
}
...
@@ -141,7 +141,7 @@ namespace Titanium.Web.Proxy.StreamExtended.Network
...
@@ -141,7 +141,7 @@ namespace Titanium.Web.Proxy.StreamExtended.Network
/// </summary>
/// </summary>
/// <param name="cancellationToken"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
/// <returns></returns>
Task
<
string
>
ICustomStreamReader
.
ReadLineAsync
(
CancellationToken
cancellationToken
)
Task
<
string
?
>
ICustomStreamReader
.
ReadLineAsync
(
CancellationToken
cancellationToken
)
{
{
return
CustomBufferedStream
.
ReadLineInternalAsync
(
this
,
bufferPool
,
cancellationToken
);
return
CustomBufferedStream
.
ReadLineInternalAsync
(
this
,
bufferPool
,
cancellationToken
);
}
}
...
...
src/Titanium.Web.Proxy/StreamExtended/Network/CustomBufferedStream.cs
View file @
d8dce115
...
@@ -36,9 +36,9 @@ namespace Titanium.Web.Proxy.StreamExtended.Network
...
@@ -36,9 +36,9 @@ namespace Titanium.Web.Proxy.StreamExtended.Network
private
readonly
IBufferPool
bufferPool
;
private
readonly
IBufferPool
bufferPool
;
public
event
EventHandler
<
DataEventArgs
>
DataRead
;
public
event
EventHandler
<
DataEventArgs
>
?
DataRead
;
public
event
EventHandler
<
DataEventArgs
>
DataWrite
;
public
event
EventHandler
<
DataEventArgs
>
?
DataWrite
;
public
Stream
BaseStream
{
get
;
}
public
Stream
BaseStream
{
get
;
}
...
@@ -510,7 +510,7 @@ namespace Titanium.Web.Proxy.StreamExtended.Network
...
@@ -510,7 +510,7 @@ namespace Titanium.Web.Proxy.StreamExtended.Network
/// </summary>
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
/// <returns></returns>
public
async
Task
<
bool
>
FillBufferAsync
(
CancellationToken
cancellationToken
=
default
)
public
async
Value
Task
<
bool
>
FillBufferAsync
(
CancellationToken
cancellationToken
=
default
)
{
{
if
(
closed
)
if
(
closed
)
{
{
...
@@ -558,7 +558,7 @@ namespace Titanium.Web.Proxy.StreamExtended.Network
...
@@ -558,7 +558,7 @@ namespace Titanium.Web.Proxy.StreamExtended.Network
/// Read a line from the byte stream
/// Read a line from the byte stream
/// </summary>
/// </summary>
/// <returns></returns>
/// <returns></returns>
public
Task
<
string
>
ReadLineAsync
(
CancellationToken
cancellationToken
=
default
)
public
Task
<
string
?
>
ReadLineAsync
(
CancellationToken
cancellationToken
=
default
)
{
{
return
ReadLineInternalAsync
(
this
,
bufferPool
,
cancellationToken
);
return
ReadLineInternalAsync
(
this
,
bufferPool
,
cancellationToken
);
}
}
...
...
src/Titanium.Web.Proxy/StreamExtended/Network/ICustomStreamReader.cs
View file @
d8dce115
...
@@ -17,7 +17,7 @@ namespace Titanium.Web.Proxy.StreamExtended.Network
...
@@ -17,7 +17,7 @@ namespace Titanium.Web.Proxy.StreamExtended.Network
/// Fills the buffer asynchronous.
/// Fills the buffer asynchronous.
/// </summary>
/// </summary>
/// <returns></returns>
/// <returns></returns>
Task
<
bool
>
FillBufferAsync
(
CancellationToken
cancellationToken
=
default
);
Value
Task
<
bool
>
FillBufferAsync
(
CancellationToken
cancellationToken
=
default
);
/// <summary>
/// <summary>
/// Peeks a byte from buffer.
/// Peeks a byte from buffer.
...
@@ -74,6 +74,6 @@ namespace Titanium.Web.Proxy.StreamExtended.Network
...
@@ -74,6 +74,6 @@ namespace Titanium.Web.Proxy.StreamExtended.Network
/// Read a line from the byte stream
/// Read a line from the byte stream
/// </summary>
/// </summary>
/// <returns></returns>
/// <returns></returns>
Task
<
string
>
ReadLineAsync
(
CancellationToken
cancellationToken
=
default
);
Task
<
string
?
>
ReadLineAsync
(
CancellationToken
cancellationToken
=
default
);
}
}
}
}
src/Titanium.Web.Proxy/Titanium.Web.Proxy.csproj
View file @
d8dce115
...
@@ -17,6 +17,7 @@
...
@@ -17,6 +17,7 @@
<PackageReference Include="Portable.BouncyCastle" Version="1.8.5" />
<PackageReference Include="Portable.BouncyCastle" Version="1.8.5" />
<PackageReference Include="System.Buffers" Version="4.5.0" />
<PackageReference Include="System.Buffers" Version="4.5.0" />
<PackageReference Include="System.Memory" Version="4.5.3" />
<PackageReference Include="System.Memory" Version="4.5.3" />
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.3" />
</ItemGroup>
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
...
...
src/Titanium.Web.Proxy/WinAuthHandler.cs
View file @
d8dce115
...
@@ -111,7 +111,7 @@ namespace Titanium.Web.Proxy
...
@@ -111,7 +111,7 @@ namespace Titanium.Web.Proxy
// initial value will match exactly any of the schemes
// initial value will match exactly any of the schemes
if
(
scheme
!=
null
)
if
(
scheme
!=
null
)
{
{
string
clientToken
=
WinAuthHandler
.
GetInitialAuthToken
(
request
.
Host
,
scheme
,
args
.
HttpClient
.
Data
);
string
clientToken
=
WinAuthHandler
.
GetInitialAuthToken
(
request
.
Host
!
,
scheme
,
args
.
HttpClient
.
Data
);
string
auth
=
string
.
Concat
(
scheme
,
clientToken
);
string
auth
=
string
.
Concat
(
scheme
,
clientToken
);
...
@@ -127,7 +127,6 @@ namespace Titanium.Web.Proxy
...
@@ -127,7 +127,6 @@ namespace Titanium.Web.Proxy
else
else
{
{
// challenge value will start with any of the scheme selected
// challenge value will start with any of the scheme selected
scheme
=
authSchemes
.
First
(
x
=>
scheme
=
authSchemes
.
First
(
x
=>
authHeader
.
Value
.
StartsWith
(
x
,
StringComparison
.
OrdinalIgnoreCase
)
&&
authHeader
.
Value
.
StartsWith
(
x
,
StringComparison
.
OrdinalIgnoreCase
)
&&
authHeader
.
Value
.
Length
>
x
.
Length
+
1
);
authHeader
.
Value
.
Length
>
x
.
Length
+
1
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment