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
2c9cdab7
Commit
2c9cdab7
authored
May 10, 2018
by
justcoding121
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
enable option to use custom buffer pool by user
parent
a7b7cc7e
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
110 additions
and
95 deletions
+110
-95
Titanium.Web.Proxy.Examples.Wpf.csproj
...Proxy.Examples.Wpf/Titanium.Web.Proxy.Examples.Wpf.csproj
+2
-2
packages.config
Examples/Titanium.Web.Proxy.Examples.Wpf/packages.config
+1
-1
LimitedStream.cs
Titanium.Web.Proxy/EventArguments/LimitedStream.cs
+7
-5
SessionEventArgs.cs
Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs
+14
-16
SessionEventArgsBase.cs
Titanium.Web.Proxy/EventArguments/SessionEventArgsBase.cs
+15
-15
TunnelConnectEventArgs.cs
Titanium.Web.Proxy/EventArguments/TunnelConnectEventArgs.cs
+3
-3
ExplicitClientHandler.cs
Titanium.Web.Proxy/ExplicitClientHandler.cs
+9
-10
StreamExtensions.cs
Titanium.Web.Proxy/Extensions/StreamExtensions.cs
+6
-6
HttpRequestWriter.cs
Titanium.Web.Proxy/Helpers/HttpRequestWriter.cs
+3
-1
HttpResponseWriter.cs
Titanium.Web.Proxy/Helpers/HttpResponseWriter.cs
+3
-1
HttpWriter.cs
Titanium.Web.Proxy/Helpers/HttpWriter.cs
+8
-6
TcpHelper.cs
Titanium.Web.Proxy/Helpers/TcpHelper.cs
+14
-13
HttpWebClient.cs
Titanium.Web.Proxy/Http/HttpWebClient.cs
+1
-1
TcpConnectionFactory.cs
Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs
+4
-4
ProxyServer.cs
Titanium.Web.Proxy/ProxyServer.cs
+11
-1
RequestHandler.cs
Titanium.Web.Proxy/RequestHandler.cs
+2
-2
Titanium.Web.Proxy.csproj
Titanium.Web.Proxy/Titanium.Web.Proxy.csproj
+1
-1
TransparentClientHandler.cs
Titanium.Web.Proxy/TransparentClientHandler.cs
+6
-7
No files found.
Examples/Titanium.Web.Proxy.Examples.Wpf/Titanium.Web.Proxy.Examples.Wpf.csproj
View file @
2c9cdab7
...
@@ -51,8 +51,8 @@
...
@@ -51,8 +51,8 @@
<WarningLevel>
4
</WarningLevel>
<WarningLevel>
4
</WarningLevel>
</PropertyGroup>
</PropertyGroup>
<ItemGroup>
<ItemGroup>
<Reference
Include=
"StreamExtended, Version=1.0.1
67
.0, Culture=neutral, PublicKeyToken=bbfa0f1d54f50043, processorArchitecture=MSIL"
>
<Reference
Include=
"StreamExtended, Version=1.0.1
70
.0, Culture=neutral, PublicKeyToken=bbfa0f1d54f50043, processorArchitecture=MSIL"
>
<HintPath>
..\..\packages\StreamExtended.1.0.1
67
-beta\lib\net45\StreamExtended.dll
</HintPath>
<HintPath>
..\..\packages\StreamExtended.1.0.1
70
-beta\lib\net45\StreamExtended.dll
</HintPath>
</Reference>
</Reference>
<Reference
Include=
"System"
/>
<Reference
Include=
"System"
/>
<Reference
Include=
"System.Data"
/>
<Reference
Include=
"System.Data"
/>
...
...
Examples/Titanium.Web.Proxy.Examples.Wpf/packages.config
View file @
2c9cdab7
<?
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
<?
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
<
packages
>
<
packages
>
<
package
id
=
"StreamExtended"
version
=
"1.0.1
67
-beta"
targetFramework
=
"net45"
/>
<
package
id
=
"StreamExtended"
version
=
"1.0.1
70
-beta"
targetFramework
=
"net45"
/>
</
packages
>
</
packages
>
\ No newline at end of file
Titanium.Web.Proxy/EventArguments/LimitedStream.cs
View file @
2c9cdab7
...
@@ -2,23 +2,25 @@
...
@@ -2,23 +2,25 @@
using
System.Globalization
;
using
System.Globalization
;
using
System.IO
;
using
System.IO
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
using
StreamExtended
.Helpers
;
using
StreamExtended
;
using
StreamExtended.Network
;
using
StreamExtended.Network
;
namespace
Titanium.Web.Proxy.EventArguments
namespace
Titanium.Web.Proxy.EventArguments
{
{
internal
class
LimitedStream
:
Stream
internal
class
LimitedStream
:
Stream
{
{
private
readonly
IBufferPool
bufferPool
;
private
readonly
ICustomStreamReader
baseStream
;
private
readonly
ICustomStreamReader
baseStream
;
private
readonly
bool
isChunked
;
private
readonly
bool
isChunked
;
private
long
bytesRemaining
;
private
long
bytesRemaining
;
private
bool
readChunkTrail
;
private
bool
readChunkTrail
;
internal
LimitedStream
(
ICustomStreamReader
baseStream
,
bool
isChunked
,
internal
LimitedStream
(
ICustomStreamReader
baseStream
,
IBufferPool
bufferPool
,
bool
isChunked
,
long
contentLength
)
long
contentLength
)
{
{
this
.
baseStream
=
baseStream
;
this
.
baseStream
=
baseStream
;
this
.
bufferPool
=
bufferPool
;
this
.
isChunked
=
isChunked
;
this
.
isChunked
=
isChunked
;
bytesRemaining
=
isChunked
bytesRemaining
=
isChunked
?
0
?
0
...
@@ -125,7 +127,7 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -125,7 +127,7 @@ namespace Titanium.Web.Proxy.EventArguments
{
{
if
(
bytesRemaining
!=
-
1
)
if
(
bytesRemaining
!=
-
1
)
{
{
var
buffer
=
B
ufferPool
.
GetBuffer
(
baseStream
.
BufferSize
);
var
buffer
=
b
ufferPool
.
GetBuffer
(
baseStream
.
BufferSize
);
try
try
{
{
int
res
=
await
ReadAsync
(
buffer
,
0
,
buffer
.
Length
);
int
res
=
await
ReadAsync
(
buffer
,
0
,
buffer
.
Length
);
...
@@ -136,7 +138,7 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -136,7 +138,7 @@ namespace Titanium.Web.Proxy.EventArguments
}
}
finally
finally
{
{
B
ufferPool
.
ReturnBuffer
(
buffer
);
b
ufferPool
.
ReturnBuffer
(
buffer
);
}
}
}
}
}
}
...
...
Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs
View file @
2c9cdab7
...
@@ -4,14 +4,12 @@ using System.IO;
...
@@ -4,14 +4,12 @@ using System.IO;
using
System.Net
;
using
System.Net
;
using
System.Threading
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
using
StreamExtended.Helpers
;
using
StreamExtended.Network
;
using
StreamExtended.Network
;
using
Titanium.Web.Proxy.Compression
;
using
Titanium.Web.Proxy.Compression
;
using
Titanium.Web.Proxy.Helpers
;
using
Titanium.Web.Proxy.Helpers
;
using
Titanium.Web.Proxy.Http
;
using
Titanium.Web.Proxy.Http
;
using
Titanium.Web.Proxy.Http.Responses
;
using
Titanium.Web.Proxy.Http.Responses
;
using
Titanium.Web.Proxy.Models
;
using
Titanium.Web.Proxy.Models
;
using
Titanium.Web.Proxy.Network
;
namespace
Titanium.Web.Proxy.EventArguments
namespace
Titanium.Web.Proxy.EventArguments
{
{
...
@@ -33,15 +31,15 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -33,15 +31,15 @@ namespace Titanium.Web.Proxy.EventArguments
/// <summary>
/// <summary>
/// Constructor to initialize the proxy
/// Constructor to initialize the proxy
/// </summary>
/// </summary>
internal
SessionEventArgs
(
int
bufferSize
,
ProxyEndPoint
endPoint
,
internal
SessionEventArgs
(
ProxyServer
server
,
ProxyEndPoint
endPoint
,
CancellationTokenSource
cancellationTokenSource
,
ExceptionHandler
exceptionFunc
)
CancellationTokenSource
cancellationTokenSource
)
:
this
(
bufferSize
,
endPoint
,
null
,
cancellationTokenSource
,
exceptionFunc
)
:
this
(
server
,
endPoint
,
null
,
cancellationTokenSource
)
{
{
}
}
protected
SessionEventArgs
(
int
bufferSize
,
ProxyEndPoint
endPoint
,
protected
SessionEventArgs
(
ProxyServer
server
,
ProxyEndPoint
endPoint
,
Request
request
,
CancellationTokenSource
cancellationTokenSource
,
ExceptionHandler
exceptionFunc
)
Request
request
,
CancellationTokenSource
cancellationTokenSource
)
:
base
(
bufferSize
,
endPoint
,
cancellationTokenSource
,
request
,
exceptionFunc
)
:
base
(
server
,
endPoint
,
cancellationTokenSource
,
request
)
{
{
}
}
...
@@ -119,7 +117,7 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -119,7 +117,7 @@ namespace Titanium.Web.Proxy.EventArguments
}
}
catch
(
Exception
ex
)
catch
(
Exception
ex
)
{
{
E
xceptionFunc
(
new
Exception
(
"Exception thrown in user event"
,
ex
));
e
xceptionFunc
(
new
Exception
(
"Exception thrown in user event"
,
ex
));
}
}
}
}
...
@@ -156,7 +154,7 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -156,7 +154,7 @@ namespace Titanium.Web.Proxy.EventArguments
{
{
using
(
var
bodyStream
=
new
MemoryStream
())
using
(
var
bodyStream
=
new
MemoryStream
())
{
{
var
writer
=
new
HttpWriter
(
bodyStream
,
B
ufferSize
);
var
writer
=
new
HttpWriter
(
bodyStream
,
bufferPool
,
b
ufferSize
);
if
(
isRequest
)
if
(
isRequest
)
{
{
...
@@ -181,7 +179,7 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -181,7 +179,7 @@ namespace Titanium.Web.Proxy.EventArguments
using
(
var
bodyStream
=
new
MemoryStream
())
using
(
var
bodyStream
=
new
MemoryStream
())
{
{
var
writer
=
new
HttpWriter
(
bodyStream
,
B
ufferSize
);
var
writer
=
new
HttpWriter
(
bodyStream
,
bufferPool
,
b
ufferSize
);
await
copyBodyAsync
(
isRequest
,
writer
,
TransformationMode
.
None
,
null
,
cancellationToken
);
await
copyBodyAsync
(
isRequest
,
writer
,
TransformationMode
.
None
,
null
,
cancellationToken
);
}
}
}
}
...
@@ -202,7 +200,7 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -202,7 +200,7 @@ namespace Titanium.Web.Proxy.EventArguments
var
reader
=
getStreamReader
(
true
);
var
reader
=
getStreamReader
(
true
);
string
boundary
=
HttpHelper
.
GetBoundaryFromContentType
(
request
.
ContentType
);
string
boundary
=
HttpHelper
.
GetBoundaryFromContentType
(
request
.
ContentType
);
using
(
var
copyStream
=
new
CopyStream
(
reader
,
writer
,
B
ufferSize
))
using
(
var
copyStream
=
new
CopyStream
(
reader
,
writer
,
bufferPool
,
b
ufferSize
))
{
{
while
(
contentLength
>
copyStream
.
ReadBytes
)
while
(
contentLength
>
copyStream
.
ReadBytes
)
{
{
...
@@ -253,7 +251,7 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -253,7 +251,7 @@ namespace Titanium.Web.Proxy.EventArguments
string
contentEncoding
=
requestResponse
.
ContentEncoding
;
string
contentEncoding
=
requestResponse
.
ContentEncoding
;
Stream
s
=
limitedStream
=
new
LimitedStream
(
stream
,
isChunked
,
contentLength
);
Stream
s
=
limitedStream
=
new
LimitedStream
(
stream
,
bufferPool
,
isChunked
,
contentLength
);
if
(
transformation
==
TransformationMode
.
Uncompress
&&
contentEncoding
!=
null
)
if
(
transformation
==
TransformationMode
.
Uncompress
&&
contentEncoding
!=
null
)
{
{
...
@@ -262,7 +260,7 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -262,7 +260,7 @@ namespace Titanium.Web.Proxy.EventArguments
try
try
{
{
using
(
var
bufStream
=
new
CustomBufferedStream
(
s
,
B
ufferSize
,
true
))
using
(
var
bufStream
=
new
CustomBufferedStream
(
s
,
bufferPool
,
b
ufferSize
,
true
))
{
{
await
writer
.
CopyBodyAsync
(
bufStream
,
false
,
-
1
,
onCopy
,
cancellationToken
);
await
writer
.
CopyBodyAsync
(
bufStream
,
false
,
-
1
,
onCopy
,
cancellationToken
);
}
}
...
@@ -284,7 +282,7 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -284,7 +282,7 @@ namespace Titanium.Web.Proxy.EventArguments
{
{
int
bufferDataLength
=
0
;
int
bufferDataLength
=
0
;
var
buffer
=
BufferPool
.
GetBuffer
(
B
ufferSize
);
var
buffer
=
bufferPool
.
GetBuffer
(
b
ufferSize
);
try
try
{
{
int
boundaryLength
=
boundary
.
Length
+
4
;
int
boundaryLength
=
boundary
.
Length
+
4
;
...
@@ -334,7 +332,7 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -334,7 +332,7 @@ namespace Titanium.Web.Proxy.EventArguments
}
}
finally
finally
{
{
B
ufferPool
.
ReturnBuffer
(
buffer
);
b
ufferPool
.
ReturnBuffer
(
buffer
);
}
}
}
}
...
...
Titanium.Web.Proxy/EventArguments/SessionEventArgsBase.cs
View file @
2c9cdab7
using
System
;
using
System
;
using
System.Net
;
using
System.Net
;
using
System.Threading
;
using
System.Threading
;
using
StreamExtended
;
using
StreamExtended.Network
;
using
StreamExtended.Network
;
using
Titanium.Web.Proxy.Helpers
;
using
Titanium.Web.Proxy.Helpers
;
using
Titanium.Web.Proxy.Http
;
using
Titanium.Web.Proxy.Http
;
...
@@ -17,34 +18,33 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -17,34 +18,33 @@ namespace Titanium.Web.Proxy.EventArguments
/// </summary>
/// </summary>
public
abstract
class
SessionEventArgsBase
:
EventArgs
,
IDisposable
public
abstract
class
SessionEventArgsBase
:
EventArgs
,
IDisposable
{
{
/// <summary>
/// Size of Buffers used by this object
/// </summary>
protected
readonly
int
BufferSize
;
internal
readonly
CancellationTokenSource
CancellationTokenSource
;
internal
readonly
CancellationTokenSource
CancellationTokenSource
;
protected
readonly
ExceptionHandler
ExceptionFunc
;
protected
readonly
int
bufferSize
;
protected
readonly
IBufferPool
bufferPool
;
protected
readonly
ExceptionHandler
exceptionFunc
;
/// <summary>
/// <summary>
/// Initializes a new instance of the <see cref="SessionEventArgsBase" /> class.
/// Initializes a new instance of the <see cref="SessionEventArgsBase" /> class.
/// </summary>
/// </summary>
internal
SessionEventArgsBase
(
int
bufferSize
,
ProxyEndPoint
endPoint
,
internal
SessionEventArgsBase
(
ProxyServer
server
,
ProxyEndPoint
endPoint
,
CancellationTokenSource
cancellationTokenSource
,
ExceptionHandler
exceptionFunc
)
CancellationTokenSource
cancellationTokenSource
)
:
this
(
bufferSize
,
endPoint
,
cancellationTokenSource
,
null
,
exceptionFunc
)
:
this
(
server
,
endPoint
,
cancellationTokenSource
,
null
)
{
{
bufferSize
=
server
.
BufferSize
;
bufferPool
=
server
.
BufferPool
;
exceptionFunc
=
server
.
ExceptionFunc
;
}
}
protected
SessionEventArgsBase
(
int
bufferSize
,
ProxyEndPoint
endPoint
,
protected
SessionEventArgsBase
(
ProxyServer
server
,
ProxyEndPoint
endPoint
,
CancellationTokenSource
cancellationTokenSource
,
CancellationTokenSource
cancellationTokenSource
,
Request
request
,
ExceptionHandler
exceptionFunc
)
Request
request
)
{
{
BufferSize
=
bufferSize
;
ExceptionFunc
=
exceptionFunc
;
CancellationTokenSource
=
cancellationTokenSource
;
CancellationTokenSource
=
cancellationTokenSource
;
ProxyClient
=
new
ProxyClient
();
ProxyClient
=
new
ProxyClient
();
WebSession
=
new
HttpWebClient
(
bufferSize
,
request
);
WebSession
=
new
HttpWebClient
(
request
);
LocalEndPoint
=
endPoint
;
LocalEndPoint
=
endPoint
;
WebSession
.
ProcessId
=
new
Lazy
<
int
>(()
=>
WebSession
.
ProcessId
=
new
Lazy
<
int
>(()
=>
...
@@ -151,7 +151,7 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -151,7 +151,7 @@ namespace Titanium.Web.Proxy.EventArguments
}
}
catch
(
Exception
ex
)
catch
(
Exception
ex
)
{
{
E
xceptionFunc
(
new
Exception
(
"Exception thrown in user event"
,
ex
));
e
xceptionFunc
(
new
Exception
(
"Exception thrown in user event"
,
ex
));
}
}
}
}
...
@@ -163,7 +163,7 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -163,7 +163,7 @@ namespace Titanium.Web.Proxy.EventArguments
}
}
catch
(
Exception
ex
)
catch
(
Exception
ex
)
{
{
E
xceptionFunc
(
new
Exception
(
"Exception thrown in user event"
,
ex
));
e
xceptionFunc
(
new
Exception
(
"Exception thrown in user event"
,
ex
));
}
}
}
}
...
...
Titanium.Web.Proxy/EventArguments/TunnelConnectEventArgs.cs
View file @
2c9cdab7
...
@@ -12,9 +12,9 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -12,9 +12,9 @@ namespace Titanium.Web.Proxy.EventArguments
{
{
private
bool
?
isHttpsConnect
;
private
bool
?
isHttpsConnect
;
internal
TunnelConnectSessionEventArgs
(
int
bufferSize
,
ProxyEndPoint
endPoint
,
ConnectRequest
connectRequest
,
internal
TunnelConnectSessionEventArgs
(
ProxyServer
server
,
ProxyEndPoint
endPoint
,
ConnectRequest
connectRequest
,
CancellationTokenSource
cancellationTokenSource
,
ExceptionHandler
exceptionFunc
)
CancellationTokenSource
cancellationTokenSource
)
:
base
(
bufferSize
,
endPoint
,
cancellationTokenSource
,
connectRequest
,
exceptionFunc
)
:
base
(
server
,
endPoint
,
cancellationTokenSource
,
connectRequest
)
{
{
WebSession
.
ConnectRequest
=
connectRequest
;
WebSession
.
ConnectRequest
=
connectRequest
;
}
}
...
...
Titanium.Web.Proxy/ExplicitClientHandler.cs
View file @
2c9cdab7
...
@@ -7,7 +7,6 @@ using System.Security.Cryptography.X509Certificates;
...
@@ -7,7 +7,6 @@ using System.Security.Cryptography.X509Certificates;
using
System.Threading
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
using
StreamExtended
;
using
StreamExtended
;
using
StreamExtended.Helpers
;
using
StreamExtended.Network
;
using
StreamExtended.Network
;
using
Titanium.Web.Proxy.EventArguments
;
using
Titanium.Web.Proxy.EventArguments
;
using
Titanium.Web.Proxy.Exceptions
;
using
Titanium.Web.Proxy.Exceptions
;
...
@@ -34,9 +33,9 @@ namespace Titanium.Web.Proxy
...
@@ -34,9 +33,9 @@ namespace Titanium.Web.Proxy
var
cancellationTokenSource
=
new
CancellationTokenSource
();
var
cancellationTokenSource
=
new
CancellationTokenSource
();
var
cancellationToken
=
cancellationTokenSource
.
Token
;
var
cancellationToken
=
cancellationTokenSource
.
Token
;
var
clientStream
=
new
CustomBufferedStream
(
clientConnection
.
GetStream
(),
BufferSize
);
var
clientStream
=
new
CustomBufferedStream
(
clientConnection
.
GetStream
(),
Buffer
Pool
,
Buffer
Size
);
var
clientStreamWriter
=
new
HttpResponseWriter
(
clientStream
,
BufferSize
);
var
clientStreamWriter
=
new
HttpResponseWriter
(
clientStream
,
Buffer
Pool
,
Buffer
Size
);
try
try
{
{
...
@@ -67,8 +66,8 @@ namespace Titanium.Web.Proxy
...
@@ -67,8 +66,8 @@ namespace Titanium.Web.Proxy
await
HeaderParser
.
ReadHeaders
(
clientStream
,
connectRequest
.
Headers
,
cancellationToken
);
await
HeaderParser
.
ReadHeaders
(
clientStream
,
connectRequest
.
Headers
,
cancellationToken
);
connectArgs
=
new
TunnelConnectSessionEventArgs
(
BufferSize
,
endPoint
,
connectRequest
,
connectArgs
=
new
TunnelConnectSessionEventArgs
(
this
,
endPoint
,
connectRequest
,
cancellationTokenSource
,
ExceptionFunc
);
cancellationTokenSource
);
connectArgs
.
ProxyClient
.
ClientConnection
=
clientConnection
;
connectArgs
.
ProxyClient
.
ClientConnection
=
clientConnection
;
connectArgs
.
ProxyClient
.
ClientStream
=
clientStream
;
connectArgs
.
ProxyClient
.
ClientStream
=
clientStream
;
...
@@ -115,7 +114,7 @@ namespace Titanium.Web.Proxy
...
@@ -115,7 +114,7 @@ namespace Titanium.Web.Proxy
await
clientStreamWriter
.
WriteResponseAsync
(
response
,
cancellationToken
:
cancellationToken
);
await
clientStreamWriter
.
WriteResponseAsync
(
response
,
cancellationToken
:
cancellationToken
);
var
clientHelloInfo
=
await
SslTools
.
PeekClientHello
(
clientStream
,
cancellationToken
);
var
clientHelloInfo
=
await
SslTools
.
PeekClientHello
(
clientStream
,
BufferPool
,
cancellationToken
);
bool
isClientHello
=
clientHelloInfo
!=
null
;
bool
isClientHello
=
clientHelloInfo
!=
null
;
if
(
isClientHello
)
if
(
isClientHello
)
...
@@ -180,8 +179,8 @@ namespace Titanium.Web.Proxy
...
@@ -180,8 +179,8 @@ namespace Titanium.Web.Proxy
#endif
#endif
// HTTPS server created - we can now decrypt the client's traffic
// HTTPS server created - we can now decrypt the client's traffic
clientStream
=
new
CustomBufferedStream
(
sslStream
,
BufferSize
);
clientStream
=
new
CustomBufferedStream
(
sslStream
,
Buffer
Pool
,
Buffer
Size
);
clientStreamWriter
=
new
HttpResponseWriter
(
clientStream
,
BufferSize
);
clientStreamWriter
=
new
HttpResponseWriter
(
clientStream
,
Buffer
Pool
,
Buffer
Size
);
}
}
catch
(
Exception
e
)
catch
(
Exception
e
)
{
{
...
@@ -230,11 +229,11 @@ namespace Titanium.Web.Proxy
...
@@ -230,11 +229,11 @@ namespace Titanium.Web.Proxy
}
}
var
serverHelloInfo
=
var
serverHelloInfo
=
await
SslTools
.
PeekServerHello
(
connection
.
Stream
,
cancellationToken
);
await
SslTools
.
PeekServerHello
(
connection
.
Stream
,
BufferPool
,
cancellationToken
);
((
ConnectResponse
)
connectArgs
.
WebSession
.
Response
).
ServerHelloInfo
=
serverHelloInfo
;
((
ConnectResponse
)
connectArgs
.
WebSession
.
Response
).
ServerHelloInfo
=
serverHelloInfo
;
}
}
await
TcpHelper
.
SendRaw
(
clientStream
,
connection
.
Stream
,
BufferSize
,
await
TcpHelper
.
SendRaw
(
clientStream
,
connection
.
Stream
,
Buffer
Pool
,
Buffer
Size
,
(
buffer
,
offset
,
count
)
=>
{
connectArgs
.
OnDataSent
(
buffer
,
offset
,
count
);
},
(
buffer
,
offset
,
count
)
=>
{
connectArgs
.
OnDataSent
(
buffer
,
offset
,
count
);
},
(
buffer
,
offset
,
count
)
=>
{
connectArgs
.
OnDataReceived
(
buffer
,
offset
,
count
);
},
(
buffer
,
offset
,
count
)
=>
{
connectArgs
.
OnDataReceived
(
buffer
,
offset
,
count
);
},
connectArgs
.
CancellationTokenSource
,
ExceptionFunc
);
connectArgs
.
CancellationTokenSource
,
ExceptionFunc
);
...
...
Titanium.Web.Proxy/Extensions/StreamExtensions.cs
View file @
2c9cdab7
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
using
System.IO
;
using
System.IO
;
using
System.Threading
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
using
StreamExtended
.Helpers
;
using
StreamExtended
;
namespace
Titanium.Web.Proxy.Extensions
namespace
Titanium.Web.Proxy.Extensions
{
{
...
@@ -19,9 +19,9 @@ namespace Titanium.Web.Proxy.Extensions
...
@@ -19,9 +19,9 @@ namespace Titanium.Web.Proxy.Extensions
/// <param name="onCopy"></param>
/// <param name="onCopy"></param>
/// <param name="bufferSize"></param>
/// <param name="bufferSize"></param>
internal
static
Task
CopyToAsync
(
this
Stream
input
,
Stream
output
,
Action
<
byte
[],
int
,
int
>
onCopy
,
internal
static
Task
CopyToAsync
(
this
Stream
input
,
Stream
output
,
Action
<
byte
[],
int
,
int
>
onCopy
,
int
bufferSize
)
IBufferPool
bufferPool
,
int
bufferSize
)
{
{
return
CopyToAsync
(
input
,
output
,
onCopy
,
bufferSize
,
CancellationToken
.
None
);
return
CopyToAsync
(
input
,
output
,
onCopy
,
buffer
Pool
,
buffer
Size
,
CancellationToken
.
None
);
}
}
/// <summary>
/// <summary>
...
@@ -33,9 +33,9 @@ namespace Titanium.Web.Proxy.Extensions
...
@@ -33,9 +33,9 @@ namespace Titanium.Web.Proxy.Extensions
/// <param name="bufferSize"></param>
/// <param name="bufferSize"></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
,
int
bufferSize
,
CancellationToken
cancellationToken
)
IBufferPool
bufferPool
,
int
bufferSize
,
CancellationToken
cancellationToken
)
{
{
var
buffer
=
B
ufferPool
.
GetBuffer
(
bufferSize
);
var
buffer
=
b
ufferPool
.
GetBuffer
(
bufferSize
);
try
try
{
{
while
(!
cancellationToken
.
IsCancellationRequested
)
while
(!
cancellationToken
.
IsCancellationRequested
)
...
@@ -58,7 +58,7 @@ namespace Titanium.Web.Proxy.Extensions
...
@@ -58,7 +58,7 @@ namespace Titanium.Web.Proxy.Extensions
}
}
finally
finally
{
{
B
ufferPool
.
ReturnBuffer
(
buffer
);
b
ufferPool
.
ReturnBuffer
(
buffer
);
}
}
}
}
...
...
Titanium.Web.Proxy/Helpers/HttpRequestWriter.cs
View file @
2c9cdab7
using
System.IO
;
using
System.IO
;
using
System.Threading
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
using
StreamExtended
;
using
Titanium.Web.Proxy.Http
;
using
Titanium.Web.Proxy.Http
;
namespace
Titanium.Web.Proxy.Helpers
namespace
Titanium.Web.Proxy.Helpers
{
{
internal
sealed
class
HttpRequestWriter
:
HttpWriter
internal
sealed
class
HttpRequestWriter
:
HttpWriter
{
{
internal
HttpRequestWriter
(
Stream
stream
,
int
bufferSize
)
:
base
(
stream
,
bufferSize
)
internal
HttpRequestWriter
(
Stream
stream
,
IBufferPool
bufferPool
,
int
bufferSize
)
:
base
(
stream
,
bufferPool
,
bufferSize
)
{
{
}
}
...
...
Titanium.Web.Proxy/Helpers/HttpResponseWriter.cs
View file @
2c9cdab7
...
@@ -2,13 +2,15 @@
...
@@ -2,13 +2,15 @@
using
System.IO
;
using
System.IO
;
using
System.Threading
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
using
StreamExtended
;
using
Titanium.Web.Proxy.Http
;
using
Titanium.Web.Proxy.Http
;
namespace
Titanium.Web.Proxy.Helpers
namespace
Titanium.Web.Proxy.Helpers
{
{
internal
sealed
class
HttpResponseWriter
:
HttpWriter
internal
sealed
class
HttpResponseWriter
:
HttpWriter
{
{
internal
HttpResponseWriter
(
Stream
stream
,
int
bufferSize
)
:
base
(
stream
,
bufferSize
)
internal
HttpResponseWriter
(
Stream
stream
,
IBufferPool
bufferPool
,
int
bufferSize
)
:
base
(
stream
,
bufferPool
,
bufferSize
)
{
{
}
}
...
...
Titanium.Web.Proxy/Helpers/HttpWriter.cs
View file @
2c9cdab7
...
@@ -4,7 +4,7 @@ using System.IO;
...
@@ -4,7 +4,7 @@ using System.IO;
using
System.Text
;
using
System.Text
;
using
System.Threading
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
using
StreamExtended
.Helpers
;
using
StreamExtended
;
using
StreamExtended.Network
;
using
StreamExtended.Network
;
using
Titanium.Web.Proxy.Http
;
using
Titanium.Web.Proxy.Http
;
using
Titanium.Web.Proxy.Shared
;
using
Titanium.Web.Proxy.Shared
;
...
@@ -14,6 +14,7 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -14,6 +14,7 @@ namespace Titanium.Web.Proxy.Helpers
internal
class
HttpWriter
:
ICustomStreamWriter
internal
class
HttpWriter
:
ICustomStreamWriter
{
{
private
readonly
Stream
stream
;
private
readonly
Stream
stream
;
private
readonly
IBufferPool
bufferPool
;
private
static
readonly
byte
[]
newLine
=
ProxyConstants
.
NewLine
;
private
static
readonly
byte
[]
newLine
=
ProxyConstants
.
NewLine
;
...
@@ -21,10 +22,11 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -21,10 +22,11 @@ namespace Titanium.Web.Proxy.Helpers
private
readonly
char
[]
charBuffer
;
private
readonly
char
[]
charBuffer
;
internal
HttpWriter
(
Stream
stream
,
int
bufferSize
)
internal
HttpWriter
(
Stream
stream
,
IBufferPool
bufferPool
,
int
bufferSize
)
{
{
BufferSize
=
bufferSize
;
BufferSize
=
bufferSize
;
this
.
stream
=
stream
;
this
.
stream
=
stream
;
this
.
bufferPool
=
bufferPool
;
// ASCII encoder max byte count is char count + 1
// ASCII encoder max byte count is char count + 1
charBuffer
=
new
char
[
BufferSize
-
1
];
charBuffer
=
new
char
[
BufferSize
-
1
];
...
@@ -55,7 +57,7 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -55,7 +57,7 @@ namespace Titanium.Web.Proxy.Helpers
{
{
value
.
CopyTo
(
0
,
charBuffer
,
0
,
charCount
);
value
.
CopyTo
(
0
,
charBuffer
,
0
,
charCount
);
var
buffer
=
B
ufferPool
.
GetBuffer
(
BufferSize
);
var
buffer
=
b
ufferPool
.
GetBuffer
(
BufferSize
);
try
try
{
{
int
idx
=
encoder
.
GetBytes
(
charBuffer
,
0
,
charCount
,
buffer
,
0
,
true
);
int
idx
=
encoder
.
GetBytes
(
charBuffer
,
0
,
charCount
,
buffer
,
0
,
true
);
...
@@ -69,7 +71,7 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -69,7 +71,7 @@ namespace Titanium.Web.Proxy.Helpers
}
}
finally
finally
{
{
B
ufferPool
.
ReturnBuffer
(
buffer
);
b
ufferPool
.
ReturnBuffer
(
buffer
);
}
}
}
}
else
else
...
@@ -254,7 +256,7 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -254,7 +256,7 @@ namespace Titanium.Web.Proxy.Helpers
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
=
B
ufferPool
.
GetBuffer
(
BufferSize
);
var
buffer
=
b
ufferPool
.
GetBuffer
(
BufferSize
);
try
try
{
{
...
@@ -283,7 +285,7 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -283,7 +285,7 @@ namespace Titanium.Web.Proxy.Helpers
}
}
finally
finally
{
{
B
ufferPool
.
ReturnBuffer
(
buffer
);
b
ufferPool
.
ReturnBuffer
(
buffer
);
}
}
}
}
...
...
Titanium.Web.Proxy/Helpers/TcpHelper.cs
View file @
2c9cdab7
using
System
;
using
System
;
using
System.IO
;
using
System.IO
;
using
System.Linq
;
using
System.Runtime.InteropServices
;
using
System.Runtime.InteropServices
;
using
System.Text
;
using
System.Threading
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
using
StreamExtended
.Helpers
;
using
StreamExtended
;
using
Titanium.Web.Proxy.Extensions
;
using
Titanium.Web.Proxy.Extensions
;
namespace
Titanium.Web.Proxy.Helpers
namespace
Titanium.Web.Proxy.Helpers
...
@@ -109,7 +107,8 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -109,7 +107,8 @@ namespace Titanium.Web.Proxy.Helpers
/// <param name="cancellationTokenSource"></param>
/// <param name="cancellationTokenSource"></param>
/// <param name="exceptionFunc"></param>
/// <param name="exceptionFunc"></param>
/// <returns></returns>
/// <returns></returns>
internal
static
async
Task
SendRawApm
(
Stream
clientStream
,
Stream
serverStream
,
int
bufferSize
,
internal
static
async
Task
SendRawApm
(
Stream
clientStream
,
Stream
serverStream
,
IBufferPool
bufferPool
,
int
bufferSize
,
Action
<
byte
[],
int
,
int
>
onDataSend
,
Action
<
byte
[],
int
,
int
>
onDataReceive
,
Action
<
byte
[],
int
,
int
>
onDataSend
,
Action
<
byte
[],
int
,
int
>
onDataReceive
,
CancellationTokenSource
cancellationTokenSource
,
CancellationTokenSource
cancellationTokenSource
,
ExceptionHandler
exceptionFunc
)
ExceptionHandler
exceptionFunc
)
...
@@ -118,8 +117,8 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -118,8 +117,8 @@ namespace Titanium.Web.Proxy.Helpers
cancellationTokenSource
.
Token
.
Register
(()
=>
taskCompletionSource
.
TrySetResult
(
true
));
cancellationTokenSource
.
Token
.
Register
(()
=>
taskCompletionSource
.
TrySetResult
(
true
));
// Now async relay all server=>client & client=>server data
// Now async relay all server=>client & client=>server data
var
clientBuffer
=
B
ufferPool
.
GetBuffer
(
bufferSize
);
var
clientBuffer
=
b
ufferPool
.
GetBuffer
(
bufferSize
);
var
serverBuffer
=
B
ufferPool
.
GetBuffer
(
bufferSize
);
var
serverBuffer
=
b
ufferPool
.
GetBuffer
(
bufferSize
);
try
try
{
{
beginRead
(
clientStream
,
serverStream
,
clientBuffer
,
onDataSend
,
cancellationTokenSource
,
exceptionFunc
);
beginRead
(
clientStream
,
serverStream
,
clientBuffer
,
onDataSend
,
cancellationTokenSource
,
exceptionFunc
);
...
@@ -129,8 +128,8 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -129,8 +128,8 @@ namespace Titanium.Web.Proxy.Helpers
}
}
finally
finally
{
{
B
ufferPool
.
ReturnBuffer
(
clientBuffer
);
b
ufferPool
.
ReturnBuffer
(
clientBuffer
);
B
ufferPool
.
ReturnBuffer
(
serverBuffer
);
b
ufferPool
.
ReturnBuffer
(
serverBuffer
);
}
}
}
}
...
@@ -214,16 +213,17 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -214,16 +213,17 @@ namespace Titanium.Web.Proxy.Helpers
/// <param name="cancellationTokenSource"></param>
/// <param name="cancellationTokenSource"></param>
/// <param name="exceptionFunc"></param>
/// <param name="exceptionFunc"></param>
/// <returns></returns>
/// <returns></returns>
private
static
async
Task
sendRawTap
(
Stream
clientStream
,
Stream
serverStream
,
int
bufferSize
,
private
static
async
Task
sendRawTap
(
Stream
clientStream
,
Stream
serverStream
,
IBufferPool
bufferPool
,
int
bufferSize
,
Action
<
byte
[],
int
,
int
>
onDataSend
,
Action
<
byte
[],
int
,
int
>
onDataReceive
,
Action
<
byte
[],
int
,
int
>
onDataSend
,
Action
<
byte
[],
int
,
int
>
onDataReceive
,
CancellationTokenSource
cancellationTokenSource
,
CancellationTokenSource
cancellationTokenSource
,
ExceptionHandler
exceptionFunc
)
ExceptionHandler
exceptionFunc
)
{
{
// Now async relay all server=>client & client=>server data
// Now async relay all server=>client & client=>server data
var
sendRelay
=
var
sendRelay
=
clientStream
.
CopyToAsync
(
serverStream
,
onDataSend
,
bufferSize
,
cancellationTokenSource
.
Token
);
clientStream
.
CopyToAsync
(
serverStream
,
onDataSend
,
buffer
Pool
,
buffer
Size
,
cancellationTokenSource
.
Token
);
var
receiveRelay
=
var
receiveRelay
=
serverStream
.
CopyToAsync
(
clientStream
,
onDataReceive
,
bufferSize
,
cancellationTokenSource
.
Token
);
serverStream
.
CopyToAsync
(
clientStream
,
onDataReceive
,
buffer
Pool
,
buffer
Size
,
cancellationTokenSource
.
Token
);
await
Task
.
WhenAny
(
sendRelay
,
receiveRelay
);
await
Task
.
WhenAny
(
sendRelay
,
receiveRelay
);
cancellationTokenSource
.
Cancel
();
cancellationTokenSource
.
Cancel
();
...
@@ -244,13 +244,14 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -244,13 +244,14 @@ namespace Titanium.Web.Proxy.Helpers
/// <param name="cancellationTokenSource"></param>
/// <param name="cancellationTokenSource"></param>
/// <param name="exceptionFunc"></param>
/// <param name="exceptionFunc"></param>
/// <returns></returns>
/// <returns></returns>
internal
static
Task
SendRaw
(
Stream
clientStream
,
Stream
serverStream
,
int
bufferSize
,
internal
static
Task
SendRaw
(
Stream
clientStream
,
Stream
serverStream
,
IBufferPool
bufferPool
,
int
bufferSize
,
Action
<
byte
[],
int
,
int
>
onDataSend
,
Action
<
byte
[],
int
,
int
>
onDataReceive
,
Action
<
byte
[],
int
,
int
>
onDataSend
,
Action
<
byte
[],
int
,
int
>
onDataReceive
,
CancellationTokenSource
cancellationTokenSource
,
CancellationTokenSource
cancellationTokenSource
,
ExceptionHandler
exceptionFunc
)
ExceptionHandler
exceptionFunc
)
{
{
// todo: fix APM mode
// todo: fix APM mode
return
sendRawTap
(
clientStream
,
serverStream
,
bufferSize
,
onDataSend
,
onDataReceive
,
return
sendRawTap
(
clientStream
,
serverStream
,
buffer
Pool
,
buffer
Size
,
onDataSend
,
onDataReceive
,
cancellationTokenSource
,
cancellationTokenSource
,
exceptionFunc
);
exceptionFunc
);
}
}
...
...
Titanium.Web.Proxy/Http/HttpWebClient.cs
View file @
2c9cdab7
...
@@ -17,7 +17,7 @@ namespace Titanium.Web.Proxy.Http
...
@@ -17,7 +17,7 @@ namespace Titanium.Web.Proxy.Http
public
class
HttpWebClient
public
class
HttpWebClient
{
{
internal
HttpWebClient
(
int
bufferSize
,
Request
request
=
null
,
Response
response
=
null
)
internal
HttpWebClient
(
Request
request
=
null
,
Response
response
=
null
)
{
{
Request
=
request
??
new
Request
();
Request
=
request
??
new
Request
();
Response
=
response
??
new
Response
();
Response
=
response
??
new
Response
();
...
...
Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs
View file @
2c9cdab7
...
@@ -247,11 +247,11 @@ namespace Titanium.Web.Proxy.Network.Tcp
...
@@ -247,11 +247,11 @@ namespace Titanium.Web.Proxy.Network.Tcp
await
tcpClient
.
ConnectAsync
(
remoteHostName
,
remotePort
);
await
tcpClient
.
ConnectAsync
(
remoteHostName
,
remotePort
);
}
}
stream
=
new
CustomBufferedStream
(
tcpClient
.
GetStream
(),
proxyServer
.
BufferSize
);
stream
=
new
CustomBufferedStream
(
tcpClient
.
GetStream
(),
proxyServer
.
Buffer
Pool
,
proxyServer
.
Buffer
Size
);
if
(
useUpstreamProxy
&&
(
isConnect
||
isHttps
))
if
(
useUpstreamProxy
&&
(
isConnect
||
isHttps
))
{
{
var
writer
=
new
HttpRequestWriter
(
stream
,
proxyServer
.
BufferSize
);
var
writer
=
new
HttpRequestWriter
(
stream
,
proxyServer
.
Buffer
Pool
,
proxyServer
.
Buffer
Size
);
var
connectRequest
=
new
ConnectRequest
var
connectRequest
=
new
ConnectRequest
{
{
OriginalUrl
=
$"
{
remoteHostName
}
:
{
remotePort
}
"
,
OriginalUrl
=
$"
{
remoteHostName
}
:
{
remotePort
}
"
,
...
@@ -286,7 +286,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
...
@@ -286,7 +286,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
{
{
var
sslStream
=
new
SslStream
(
stream
,
false
,
proxyServer
.
ValidateServerCertificate
,
var
sslStream
=
new
SslStream
(
stream
,
false
,
proxyServer
.
ValidateServerCertificate
,
proxyServer
.
SelectClientCertificate
);
proxyServer
.
SelectClientCertificate
);
stream
=
new
CustomBufferedStream
(
sslStream
,
proxyServer
.
BufferSize
);
stream
=
new
CustomBufferedStream
(
sslStream
,
proxyServer
.
Buffer
Pool
,
proxyServer
.
Buffer
Size
);
var
options
=
new
SslClientAuthenticationOptions
var
options
=
new
SslClientAuthenticationOptions
{
{
...
@@ -318,7 +318,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
...
@@ -318,7 +318,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
IsHttps
=
isHttps
,
IsHttps
=
isHttps
,
NegotiatedApplicationProtocol
=
negotiatedApplicationProtocol
,
NegotiatedApplicationProtocol
=
negotiatedApplicationProtocol
,
UseUpstreamProxy
=
useUpstreamProxy
,
UseUpstreamProxy
=
useUpstreamProxy
,
StreamWriter
=
new
HttpRequestWriter
(
stream
,
proxyServer
.
BufferSize
),
StreamWriter
=
new
HttpRequestWriter
(
stream
,
proxyServer
.
Buffer
Pool
,
proxyServer
.
Buffer
Size
),
Stream
=
stream
,
Stream
=
stream
,
Version
=
httpVersion
Version
=
httpVersion
};
};
...
...
Titanium.Web.Proxy/ProxyServer.cs
View file @
2c9cdab7
...
@@ -7,6 +7,7 @@ using System.Security.Authentication;
...
@@ -7,6 +7,7 @@ using System.Security.Authentication;
using
System.Security.Cryptography.X509Certificates
;
using
System.Security.Cryptography.X509Certificates
;
using
System.Threading
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
using
StreamExtended
;
using
StreamExtended.Network
;
using
StreamExtended.Network
;
using
Titanium.Web.Proxy.EventArguments
;
using
Titanium.Web.Proxy.EventArguments
;
using
Titanium.Web.Proxy.Extensions
;
using
Titanium.Web.Proxy.Extensions
;
...
@@ -15,7 +16,6 @@ using Titanium.Web.Proxy.Helpers.WinHttp;
...
@@ -15,7 +16,6 @@ using Titanium.Web.Proxy.Helpers.WinHttp;
using
Titanium.Web.Proxy.Models
;
using
Titanium.Web.Proxy.Models
;
using
Titanium.Web.Proxy.Network
;
using
Titanium.Web.Proxy.Network
;
using
Titanium.Web.Proxy.Network.Tcp
;
using
Titanium.Web.Proxy.Network.Tcp
;
using
Titanium.Web.Proxy.Network.WinAuth.Security
;
namespace
Titanium.Web.Proxy
namespace
Titanium.Web.Proxy
{
{
...
@@ -97,6 +97,11 @@ namespace Titanium.Web.Proxy
...
@@ -97,6 +97,11 @@ namespace Titanium.Web.Proxy
// default values
// default values
ConnectionTimeOutSeconds
=
60
;
ConnectionTimeOutSeconds
=
60
;
if
(
BufferPool
==
null
)
{
BufferPool
=
new
DefaultBufferPool
();
}
ProxyEndPoints
=
new
List
<
ProxyEndPoint
>();
ProxyEndPoints
=
new
List
<
ProxyEndPoint
>();
tcpConnectionFactory
=
new
TcpConnectionFactory
(
this
);
tcpConnectionFactory
=
new
TcpConnectionFactory
(
this
);
if
(!
RunTime
.
IsRunningOnMono
&&
RunTime
.
IsWindows
)
if
(!
RunTime
.
IsRunningOnMono
&&
RunTime
.
IsWindows
)
...
@@ -197,6 +202,11 @@ namespace Titanium.Web.Proxy
...
@@ -197,6 +202,11 @@ namespace Titanium.Web.Proxy
#endif
#endif
SslProtocols
.
Tls
|
SslProtocols
.
Tls11
|
SslProtocols
.
Tls12
;
SslProtocols
.
Tls
|
SslProtocols
.
Tls11
|
SslProtocols
.
Tls12
;
/// <summary>
/// The buffer pool used throughout this proxy instance.
/// </summary>
public
IBufferPool
BufferPool
{
get
;
set
;
}
/// <summary>
/// <summary>
/// Manages certificates used by this proxy.
/// Manages certificates used by this proxy.
/// </summary>
/// </summary>
...
...
Titanium.Web.Proxy/RequestHandler.cs
View file @
2c9cdab7
...
@@ -71,7 +71,7 @@ namespace Titanium.Web.Proxy
...
@@ -71,7 +71,7 @@ namespace Titanium.Web.Proxy
return
;
return
;
}
}
var
args
=
new
SessionEventArgs
(
BufferSize
,
endPoint
,
cancellationTokenSource
,
ExceptionFunc
)
var
args
=
new
SessionEventArgs
(
this
,
endPoint
,
cancellationTokenSource
)
{
{
ProxyClient
=
{
ClientConnection
=
clientConnection
},
ProxyClient
=
{
ClientConnection
=
clientConnection
},
WebSession
=
{
ConnectRequest
=
connectRequest
}
WebSession
=
{
ConnectRequest
=
connectRequest
}
...
@@ -482,7 +482,7 @@ namespace Titanium.Web.Proxy
...
@@ -482,7 +482,7 @@ namespace Titanium.Web.Proxy
await
invokeBeforeResponse
(
args
);
await
invokeBeforeResponse
(
args
);
}
}
await
TcpHelper
.
SendRaw
(
clientStream
,
serverConnection
.
Stream
,
BufferSize
,
await
TcpHelper
.
SendRaw
(
clientStream
,
serverConnection
.
Stream
,
Buffer
Pool
,
Buffer
Size
,
(
buffer
,
offset
,
count
)
=>
{
args
.
OnDataSent
(
buffer
,
offset
,
count
);
},
(
buffer
,
offset
,
count
)
=>
{
args
.
OnDataSent
(
buffer
,
offset
,
count
);
},
(
buffer
,
offset
,
count
)
=>
{
args
.
OnDataReceived
(
buffer
,
offset
,
count
);
},
(
buffer
,
offset
,
count
)
=>
{
args
.
OnDataReceived
(
buffer
,
offset
,
count
);
},
cancellationTokenSource
,
ExceptionFunc
);
cancellationTokenSource
,
ExceptionFunc
);
...
...
Titanium.Web.Proxy/Titanium.Web.Proxy.csproj
View file @
2c9cdab7
...
@@ -13,7 +13,7 @@
...
@@ -13,7 +13,7 @@
<ItemGroup>
<ItemGroup>
<PackageReference Include="Portable.BouncyCastle" Version="1.8.2" />
<PackageReference Include="Portable.BouncyCastle" Version="1.8.2" />
<PackageReference Include="StreamExtended" Version="1.0.1
67
-beta" />
<PackageReference Include="StreamExtended" Version="1.0.1
70
-beta" />
</ItemGroup>
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
...
...
Titanium.Web.Proxy/TransparentClientHandler.cs
View file @
2c9cdab7
...
@@ -6,7 +6,6 @@ using System.Security.Authentication;
...
@@ -6,7 +6,6 @@ using System.Security.Authentication;
using
System.Threading
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
using
StreamExtended
;
using
StreamExtended
;
using
StreamExtended.Helpers
;
using
StreamExtended.Network
;
using
StreamExtended.Network
;
using
Titanium.Web.Proxy.EventArguments
;
using
Titanium.Web.Proxy.EventArguments
;
using
Titanium.Web.Proxy.Exceptions
;
using
Titanium.Web.Proxy.Exceptions
;
...
@@ -31,13 +30,13 @@ namespace Titanium.Web.Proxy
...
@@ -31,13 +30,13 @@ namespace Titanium.Web.Proxy
var
cancellationTokenSource
=
new
CancellationTokenSource
();
var
cancellationTokenSource
=
new
CancellationTokenSource
();
var
cancellationToken
=
cancellationTokenSource
.
Token
;
var
cancellationToken
=
cancellationTokenSource
.
Token
;
var
clientStream
=
new
CustomBufferedStream
(
clientConnection
.
GetStream
(),
BufferSize
);
var
clientStream
=
new
CustomBufferedStream
(
clientConnection
.
GetStream
(),
Buffer
Pool
,
Buffer
Size
);
var
clientStreamWriter
=
new
HttpResponseWriter
(
clientStream
,
BufferSize
);
var
clientStreamWriter
=
new
HttpResponseWriter
(
clientStream
,
Buffer
Pool
,
Buffer
Size
);
try
try
{
{
var
clientHelloInfo
=
await
SslTools
.
PeekClientHello
(
clientStream
,
cancellationToken
);
var
clientHelloInfo
=
await
SslTools
.
PeekClientHello
(
clientStream
,
BufferPool
,
cancellationToken
);
bool
isHttps
=
clientHelloInfo
!=
null
;
bool
isHttps
=
clientHelloInfo
!=
null
;
string
httpsHostName
=
null
;
string
httpsHostName
=
null
;
...
@@ -73,9 +72,9 @@ namespace Titanium.Web.Proxy
...
@@ -73,9 +72,9 @@ namespace Titanium.Web.Proxy
await
sslStream
.
AuthenticateAsServerAsync
(
certificate
,
false
,
SslProtocols
.
Tls
,
false
);
await
sslStream
.
AuthenticateAsServerAsync
(
certificate
,
false
,
SslProtocols
.
Tls
,
false
);
// HTTPS server created - we can now decrypt the client's traffic
// HTTPS server created - we can now decrypt the client's traffic
clientStream
=
new
CustomBufferedStream
(
sslStream
,
BufferSize
);
clientStream
=
new
CustomBufferedStream
(
sslStream
,
Buffer
Pool
,
Buffer
Size
);
clientStreamWriter
=
new
HttpResponseWriter
(
clientStream
,
BufferSize
);
clientStreamWriter
=
new
HttpResponseWriter
(
clientStream
,
Buffer
Pool
,
Buffer
Size
);
}
}
catch
(
Exception
e
)
catch
(
Exception
e
)
{
{
...
@@ -113,7 +112,7 @@ namespace Titanium.Web.Proxy
...
@@ -113,7 +112,7 @@ namespace Titanium.Web.Proxy
}
}
}
}
await
TcpHelper
.
SendRaw
(
clientStream
,
serverStream
,
BufferSize
,
await
TcpHelper
.
SendRaw
(
clientStream
,
serverStream
,
Buffer
Pool
,
Buffer
Size
,
null
,
null
,
cancellationTokenSource
,
ExceptionFunc
);
null
,
null
,
cancellationTokenSource
,
ExceptionFunc
);
tcpConnectionFactory
.
Release
(
connection
,
true
);
tcpConnectionFactory
.
Release
(
connection
,
true
);
...
...
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