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
a9c29243
Commit
a9c29243
authored
Mar 25, 2018
by
Honfika
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
content length limit fix
parent
72cd50d5
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
57 additions
and
100 deletions
+57
-100
CompressionFactory.cs
Titanium.Web.Proxy/Compression/CompressionFactory.cs
+2
-5
DefaultCompression.cs
Titanium.Web.Proxy/Compression/DefaultCompression.cs
+0
-16
DecompressionFactory.cs
Titanium.Web.Proxy/Decompression/DecompressionFactory.cs
+2
-5
DefaultDecompression.cs
Titanium.Web.Proxy/Decompression/DefaultDecompression.cs
+0
-16
LimitedStream.cs
Titanium.Web.Proxy/EventArguments/LimitedStream.cs
+22
-12
SessionEventArgs.cs
Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs
+30
-45
HttpWriter.cs
Titanium.Web.Proxy/Helpers/HttpWriter.cs
+1
-1
No files found.
Titanium.Web.Proxy/Compression/CompressionFactory.cs
View file @
a9c29243
...
...
@@ -6,14 +6,11 @@ namespace Titanium.Web.Proxy.Compression
/// <summary>
/// A factory to generate the compression methods based on the type of compression
/// </summary>
internal
class
CompressionFactory
internal
static
class
CompressionFactory
{
public
static
readonly
CompressionFactory
Instance
=
new
CompressionFactory
();
//cache
private
static
readonly
Lazy
<
ICompression
>
gzip
=
new
Lazy
<
ICompression
>(()
=>
new
GZipCompression
());
private
static
readonly
Lazy
<
ICompression
>
deflate
=
new
Lazy
<
ICompression
>(()
=>
new
DeflateCompression
());
private
static
readonly
Lazy
<
ICompression
>
def
=
new
Lazy
<
ICompression
>(()
=>
new
DefaultCompression
());
public
static
ICompression
GetCompression
(
string
type
)
{
...
...
@@ -24,7 +21,7 @@ namespace Titanium.Web.Proxy.Compression
case
KnownHeaders
.
ContentEncodingDeflate
:
return
deflate
.
Value
;
default
:
return
def
.
Value
;
throw
new
Exception
(
$"Unsupported compression mode:
{
type
}
"
)
;
}
}
}
...
...
Titanium.Web.Proxy/Compression/DefaultCompression.cs
deleted
100644 → 0
View file @
72cd50d5
using
System.IO
;
using
System.Threading.Tasks
;
namespace
Titanium.Web.Proxy.Compression
{
/// <summary>
/// When no compression is specified just return the stream
/// </summary>
internal
class
DefaultCompression
:
ICompression
{
public
Stream
GetStream
(
Stream
stream
)
{
return
stream
;
}
}
}
Titanium.Web.Proxy/Decompression/DecompressionFactory.cs
View file @
a9c29243
...
...
@@ -8,14 +8,11 @@ namespace Titanium.Web.Proxy.Decompression
/// </summary>
internal
class
DecompressionFactory
{
public
static
readonly
DecompressionFactory
Instance
=
new
DecompressionFactory
();
//cache
private
static
readonly
Lazy
<
IDecompression
>
gzip
=
new
Lazy
<
IDecompression
>(()
=>
new
GZipDecompression
());
private
static
readonly
Lazy
<
IDecompression
>
deflate
=
new
Lazy
<
IDecompression
>(()
=>
new
DeflateDecompression
());
private
static
readonly
Lazy
<
IDecompression
>
def
=
new
Lazy
<
IDecompression
>(()
=>
new
DefaultDecompression
());
internal
IDecompression
Create
(
string
type
)
public
static
IDecompression
Create
(
string
type
)
{
switch
(
type
)
{
...
...
@@ -24,7 +21,7 @@ namespace Titanium.Web.Proxy.Decompression
case
KnownHeaders
.
ContentEncodingDeflate
:
return
deflate
.
Value
;
default
:
return
def
.
Value
;
throw
new
Exception
(
$"Unsupported decompression mode:
{
type
}
"
)
;
}
}
}
...
...
Titanium.Web.Proxy/Decompression/DefaultDecompression.cs
deleted
100644 → 0
View file @
72cd50d5
using
System.IO
;
using
System.Threading.Tasks
;
namespace
Titanium.Web.Proxy.Decompression
{
/// <summary>
/// When no compression is specified just return the stream
/// </summary>
internal
class
DefaultDecompression
:
IDecompression
{
public
Stream
GetStream
(
Stream
stream
)
{
return
stream
;
}
}
}
Titanium.Web.Proxy/EventArguments/
Chunk
edStream.cs
→
Titanium.Web.Proxy/EventArguments/
Limit
edStream.cs
View file @
a9c29243
...
...
@@ -8,18 +8,21 @@ using StreamExtended.Network;
namespace
Titanium.Web.Proxy.EventArguments
{
internal
class
Chunk
edStream
:
Stream
internal
class
Limit
edStream
:
Stream
{
private
readonly
CustomBufferedStream
baseStream
;
private
readonly
CustomBinaryReader
baseReader
;
private
readonly
bool
isChunked
;
private
bool
readChunkTrail
;
private
int
chunkB
ytesRemaining
;
private
long
b
ytesRemaining
;
public
ChunkedStream
(
CustomBufferedStream
baseStream
,
CustomBinaryReader
baseReader
)
public
LimitedStream
(
CustomBufferedStream
baseStream
,
CustomBinaryReader
baseReader
,
bool
isChunked
,
long
contentLength
)
{
this
.
baseStream
=
baseStream
;
this
.
baseReader
=
baseReader
;
this
.
isChunked
=
isChunked
;
bytesRemaining
=
isChunked
?
0
:
contentLength
;
}
private
void
GetNextChunk
()
...
...
@@ -41,11 +44,11 @@ namespace Titanium.Web.Proxy.EventArguments
}
int
chunkSize
=
int
.
Parse
(
chunkHead
,
NumberStyles
.
HexNumber
);
chunkB
ytesRemaining
=
chunkSize
;
b
ytesRemaining
=
chunkSize
;
if
(
chunkSize
==
0
)
{
chunkB
ytesRemaining
=
-
1
;
b
ytesRemaining
=
-
1
;
//chunk trail
string
s
=
baseReader
.
ReadLineAsync
().
Result
;
...
...
@@ -69,24 +72,31 @@ namespace Titanium.Web.Proxy.EventArguments
public
override
int
Read
(
byte
[]
buffer
,
int
offset
,
int
count
)
{
if
(
chunkB
ytesRemaining
==
-
1
)
if
(
b
ytesRemaining
==
-
1
)
{
return
0
;
}
if
(
chunkBytesRemaining
==
0
)
if
(
bytesRemaining
==
0
)
{
if
(
isChunked
)
{
GetNextChunk
();
}
else
{
bytesRemaining
=
-
1
;
}
}
if
(
chunkB
ytesRemaining
==
-
1
)
if
(
b
ytesRemaining
==
-
1
)
{
return
0
;
}
int
toRead
=
Math
.
Min
(
count
,
chunkB
ytesRemaining
);
int
toRead
=
(
int
)
Math
.
Min
(
count
,
b
ytesRemaining
);
int
res
=
baseStream
.
Read
(
buffer
,
offset
,
toRead
);
chunkB
ytesRemaining
-=
res
;
b
ytesRemaining
-=
res
;
return
res
;
}
...
...
@@ -96,7 +106,7 @@ namespace Titanium.Web.Proxy.EventArguments
var
buffer
=
BufferPool
.
GetBuffer
(
baseReader
.
Buffer
.
Length
);
try
{
while
(
chunkB
ytesRemaining
!=
-
1
)
while
(
b
ytesRemaining
!=
-
1
)
{
await
ReadAsync
(
buffer
,
0
,
buffer
.
Length
);
}
...
...
Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs
View file @
a9c29243
...
...
@@ -294,73 +294,58 @@ namespace Titanium.Web.Proxy.EventArguments
}
else
{
await
CopyBodyAsync
(
ProxyClient
.
ClientStream
,
reader
,
writer
,
request
.
IsChunked
,
transformation
,
request
.
ContentEncoding
,
contentLength
,
OnDataSent
);
await
CopyBodyAsync
(
ProxyClient
.
ClientStream
,
reader
,
writer
,
request
,
transformation
,
OnDataSent
);
}
}
private
async
Task
CopyBodyAsync
(
CustomBufferedStream
stream
,
CustomBinaryReader
reader
,
HttpWriter
writer
,
bool
isChunked
,
TransformationMode
transformation
,
string
contentEncoding
,
long
contentLength
,
Action
<
byte
[],
int
,
int
>
onCopy
)
internal
async
Task
CopyResponseBodyAsync
(
HttpWriter
writer
,
TransformationMode
transformation
)
{
bool
newReader
=
false
;
var
response
=
WebSession
.
Response
;
var
reader
=
WebSession
.
ServerConnection
.
StreamReader
;
Stream
s
=
stream
;
ChunkedStream
chunkedStream
=
null
;
Stream
decompressStream
=
null
;
await
CopyBodyAsync
(
WebSession
.
ServerConnection
.
Stream
,
reader
,
writer
,
response
,
transformation
,
OnDataReceived
);
}
if
(
isChunked
&&
transformation
!=
TransformationMode
.
None
)
private
async
Task
CopyBodyAsync
(
CustomBufferedStream
stream
,
CustomBinaryReader
reader
,
HttpWriter
writer
,
RequestResponseBase
requestResponse
,
TransformationMode
transformation
,
Action
<
byte
[],
int
,
int
>
onCopy
)
{
bool
isChunked
=
requestResponse
.
IsChunked
;
long
contentLength
=
requestResponse
.
ContentLength
;
if
(
transformation
==
TransformationMode
.
None
)
{
s
=
chunkedStream
=
new
ChunkedStream
(
stream
,
reader
);
isChunked
=
false
;
newReader
=
true
;
await
writer
.
CopyBodyAsync
(
reader
,
isChunked
,
contentLength
,
onCopy
);
return
;
}
if
(
transformation
==
TransformationMode
.
Uncompress
)
LimitedStream
limitedStream
;
Stream
decompressStream
=
null
;
string
contentEncoding
=
requestResponse
.
ContentEncoding
;
Stream
s
=
limitedStream
=
new
LimitedStream
(
stream
,
reader
,
isChunked
,
contentLength
);
if
(
transformation
==
TransformationMode
.
Uncompress
&&
contentEncoding
!=
null
)
{
s
=
decompressStream
=
DecompressionFactory
.
Instance
.
Create
(
contentEncoding
).
GetStream
(
s
);
newReader
=
true
;
s
=
decompressStream
=
DecompressionFactory
.
Create
(
contentEncoding
).
GetStream
(
s
);
}
try
{
if
(
newReader
)
{
var
bufStream
=
new
CustomBufferedStream
(
s
,
bufferSize
,
true
);
s
=
bufStream
;
reader
=
new
CustomBinaryReader
(
bufStream
,
bufferSize
);
}
await
writer
.
CopyBodyAsync
(
reader
,
isChunked
,
contentLength
,
onCopy
);
await
writer
.
CopyBodyAsync
(
reader
,
false
,
-
1
,
onCopy
);
}
finally
{
if
(
newReader
)
{
reader
?.
Dispose
();
if
(
decompressStream
!=
null
&&
decompressStream
!=
stream
)
{
decompressStream
.
Dispose
();
}
decompressStream
?.
Dispose
();
if
(
chunkedStream
!=
null
)
{
await
chunkedStream
.
Finish
();
chunkedStream
.
Dispose
();
}
}
await
limitedStream
.
Finish
();
limitedStream
.
Dispose
();
}
}
internal
async
Task
CopyResponseBodyAsync
(
HttpWriter
writer
,
TransformationMode
transformation
)
{
var
response
=
WebSession
.
Response
;
var
reader
=
WebSession
.
ServerConnection
.
StreamReader
;
await
CopyBodyAsync
(
WebSession
.
ServerConnection
.
Stream
,
reader
,
writer
,
response
.
IsChunked
,
transformation
,
response
.
ContentEncoding
,
response
.
ContentLength
,
OnDataReceived
);
}
/// <summary>
/// Read a line from the byte stream
/// </summary>
...
...
Titanium.Web.Proxy/Helpers/HttpWriter.cs
View file @
a9c29243
...
...
@@ -165,7 +165,7 @@ namespace Titanium.Web.Proxy.Helpers
return
CopyBodyChunkedAsync
(
streamReader
,
onCopy
);
}
//http 1.0
//http 1.0
or the stream reader limits the stream
if
(
contentLength
==
-
1
)
{
contentLength
=
long
.
MaxValue
;
...
...
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