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
412b50b8
Commit
412b50b8
authored
May 15, 2017
by
Honfika
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
reuse buffers, missing dispose added
parent
81d32f79
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
30 additions
and
16 deletions
+30
-16
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
+9
-1
RequestHandler.cs
Titanium.Web.Proxy/RequestHandler.cs
+12
-14
No files found.
Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs
View file @
412b50b8
...
@@ -522,6 +522,7 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -522,6 +522,7 @@ namespace Titanium.Web.Proxy.EventArguments
/// </summary>
/// </summary>
public
void
Dispose
()
public
void
Dispose
()
{
{
WebSession
.
Dispose
();
}
}
}
}
}
}
Titanium.Web.Proxy/Helpers/CustomBinaryReader.cs
View file @
412b50b8
using
System
;
using
System
;
using
System.Collections.Concurrent
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
System.IO
;
using
System.IO
;
using
System.Text
;
using
System.Text
;
...
@@ -18,10 +19,15 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -18,10 +19,15 @@ namespace Titanium.Web.Proxy.Helpers
private
readonly
byte
[]
staticBuffer
;
private
readonly
byte
[]
staticBuffer
;
private
readonly
Encoding
encoding
;
private
readonly
Encoding
encoding
;
private
static
readonly
ConcurrentQueue
<
byte
[
]>
buffers
=
new
ConcurrentQueue
<
byte
[
]>
();
internal
CustomBinaryReader
(
CustomBufferedStream
stream
,
int
bufferSize
)
internal
CustomBinaryReader
(
CustomBufferedStream
stream
,
int
bufferSize
)
{
{
this
.
stream
=
stream
;
this
.
stream
=
stream
;
staticBuffer
=
new
byte
[
bufferSize
];
if
(!
buffers
.
TryDequeue
(
out
staticBuffer
)
||
staticBuffer
.
Length
!=
bufferSize
)
{
staticBuffer
=
new
byte
[
bufferSize
];
}
this
.
bufferSize
=
bufferSize
;
this
.
bufferSize
=
bufferSize
;
...
@@ -148,6 +154,7 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -148,6 +154,7 @@ namespace Titanium.Web.Proxy.Helpers
public
void
Dispose
()
public
void
Dispose
()
{
{
buffers
.
Enqueue
(
staticBuffer
);
}
}
private
void
ResizeBuffer
(
ref
byte
[]
buffer
,
long
size
)
private
void
ResizeBuffer
(
ref
byte
[]
buffer
,
long
size
)
...
...
Titanium.Web.Proxy/Http/HttpWebClient.cs
View file @
412b50b8
...
@@ -11,7 +11,7 @@ namespace Titanium.Web.Proxy.Http
...
@@ -11,7 +11,7 @@ namespace Titanium.Web.Proxy.Http
/// <summary>
/// <summary>
/// Used to communicate with the server over HTTP(S)
/// Used to communicate with the server over HTTP(S)
/// </summary>
/// </summary>
public
class
HttpWebClient
public
class
HttpWebClient
:
IDisposable
{
{
/// <summary>
/// <summary>
/// Connection to server
/// Connection to server
...
@@ -208,5 +208,13 @@ namespace Titanium.Web.Proxy.Http
...
@@ -208,5 +208,13 @@ namespace Titanium.Web.Proxy.Http
//Read the response headers in to unique and non-unique header collections
//Read the response headers in to unique and non-unique header collections
await
HeaderParser
.
ReadHeaders
(
ServerConnection
.
StreamReader
,
Response
.
NonUniqueResponseHeaders
,
Response
.
ResponseHeaders
);
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
()
{
ServerConnection
.
Dispose
();
}
}
}
}
}
Titanium.Web.Proxy/RequestHandler.cs
View file @
412b50b8
...
@@ -44,7 +44,6 @@ namespace Titanium.Web.Proxy
...
@@ -44,7 +44,6 @@ namespace Titanium.Web.Proxy
if
(
string
.
IsNullOrEmpty
(
httpCmd
))
if
(
string
.
IsNullOrEmpty
(
httpCmd
))
{
{
Dispose
(
clientStream
,
clientStreamReader
,
clientStreamWriter
,
null
);
return
;
return
;
}
}
...
@@ -99,7 +98,6 @@ namespace Titanium.Web.Proxy
...
@@ -99,7 +98,6 @@ namespace Titanium.Web.Proxy
if
(
await
CheckAuthorization
(
clientStreamWriter
,
connectRequestHeaders
)
==
false
)
if
(
await
CheckAuthorization
(
clientStreamWriter
,
connectRequestHeaders
)
==
false
)
{
{
Dispose
(
clientStream
,
clientStreamReader
,
clientStreamWriter
,
null
);
return
;
return
;
}
}
...
@@ -111,7 +109,8 @@ namespace Titanium.Web.Proxy
...
@@ -111,7 +109,8 @@ namespace Titanium.Web.Proxy
{
{
sslStream
=
new
SslStream
(
clientStream
,
true
);
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
//Successfully managed to authenticate the client using the fake certificate
await
sslStream
.
AuthenticateAsServerAsync
(
certificate
,
false
,
await
sslStream
.
AuthenticateAsServerAsync
(
certificate
,
false
,
...
@@ -119,14 +118,13 @@ namespace Titanium.Web.Proxy
...
@@ -119,14 +118,13 @@ namespace Titanium.Web.Proxy
//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
,
BufferSize
);
clientStreamReader
.
Dispose
();
clientStreamReader
=
new
CustomBinaryReader
(
clientStream
,
BufferSize
);
clientStreamReader
=
new
CustomBinaryReader
(
clientStream
,
BufferSize
);
clientStreamWriter
=
new
StreamWriter
(
clientStream
)
{
NewLine
=
ProxyConstants
.
NewLine
};
clientStreamWriter
=
new
StreamWriter
(
clientStream
)
{
NewLine
=
ProxyConstants
.
NewLine
};
}
}
catch
catch
{
{
sslStream
?.
Dispose
();
sslStream
?.
Dispose
();
Dispose
(
clientStream
,
clientStreamReader
,
clientStreamWriter
,
null
);
return
;
return
;
}
}
...
@@ -141,24 +139,25 @@ namespace Titanium.Web.Proxy
...
@@ -141,24 +139,25 @@ namespace Titanium.Web.Proxy
//write back successfull CONNECT response
//write back successfull CONNECT response
await
WriteConnectResponse
(
clientStreamWriter
,
version
);
await
WriteConnectResponse
(
clientStreamWriter
,
version
);
await
TcpHelper
.
SendRaw
(
this
,
await
TcpHelper
.
SendRaw
(
this
,
httpRemoteUri
.
Host
,
httpRemoteUri
.
Port
,
httpRemoteUri
.
Host
,
httpRemoteUri
.
Port
,
null
,
version
,
null
,
null
,
version
,
null
,
false
,
false
,
clientStream
,
tcpConnectionFactory
);
clientStream
,
tcpConnectionFactory
);
Dispose
(
clientStream
,
clientStreamReader
,
clientStreamWriter
,
null
);
return
;
return
;
}
}
//Now create the request
//Now create the request
await
HandleHttpSessionRequest
(
tcpClient
,
httpCmd
,
clientStream
,
clientStreamReader
,
clientStreamWriter
,
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
)
catch
(
Exception
)
{
{
Dispose
(
clientStream
,
}
clientStreamReader
,
finally
clientStreamWriter
,
null
);
{
Dispose
(
clientStream
,
clientStreamReader
,
clientStreamWriter
,
null
);
}
}
}
}
...
@@ -544,7 +543,6 @@ namespace Titanium.Web.Proxy
...
@@ -544,7 +543,6 @@ namespace Titanium.Web.Proxy
break
;
break
;
}
}
}
}
}
}
/// <summary>
/// <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