11using  System ; 
2+ using  System . Linq ; 
23using  System . Net ; 
34using  System . Net . Http ; 
5+ using  System . Text ; 
46using  System . Threading . Tasks ; 
57using  Newtonsoft . Json ; 
8+ using  WebDriverManager . Helpers ; 
69using  WebDriverManager . Models . Chrome ; 
710
811namespace  WebDriverManager . Clients 
912{ 
1013    public  static   class  ChromeForTestingClient 
1114    { 
1215        private  static   readonly  string  BaseUrl  =  "https://googlechromelabs.github.io/chrome-for-testing/" ; 
13-          
16+ 
1417        private  static   HttpClient  _httpClient ; 
1518
1619        private  static   HttpClient  HttpClient 
@@ -28,6 +31,9 @@ private static HttpClient HttpClient
2831                    BaseAddress  =  new  Uri ( BaseUrl ) 
2932                } ; 
3033
34+                 _httpClient . DefaultRequestHeaders . Add ( "User-Agent" ,  "WebDriverManager.NET" ) ; 
35+                 _httpClient . DefaultRequestHeaders . Add ( "Accept" ,  "*/*" ) ; 
36+                 _httpClient . DefaultRequestHeaders . Add ( "Accept-Encoding" ,  "br, deflate, gzip, x-gzip" ) ; 
3137                return  _httpClient ; 
3238            } 
3339        } 
@@ -59,11 +65,26 @@ private static TResult GetResultFromHttpTask<TResult>(Task<HttpResponseMessage>
5965        { 
6066            var  httpTask  =  Task . Run ( ( )  =>  taskToRun ) ; 
6167            httpTask . Wait ( ) ; 
68+             var  response  =  httpTask . Result ; 
69+             if  ( response . Content . Headers . Contains ( "Content-Encoding" ) ) 
70+             { 
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 ( ) ; 
76+ 
77+                     byte [ ]  decompressionData  =  GzipDecompression . DecompressGzip ( readBytesTask . Result ) ; 
78+                     return  JsonConvert . DeserializeObject < TResult > ( Encoding . UTF8 . GetString ( decompressionData ) ) ; 
79+                 } 
80+             } 
81+ 
6282
6383            var  readStringTask  =  Task . Run ( ( )  =>  httpTask . Result . Content . ReadAsStringAsync ( ) ) ; 
6484            readStringTask . Wait ( ) ; 
65- 
6685            return  JsonConvert . DeserializeObject < TResult > ( readStringTask . Result ) ; 
86+ 
87+ 
6788        } 
6889    } 
6990} 
0 commit comments