This repository was archived by the owner on Jul 9, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +11
-6
lines changed
Expand file tree Collapse file tree 2 files changed +11
-6
lines changed Original file line number Diff line number Diff line change 1- namespace Titanium . Web . Proxy . Compression
1+ using System ;
2+
3+ namespace Titanium . Web . Proxy . Compression
24{
35 /// <summary>
46 /// A factory to generate the compression methods based on the type of compression
57 /// </summary>
68 internal class CompressionFactory
79 {
8- public ICompression Create ( string type )
10+ //cache
11+ private static Lazy < ICompression > gzip = new Lazy < ICompression > ( ( ) => new GZipCompression ( ) ) ;
12+ private static Lazy < ICompression > deflate = new Lazy < ICompression > ( ( ) => new DeflateCompression ( ) ) ;
13+
14+ public static ICompression GetCompression ( string type )
915 {
1016 switch ( type )
1117 {
1218 case "gzip" :
13- return new GZipCompression ( ) ;
19+ return gzip . Value ;
1420 case "deflate" :
15- return new DeflateCompression ( ) ;
21+ return deflate . Value ;
1622 default :
1723 return null ;
1824 }
Original file line number Diff line number Diff line change @@ -122,8 +122,7 @@ private async Task HandleHttpSessionResponse(SessionEventArgs args)
122122 /// <returns></returns>
123123 private async Task < byte [ ] > GetCompressedResponseBody ( string encodingType , byte [ ] responseBodyStream )
124124 {
125- var compressionFactory = new CompressionFactory ( ) ;
126- var compressor = compressionFactory . Create ( encodingType ) ;
125+ var compressor = CompressionFactory . GetCompression ( encodingType ) ;
127126 return await compressor . Compress ( responseBodyStream ) ;
128127 }
129128 }
You can’t perform that action at this time.
0 commit comments