File tree Expand file tree Collapse file tree 3 files changed +29
-40
lines changed Expand file tree Collapse file tree 3 files changed +29
-40
lines changed Original file line number Diff line number Diff line change @@ -65,26 +65,20 @@ private static TResult GetResultFromHttpTask<TResult>(Task<HttpResponseMessage>
6565 {
6666 var httpTask = Task . Run ( ( ) => taskToRun ) ;
6767 httpTask . Wait ( ) ;
68- var response = httpTask . Result ;
69- if ( response . Content . Headers . Contains ( "Content-Encoding" ) )
68+
69+ var encoding = httpTask . Result . Content . Headers ? . GetValues ( "Content-Encoding" ) ? . FirstOrDefault ( ) ;
70+ if ( encoding != null && encoding . Equals ( "gzip" , StringComparison . OrdinalIgnoreCase ) )
7071 {
71- string encoding = response . Content . Headers . GetValues ( "Content-Encoding" ) . FirstOrDefault ( ) ;
72- if ( string . Equals ( encoding , "gzip" , StringComparison . OrdinalIgnoreCase ) )
73- {
74- var readBytesTask = Task . Run ( ( ) => httpTask . Result . Content . ReadAsByteArrayAsync ( ) ) ;
75- readBytesTask . Wait ( ) ;
72+ var readBytesTask = Task . Run ( ( ) => httpTask . Result . Content . ReadAsByteArrayAsync ( ) ) ;
73+ readBytesTask . Wait ( ) ;
7674
77- byte [ ] decompressionData = GzipDecompression . DecompressGzip ( readBytesTask . Result ) ;
78- return JsonConvert . DeserializeObject < TResult > ( Encoding . UTF8 . GetString ( decompressionData ) ) ;
79- }
75+ var decompressionData = ArchiveHelper . UnpackGzip ( readBytesTask . Result ) ;
76+ return JsonConvert . DeserializeObject < TResult > ( Encoding . UTF8 . GetString ( decompressionData ) ) ;
8077 }
8178
82-
8379 var readStringTask = Task . Run ( ( ) => httpTask . Result . Content . ReadAsStringAsync ( ) ) ;
8480 readStringTask . Wait ( ) ;
8581 return JsonConvert . DeserializeObject < TResult > ( readStringTask . Result ) ;
86-
87-
8882 }
8983 }
9084}
Original file line number Diff line number Diff line change 1+ using System . IO . Compression ;
2+ using System . IO ;
3+
4+ namespace WebDriverManager . Helpers
5+ {
6+ internal static class ArchiveHelper
7+ {
8+ public static byte [ ] UnpackGzip ( byte [ ] compressedData )
9+ {
10+ using ( var compressedStream = new MemoryStream ( compressedData ) )
11+ using ( var decompressedStream = new MemoryStream ( ) )
12+ {
13+ using ( var gZipStream = new GZipStream ( compressedStream , CompressionMode . Decompress ) )
14+ {
15+ gZipStream . CopyTo ( decompressedStream ) ;
16+ }
17+
18+ return decompressedStream . ToArray ( ) ;
19+ }
20+ }
21+ }
22+ }
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments