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
5494a981
Commit
5494a981
authored
Jul 17, 2017
by
justcoding121
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
unify buffer size
parent
ec38010b
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
28 additions
and
20 deletions
+28
-20
SessionEventArgs.cs
Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs
+1
-1
DotNet45Extensions.cs
Titanium.Web.Proxy/Extensions/DotNet45Extensions.cs
+1
-1
StreamExtensions.cs
Titanium.Web.Proxy/Extensions/StreamExtensions.cs
+2
-2
HttpRequestWriter.cs
Titanium.Web.Proxy/Helpers/HttpRequestWriter.cs
+2
-1
HttpResponseWriter.cs
Titanium.Web.Proxy/Helpers/HttpResponseWriter.cs
+2
-1
HttpWriter.cs
Titanium.Web.Proxy/Helpers/HttpWriter.cs
+2
-1
Tcp.cs
Titanium.Web.Proxy/Helpers/Tcp.cs
+4
-3
HttpWebClient.cs
Titanium.Web.Proxy/Http/HttpWebClient.cs
+6
-2
TcpConnectionFactory.cs
Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs
+1
-1
RequestHandler.cs
Titanium.Web.Proxy/RequestHandler.cs
+6
-6
Titanium.Web.Proxy.csproj
Titanium.Web.Proxy/Titanium.Web.Proxy.csproj
+1
-1
No files found.
Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs
View file @
5494a981
...
@@ -104,7 +104,7 @@ namespace Titanium.Web.Proxy.EventArguments
...
@@ -104,7 +104,7 @@ namespace Titanium.Web.Proxy.EventArguments
this
.
httpResponseHandler
=
httpResponseHandler
;
this
.
httpResponseHandler
=
httpResponseHandler
;
ProxyClient
=
new
ProxyClient
();
ProxyClient
=
new
ProxyClient
();
WebSession
=
new
HttpWebClient
();
WebSession
=
new
HttpWebClient
(
bufferSize
);
WebSession
.
ProcessId
=
new
Lazy
<
int
>(()
=>
WebSession
.
ProcessId
=
new
Lazy
<
int
>(()
=>
{
{
...
...
Titanium.Web.Proxy/Extensions/DotNet
Standard
Extensions.cs
→
Titanium.Web.Proxy/Extensions/DotNet
45
Extensions.cs
View file @
5494a981
...
@@ -3,7 +3,7 @@ using System.Security.Cryptography.X509Certificates;
...
@@ -3,7 +3,7 @@ using System.Security.Cryptography.X509Certificates;
namespace
Titanium.Web.Proxy.Extensions
namespace
Titanium.Web.Proxy.Extensions
{
{
internal
static
class
DotNet
Standard
Extensions
internal
static
class
DotNet
45
Extensions
{
{
#if NET45
#if NET45
/// <summary>
/// <summary>
...
...
Titanium.Web.Proxy/Extensions/StreamExtensions.cs
View file @
5494a981
...
@@ -17,9 +17,9 @@ namespace Titanium.Web.Proxy.Extensions
...
@@ -17,9 +17,9 @@ namespace Titanium.Web.Proxy.Extensions
/// <param name="input"></param>
/// <param name="input"></param>
/// <param name="output"></param>
/// <param name="output"></param>
/// <param name="onCopy"></param>
/// <param name="onCopy"></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
)
{
{
byte
[]
buffer
=
new
byte
[
81920
];
byte
[]
buffer
=
new
byte
[
bufferSize
];
while
(
true
)
while
(
true
)
{
{
int
num
=
await
input
.
ReadAsync
(
buffer
,
0
,
buffer
.
Length
).
ConfigureAwait
(
false
);
int
num
=
await
input
.
ReadAsync
(
buffer
,
0
,
buffer
.
Length
).
ConfigureAwait
(
false
);
...
...
Titanium.Web.Proxy/Helpers/HttpRequestWriter.cs
View file @
5494a981
...
@@ -4,7 +4,8 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -4,7 +4,8 @@ namespace Titanium.Web.Proxy.Helpers
{
{
sealed
class
HttpRequestWriter
:
HttpWriter
sealed
class
HttpRequestWriter
:
HttpWriter
{
{
public
HttpRequestWriter
(
Stream
stream
)
:
base
(
stream
,
true
)
public
HttpRequestWriter
(
Stream
stream
,
int
bufferSize
)
:
base
(
stream
,
bufferSize
,
true
)
{
{
}
}
}
}
...
...
Titanium.Web.Proxy/Helpers/HttpResponseWriter.cs
View file @
5494a981
...
@@ -12,7 +12,8 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -12,7 +12,8 @@ namespace Titanium.Web.Proxy.Helpers
{
{
sealed
class
HttpResponseWriter
:
HttpWriter
sealed
class
HttpResponseWriter
:
HttpWriter
{
{
public
HttpResponseWriter
(
Stream
stream
)
:
base
(
stream
,
true
)
public
HttpResponseWriter
(
Stream
stream
,
int
bufferSize
)
:
base
(
stream
,
bufferSize
,
true
)
{
{
}
}
...
...
Titanium.Web.Proxy/Helpers/HttpWriter.cs
View file @
5494a981
...
@@ -8,7 +8,8 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -8,7 +8,8 @@ namespace Titanium.Web.Proxy.Helpers
{
{
abstract
class
HttpWriter
:
StreamWriter
abstract
class
HttpWriter
:
StreamWriter
{
{
protected
HttpWriter
(
Stream
stream
,
bool
leaveOpen
)
:
base
(
stream
,
Encoding
.
ASCII
,
1024
,
leaveOpen
)
protected
HttpWriter
(
Stream
stream
,
int
bufferSize
,
bool
leaveOpen
)
:
base
(
stream
,
Encoding
.
ASCII
,
bufferSize
,
leaveOpen
)
{
{
NewLine
=
ProxyConstants
.
NewLine
;
NewLine
=
ProxyConstants
.
NewLine
;
}
}
...
...
Titanium.Web.Proxy/Helpers/Tcp.cs
View file @
5494a981
...
@@ -116,12 +116,13 @@ namespace Titanium.Web.Proxy.Helpers
...
@@ -116,12 +116,13 @@ namespace Titanium.Web.Proxy.Helpers
/// <param name="onDataSend"></param>
/// <param name="onDataSend"></param>
/// <param name="onDataReceive"></param>
/// <param name="onDataReceive"></param>
/// <returns></returns>
/// <returns></returns>
internal
static
async
Task
SendRaw
(
Stream
clientStream
,
Stream
serverStream
,
Action
<
byte
[],
int
,
int
>
onDataSend
,
Action
<
byte
[],
int
,
int
>
onDataReceive
)
internal
static
async
Task
SendRaw
(
Stream
clientStream
,
Stream
serverStream
,
int
bufferSize
,
Action
<
byte
[],
int
,
int
>
onDataSend
,
Action
<
byte
[],
int
,
int
>
onDataReceive
)
{
{
//Now async relay all server=>client & client=>server data
//Now async relay all server=>client & client=>server data
var
sendRelay
=
clientStream
.
CopyToAsync
(
serverStream
,
onDataSend
);
var
sendRelay
=
clientStream
.
CopyToAsync
(
serverStream
,
onDataSend
,
bufferSize
);
var
receiveRelay
=
serverStream
.
CopyToAsync
(
clientStream
,
onDataReceive
);
var
receiveRelay
=
serverStream
.
CopyToAsync
(
clientStream
,
onDataReceive
,
bufferSize
);
await
Task
.
WhenAll
(
sendRelay
,
receiveRelay
);
await
Task
.
WhenAll
(
sendRelay
,
receiveRelay
);
}
}
...
...
Titanium.Web.Proxy/Http/HttpWebClient.cs
View file @
5494a981
...
@@ -13,6 +13,8 @@ namespace Titanium.Web.Proxy.Http
...
@@ -13,6 +13,8 @@ namespace Titanium.Web.Proxy.Http
/// </summary>
/// </summary>
public
class
HttpWebClient
:
IDisposable
public
class
HttpWebClient
:
IDisposable
{
{
private
int
bufferSize
;
/// <summary>
/// <summary>
/// Connection to server
/// Connection to server
/// </summary>
/// </summary>
...
@@ -49,8 +51,10 @@ namespace Titanium.Web.Proxy.Http
...
@@ -49,8 +51,10 @@ namespace Titanium.Web.Proxy.Http
/// </summary>
/// </summary>
public
bool
IsHttps
=>
Request
.
IsHttps
;
public
bool
IsHttps
=>
Request
.
IsHttps
;
internal
HttpWebClient
()
internal
HttpWebClient
(
int
bufferSize
)
{
{
this
.
bufferSize
=
bufferSize
;
RequestId
=
Guid
.
NewGuid
();
RequestId
=
Guid
.
NewGuid
();
Request
=
new
Request
();
Request
=
new
Request
();
Response
=
new
Response
();
Response
=
new
Response
();
...
@@ -77,7 +81,7 @@ namespace Titanium.Web.Proxy.Http
...
@@ -77,7 +81,7 @@ namespace Titanium.Web.Proxy.Http
byte
[]
requestBytes
;
byte
[]
requestBytes
;
using
(
var
ms
=
new
MemoryStream
())
using
(
var
ms
=
new
MemoryStream
())
using
(
var
writer
=
new
HttpRequestWriter
(
ms
))
using
(
var
writer
=
new
HttpRequestWriter
(
ms
,
bufferSize
))
{
{
var
upstreamProxy
=
ServerConnection
.
UpStreamHttpProxy
;
var
upstreamProxy
=
ServerConnection
.
UpStreamHttpProxy
;
...
...
Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs
View file @
5494a981
...
@@ -72,7 +72,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
...
@@ -72,7 +72,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
if
(
useUpstreamProxy
&&
(
isConnect
||
isHttps
))
if
(
useUpstreamProxy
&&
(
isConnect
||
isHttps
))
{
{
using
(
var
writer
=
new
HttpRequestWriter
(
stream
))
using
(
var
writer
=
new
HttpRequestWriter
(
stream
,
server
.
BufferSize
))
{
{
await
writer
.
WriteLineAsync
(
$"CONNECT
{
remoteHostName
}
:
{
remotePort
}
HTTP/
{
httpVersion
}
"
);
await
writer
.
WriteLineAsync
(
$"CONNECT
{
remoteHostName
}
:
{
remotePort
}
HTTP/
{
httpVersion
}
"
);
await
writer
.
WriteLineAsync
(
$"Host:
{
remoteHostName
}
:
{
remotePort
}
"
);
await
writer
.
WriteLineAsync
(
$"Host:
{
remoteHostName
}
:
{
remotePort
}
"
);
...
...
Titanium.Web.Proxy/RequestHandler.cs
View file @
5494a981
...
@@ -37,7 +37,7 @@ namespace Titanium.Web.Proxy
...
@@ -37,7 +37,7 @@ namespace Titanium.Web.Proxy
var
clientStream
=
new
CustomBufferedStream
(
tcpClient
.
GetStream
(),
BufferSize
);
var
clientStream
=
new
CustomBufferedStream
(
tcpClient
.
GetStream
(),
BufferSize
);
var
clientStreamReader
=
new
CustomBinaryReader
(
clientStream
,
BufferSize
);
var
clientStreamReader
=
new
CustomBinaryReader
(
clientStream
,
BufferSize
);
var
clientStreamWriter
=
new
HttpResponseWriter
(
clientStream
);
var
clientStreamWriter
=
new
HttpResponseWriter
(
clientStream
,
BufferSize
);
Uri
httpRemoteUri
;
Uri
httpRemoteUri
;
...
@@ -147,7 +147,7 @@ namespace Titanium.Web.Proxy
...
@@ -147,7 +147,7 @@ namespace Titanium.Web.Proxy
clientStreamReader
.
Dispose
();
clientStreamReader
.
Dispose
();
clientStreamReader
=
new
CustomBinaryReader
(
clientStream
,
BufferSize
);
clientStreamReader
=
new
CustomBinaryReader
(
clientStream
,
BufferSize
);
clientStreamWriter
=
new
HttpResponseWriter
(
clientStream
);
clientStreamWriter
=
new
HttpResponseWriter
(
clientStream
,
BufferSize
);
}
}
catch
catch
{
{
...
@@ -179,7 +179,7 @@ namespace Titanium.Web.Proxy
...
@@ -179,7 +179,7 @@ namespace Titanium.Web.Proxy
((
ConnectResponse
)
connectArgs
.
WebSession
.
Response
).
ServerHelloInfo
=
serverHelloInfo
;
((
ConnectResponse
)
connectArgs
.
WebSession
.
Response
).
ServerHelloInfo
=
serverHelloInfo
;
}
}
await
TcpHelper
.
SendRaw
(
clientStream
,
connection
.
Stream
,
await
TcpHelper
.
SendRaw
(
clientStream
,
connection
.
Stream
,
BufferSize
,
(
buffer
,
offset
,
count
)
=>
{
connectArgs
.
OnDataSent
(
buffer
,
offset
,
count
);
},
(
buffer
,
offset
,
count
)
=>
{
connectArgs
.
OnDataReceived
(
buffer
,
offset
,
count
);
});
(
buffer
,
offset
,
count
)
=>
{
connectArgs
.
OnDataSent
(
buffer
,
offset
,
count
);
},
(
buffer
,
offset
,
count
)
=>
{
connectArgs
.
OnDataReceived
(
buffer
,
offset
,
count
);
});
UpdateServerConnectionCount
(
false
);
UpdateServerConnectionCount
(
false
);
}
}
...
@@ -243,7 +243,7 @@ namespace Titanium.Web.Proxy
...
@@ -243,7 +243,7 @@ namespace Titanium.Web.Proxy
}
}
clientStreamReader
=
new
CustomBinaryReader
(
clientStream
,
BufferSize
);
clientStreamReader
=
new
CustomBinaryReader
(
clientStream
,
BufferSize
);
clientStreamWriter
=
new
HttpResponseWriter
(
clientStream
);
clientStreamWriter
=
new
HttpResponseWriter
(
clientStream
,
BufferSize
);
//now read the request line
//now read the request line
string
httpCmd
=
await
clientStreamReader
.
ReadLineAsync
();
string
httpCmd
=
await
clientStreamReader
.
ReadLineAsync
();
...
@@ -374,7 +374,7 @@ namespace Titanium.Web.Proxy
...
@@ -374,7 +374,7 @@ namespace Titanium.Web.Proxy
var
requestHeaders
=
args
.
WebSession
.
Request
.
RequestHeaders
;
var
requestHeaders
=
args
.
WebSession
.
Request
.
RequestHeaders
;
byte
[]
requestBytes
;
byte
[]
requestBytes
;
using
(
var
ms
=
new
MemoryStream
())
using
(
var
ms
=
new
MemoryStream
())
using
(
var
writer
=
new
HttpRequestWriter
(
ms
))
using
(
var
writer
=
new
HttpRequestWriter
(
ms
,
BufferSize
))
{
{
writer
.
WriteLine
(
httpCmd
);
writer
.
WriteLine
(
httpCmd
);
writer
.
WriteHeaders
(
requestHeaders
);
writer
.
WriteHeaders
(
requestHeaders
);
...
@@ -402,7 +402,7 @@ namespace Titanium.Web.Proxy
...
@@ -402,7 +402,7 @@ namespace Titanium.Web.Proxy
await
BeforeResponse
.
InvokeParallelAsync
(
this
,
args
,
ExceptionFunc
);
await
BeforeResponse
.
InvokeParallelAsync
(
this
,
args
,
ExceptionFunc
);
}
}
await
TcpHelper
.
SendRaw
(
clientStream
,
connection
.
Stream
,
await
TcpHelper
.
SendRaw
(
clientStream
,
connection
.
Stream
,
BufferSize
,
(
buffer
,
offset
,
count
)
=>
{
args
.
OnDataSent
(
buffer
,
offset
,
count
);
},
(
buffer
,
offset
,
count
)
=>
{
args
.
OnDataReceived
(
buffer
,
offset
,
count
);
});
(
buffer
,
offset
,
count
)
=>
{
args
.
OnDataSent
(
buffer
,
offset
,
count
);
},
(
buffer
,
offset
,
count
)
=>
{
args
.
OnDataReceived
(
buffer
,
offset
,
count
);
});
args
.
Dispose
();
args
.
Dispose
();
...
...
Titanium.Web.Proxy/Titanium.Web.Proxy.csproj
View file @
5494a981
...
@@ -84,7 +84,7 @@
...
@@ -84,7 +84,7 @@
<Compile
Include=
"Exceptions\ProxyException.cs"
/>
<Compile
Include=
"Exceptions\ProxyException.cs"
/>
<Compile
Include=
"Exceptions\ProxyHttpException.cs"
/>
<Compile
Include=
"Exceptions\ProxyHttpException.cs"
/>
<Compile
Include=
"Extensions\ByteArrayExtensions.cs"
/>
<Compile
Include=
"Extensions\ByteArrayExtensions.cs"
/>
<Compile
Include=
"Extensions\DotNet
Standard
Extensions.cs"
/>
<Compile
Include=
"Extensions\DotNet
45
Extensions.cs"
/>
<Compile
Include=
"Extensions\FuncExtensions.cs"
/>
<Compile
Include=
"Extensions\FuncExtensions.cs"
/>
<Compile
Include=
"Extensions\HttpWebRequestExtensions.cs"
/>
<Compile
Include=
"Extensions\HttpWebRequestExtensions.cs"
/>
<Compile
Include=
"Extensions\HttpWebResponseExtensions.cs"
/>
<Compile
Include=
"Extensions\HttpWebResponseExtensions.cs"
/>
...
...
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