@@ -11,37 +11,31 @@ public class ScriptDownloader
1111 {
1212 public async Task < string > Download ( string uri )
1313 {
14- using ( HttpClient client = new HttpClient ( new HttpClientHandler
14+ using HttpClient client = new HttpClient ( new HttpClientHandler
1515 {
1616 // Avoid Deflate due to bugs. For more info, see:
1717 // https://github.com/weblinq/WebLinq/issues/132
1818 AutomaticDecompression = DecompressionMethods . GZip
19- } ) )
20- {
21- using ( HttpResponseMessage response = await client . GetAsync ( uri , HttpCompletionOption . ResponseHeadersRead ) )
22- {
23- response . EnsureSuccessStatusCode ( ) ;
19+ } ) ;
20+ using HttpResponseMessage response = await client . GetAsync ( uri , HttpCompletionOption . ResponseHeadersRead ) ;
21+ response . EnsureSuccessStatusCode ( ) ;
2422
25- using ( HttpContent content = response . Content )
26- {
27- var mediaType = content . Headers . ContentType ? . MediaType ? . ToLowerInvariant ( ) . Trim ( ) ;
28- switch ( mediaType )
29- {
30- case null :
31- case "" :
32- case "text/plain" :
33- return await content . ReadAsStringAsync ( ) ;
34- case "application/gzip" :
35- case "application/x-gzip" :
36- using ( var stream = await content . ReadAsStreamAsync ( ) )
37- using ( var gzip = new GZipStream ( stream , CompressionMode . Decompress ) )
38- using ( var reader = new StreamReader ( gzip ) )
39- return await reader . ReadToEndAsync ( ) ;
40- default :
41- throw new NotSupportedException ( $ "The media type '{ mediaType } ' is not supported when executing a script over http/https") ;
42- }
43- }
44- }
23+ using HttpContent content = response . Content ;
24+ var mediaType = content . Headers . ContentType ? . MediaType ? . ToLowerInvariant ( ) . Trim ( ) ;
25+ switch ( mediaType )
26+ {
27+ case null :
28+ case "" :
29+ case "text/plain" :
30+ return await content . ReadAsStringAsync ( ) ;
31+ case "application/gzip" :
32+ case "application/x-gzip" :
33+ using ( var stream = await content . ReadAsStreamAsync ( ) )
34+ using ( var gzip = new GZipStream ( stream , CompressionMode . Decompress ) )
35+ using ( var reader = new StreamReader ( gzip ) )
36+ return await reader . ReadToEndAsync ( ) ;
37+ default :
38+ throw new NotSupportedException ( $ "The media type '{ mediaType } ' is not supported when executing a script over http/https") ;
4539 }
4640 }
4741 }
0 commit comments