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
1b77bf22
Commit
1b77bf22
authored
Mar 24, 2018
by
Honfika
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
decompression class caching
parent
0f9a073c
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
37 additions
and
11 deletions
+37
-11
CompressionFactory.cs
Titanium.Web.Proxy/Compression/CompressionFactory.cs
+4
-1
DefaultCompression.cs
Titanium.Web.Proxy/Compression/DefaultCompression.cs
+16
-0
DeflateCompression.cs
Titanium.Web.Proxy/Compression/DeflateCompression.cs
+2
-2
GZipCompression.cs
Titanium.Web.Proxy/Compression/GZipCompression.cs
+2
-2
ICompression.cs
Titanium.Web.Proxy/Compression/ICompression.cs
+1
-1
DecompressionFactory.cs
Titanium.Web.Proxy/Decompression/DecompressionFactory.cs
+12
-5
No files found.
Titanium.Web.Proxy/Compression/CompressionFactory.cs
View file @
1b77bf22
...
...
@@ -7,9 +7,12 @@ namespace Titanium.Web.Proxy.Compression
/// </summary>
internal
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
)
{
...
...
@@ -20,7 +23,7 @@ namespace Titanium.Web.Proxy.Compression
case
"deflate"
:
return
deflate
.
Value
;
default
:
return
null
;
return
def
.
Value
;
}
}
}
...
...
Titanium.Web.Proxy/Compression/DefaultCompression.cs
0 → 100644
View file @
1b77bf22
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
async
Task
<
byte
[
]>
Compress
(
byte
[]
body
)
{
return
body
;
}
}
}
Titanium.Web.Proxy/Compression/DeflateCompression.cs
View file @
1b77bf22
...
...
@@ -9,13 +9,13 @@ namespace Titanium.Web.Proxy.Compression
/// </summary>
internal
class
DeflateCompression
:
ICompression
{
public
async
Task
<
byte
[
]>
Compress
(
byte
[]
responseB
ody
)
public
async
Task
<
byte
[
]>
Compress
(
byte
[]
b
ody
)
{
using
(
var
ms
=
new
MemoryStream
())
{
using
(
var
zip
=
new
DeflateStream
(
ms
,
CompressionMode
.
Compress
,
true
))
{
await
zip
.
WriteAsync
(
responseBody
,
0
,
responseB
ody
.
Length
);
await
zip
.
WriteAsync
(
body
,
0
,
b
ody
.
Length
);
}
return
ms
.
ToArray
();
...
...
Titanium.Web.Proxy/Compression/GZipCompression.cs
View file @
1b77bf22
...
...
@@ -9,13 +9,13 @@ namespace Titanium.Web.Proxy.Compression
/// </summary>
internal
class
GZipCompression
:
ICompression
{
public
async
Task
<
byte
[
]>
Compress
(
byte
[]
responseB
ody
)
public
async
Task
<
byte
[
]>
Compress
(
byte
[]
b
ody
)
{
using
(
var
ms
=
new
MemoryStream
())
{
using
(
var
zip
=
new
GZipStream
(
ms
,
CompressionMode
.
Compress
,
true
))
{
await
zip
.
WriteAsync
(
responseBody
,
0
,
responseB
ody
.
Length
);
await
zip
.
WriteAsync
(
body
,
0
,
b
ody
.
Length
);
}
return
ms
.
ToArray
();
...
...
Titanium.Web.Proxy/Compression/ICompression.cs
View file @
1b77bf22
...
...
@@ -7,6 +7,6 @@ namespace Titanium.Web.Proxy.Compression
/// </summary>
interface
ICompression
{
Task
<
byte
[
]>
Compress
(
byte
[]
responseB
ody
);
Task
<
byte
[
]>
Compress
(
byte
[]
b
ody
);
}
}
Titanium.Web.Proxy/Decompression/DecompressionFactory.cs
View file @
1b77bf22
namespace
Titanium.Web.Proxy.Decompression
using
System
;
namespace
Titanium.Web.Proxy.Decompression
{
/// <summary>
/// A factory to generate the de-compression methods based on the type of compression
/// </summary>
internal
class
DecompressionFactory
{
public
static
DecompressionFactory
Instance
=
new
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
)
{
switch
(
type
)
{
case
"gzip"
:
return
new
GZipDecompression
()
;
return
gzip
.
Value
;
case
"deflate"
:
return
new
DeflateDecompression
()
;
return
deflate
.
Value
;
default
:
return
new
DefaultDecompression
()
;
return
def
.
Value
;
}
}
}
...
...
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