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
30125ee1
Commit
30125ee1
authored
May 16, 2017
by
Jehonathan Thomas
Committed by
GitHub
May 16, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #229 from honfika/develop
reuse buffers, missing dispose added
parents
fe81398b
0ce775eb
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
27 additions
and
14 deletions
+27
-14
SessionEventArgs.cs
Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs
+1
-0
CustomBinaryReader.cs
Titanium.Web.Proxy/Helpers/CustomBinaryReader.cs
+8
-1
HttpWebClient.cs
Titanium.Web.Proxy/Http/HttpWebClient.cs
+8
-1
RequestHandler.cs
Titanium.Web.Proxy/RequestHandler.cs
+10
-12
No files found.
Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs
View file @
30125ee1
...
...
@@ -522,6 +522,7 @@ namespace Titanium.Web.Proxy.EventArguments
/// </summary>
public
void
Dispose
()
{
WebSession
.
Dispose
();
}
}
}
Titanium.Web.Proxy/Helpers/CustomBinaryReader.cs
View file @
30125ee1
using
System
;
using
System.Collections.Concurrent
;
using
System.Collections.Generic
;
using
System.IO
;
using
System.Text
;
...
...
@@ -18,10 +19,15 @@ namespace Titanium.Web.Proxy.Helpers
private
readonly
byte
[]
staticBuffer
;
private
readonly
Encoding
encoding
;
private
static
readonly
ConcurrentQueue
<
byte
[
]>
buffers
=
new
ConcurrentQueue
<
byte
[
]>
();
internal
CustomBinaryReader
(
CustomBufferedStream
stream
,
int
bufferSize
)
{
this
.
stream
=
stream
;
staticBuffer
=
new
byte
[
bufferSize
];
if
(!
buffers
.
TryDequeue
(
out
staticBuffer
)
||
staticBuffer
.
Length
!=
bufferSize
)
{
staticBuffer
=
new
byte
[
bufferSize
];
}
this
.
bufferSize
=
bufferSize
;
...
...
@@ -148,6 +154,7 @@ namespace Titanium.Web.Proxy.Helpers
public
void
Dispose
()
{
buffers
.
Enqueue
(
staticBuffer
);
}
private
void
ResizeBuffer
(
ref
byte
[]
buffer
,
long
size
)
...
...
Titanium.Web.Proxy/Http/HttpWebClient.cs
View file @
30125ee1
...
...
@@ -11,7 +11,7 @@ namespace Titanium.Web.Proxy.Http
/// <summary>
/// Used to communicate with the server over HTTP(S)
/// </summary>
public
class
HttpWebClient
public
class
HttpWebClient
:
IDisposable
{
/// <summary>
/// Connection to server
...
...
@@ -208,5 +208,12 @@ namespace Titanium.Web.Proxy.Http
//Read the response headers in to unique and non-unique header collections
await
HeaderParser
.
ReadHeaders
(
ServerConnection
.
StreamReader
,
Response
.
NonUniqueResponseHeaders
,
Response
.
ResponseHeaders
);
}
/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
public
void
Dispose
()
{
}
}
}
Titanium.Web.Proxy/RequestHandler.cs
View file @
30125ee1
...
...
@@ -44,7 +44,6 @@ namespace Titanium.Web.Proxy
if
(
string
.
IsNullOrEmpty
(
httpCmd
))
{
Dispose
(
clientStream
,
clientStreamReader
,
clientStreamWriter
,
null
);
return
;
}
...
...
@@ -99,7 +98,6 @@ namespace Titanium.Web.Proxy
if
(
await
CheckAuthorization
(
clientStreamWriter
,
connectRequestHeaders
)
==
false
)
{
Dispose
(
clientStream
,
clientStreamReader
,
clientStreamWriter
,
null
);
return
;
}
...
...
@@ -111,7 +109,8 @@ namespace Titanium.Web.Proxy
{
sslStream
=
new
SslStream
(
clientStream
,
true
);
var
certificate
=
endPoint
.
GenericCertificate
??
CertificateManager
.
CreateCertificate
(
httpRemoteUri
.
Host
,
false
);
var
certificate
=
endPoint
.
GenericCertificate
??
CertificateManager
.
CreateCertificate
(
httpRemoteUri
.
Host
,
false
);
//Successfully managed to authenticate the client using the fake certificate
await
sslStream
.
AuthenticateAsServerAsync
(
certificate
,
false
,
...
...
@@ -119,14 +118,13 @@ namespace Titanium.Web.Proxy
//HTTPS server created - we can now decrypt the client's traffic
clientStream
=
new
CustomBufferedStream
(
sslStream
,
BufferSize
);
clientStreamReader
.
Dispose
();
clientStreamReader
=
new
CustomBinaryReader
(
clientStream
,
BufferSize
);
clientStreamWriter
=
new
StreamWriter
(
clientStream
)
{
NewLine
=
ProxyConstants
.
NewLine
};
clientStreamWriter
=
new
StreamWriter
(
clientStream
)
{
NewLine
=
ProxyConstants
.
NewLine
};
}
catch
{
sslStream
?.
Dispose
();
Dispose
(
clientStream
,
clientStreamReader
,
clientStreamWriter
,
null
);
return
;
}
...
...
@@ -147,18 +145,19 @@ namespace Titanium.Web.Proxy
false
,
clientStream
,
tcpConnectionFactory
);
Dispose
(
clientStream
,
clientStreamReader
,
clientStreamWriter
,
null
);
return
;
}
//Now create the request
await
HandleHttpSessionRequest
(
tcpClient
,
httpCmd
,
clientStream
,
clientStreamReader
,
clientStreamWriter
,
httpRemoteUri
.
Scheme
==
Uri
.
UriSchemeHttps
?
httpRemoteUri
.
Host
:
null
,
endPoint
,
connectRequestHeaders
);
httpRemoteUri
.
Scheme
==
Uri
.
UriSchemeHttps
?
httpRemoteUri
.
Host
:
null
,
endPoint
,
connectRequestHeaders
);
}
catch
(
Exception
)
{
Dispose
(
clientStream
,
clientStreamReader
,
clientStreamWriter
,
null
);
}
finally
{
Dispose
(
clientStream
,
clientStreamReader
,
clientStreamWriter
,
null
);
}
}
...
...
@@ -563,7 +562,6 @@ namespace Titanium.Web.Proxy
break
;
}
}
}
/// <summary>
...
...
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