1616using System . Text ;
1717using System . Threading ;
1818using System . Threading . Tasks ;
19+ using Elastic . Elasticsearch . Managed ;
1920using Elastic . Elasticsearch . Managed . ConsoleWriters ;
2021using ICSharpCode . SharpZipLib . GZip ;
2122using ICSharpCode . SharpZipLib . Tar ;
@@ -87,6 +88,9 @@ private HttpResponseMessage Call(
8788 AutomaticDecompression =
8889 DecompressionMethods . Deflate | DecompressionMethods . GZip | DecompressionMethods . None ,
8990 } ;
91+ if ( cluster . DetectedProxy != DetectedProxySoftware . None )
92+ handler . Proxy = new WebProxy { Address = new Uri ( "http://localhost:8080" ) } ;
93+
9094 cluster . Writer . WriteDiagnostic (
9195 $ "{{{nameof(Call)}}} [{ statusUrl } ] SSL: { cluster . ClusterConfiguration . EnableSsl } Security: { cluster . ClusterConfiguration . EnableSecurity } ") ;
9296 if ( cluster . ClusterConfiguration . EnableSsl )
@@ -98,39 +102,37 @@ private HttpResponseMessage Call(
98102#endif
99103 }
100104
101- using ( var client = new HttpClient ( handler ) { Timeout = TimeSpan . FromSeconds ( 20 ) } )
105+ using var client = new HttpClient ( handler ) { Timeout = TimeSpan . FromSeconds ( 20 ) } ;
106+ if ( cluster . ClusterConfiguration . EnableSecurity )
102107 {
103- if ( cluster . ClusterConfiguration . EnableSecurity )
104- {
105- var byteArray =
106- Encoding . ASCII . GetBytes (
107- $ "{ ClusterAuthentication . Admin . Username } :{ ClusterAuthentication . Admin . Password } ") ;
108- client . DefaultRequestHeaders . Authorization =
109- new AuthenticationHeaderValue ( "Basic" , Convert . ToBase64String ( byteArray ) ) ;
110- }
108+ var byteArray =
109+ Encoding . ASCII . GetBytes (
110+ $ "{ ClusterAuthentication . Admin . Username } :{ ClusterAuthentication . Admin . Password } ") ;
111+ client . DefaultRequestHeaders . Authorization =
112+ new AuthenticationHeaderValue ( "Basic" , Convert . ToBase64String ( byteArray ) ) ;
113+ }
111114
112- try
113- {
114- var response = verb ( client , statusUrl , tokenSource . Token ) . ConfigureAwait ( false ) . GetAwaiter ( )
115- . GetResult ( ) ;
116- if ( response . StatusCode == HttpStatusCode . OK ) return response ;
117- cluster . Writer . WriteDiagnostic (
118- $ "{{{nameof(Call)}}} [{ statusUrl } ] Bad status code: [{ ( int ) response . StatusCode } ]") ;
119- var body = response . Content . ReadAsStringAsync ( ) . GetAwaiter ( ) . GetResult ( ) ;
120- foreach ( var l in ( body ?? string . Empty ) . Split ( '\n ' , '\r ' ) )
121- cluster . Writer . WriteDiagnostic ( $ "{{{nameof(Call)}}} [{ statusUrl } ] returned [{ l } ]") ;
122- }
123- catch ( Exception e )
124- {
125- cluster . Writer . WriteError ( $ "{{{nameof(Call)}}} [{ statusUrl } ] exception: { e } ") ;
126- // ignored
127- }
128- finally
129- {
115+ try
116+ {
117+ var response = verb ( client , statusUrl , tokenSource . Token ) . ConfigureAwait ( false ) . GetAwaiter ( )
118+ . GetResult ( ) ;
119+ if ( response . StatusCode == HttpStatusCode . OK ) return response ;
120+ cluster . Writer . WriteDiagnostic (
121+ $ "{{{nameof(Call)}}} [{ statusUrl } ] Bad status code: [{ ( int ) response . StatusCode } ]") ;
122+ var body = response . Content . ReadAsStringAsync ( ) . GetAwaiter ( ) . GetResult ( ) ;
123+ foreach ( var l in ( body ?? string . Empty ) . Split ( '\n ' , '\r ' ) )
124+ cluster . Writer . WriteDiagnostic ( $ "{{{nameof(Call)}}} [{ statusUrl } ] returned [{ l } ]") ;
125+ }
126+ catch ( Exception e )
127+ {
128+ cluster . Writer . WriteError ( $ "{{{nameof(Call)}}} [{ statusUrl } ] exception: { e } ") ;
129+ // ignored
130+ }
131+ finally
132+ {
130133#if ! NETSTANDARD
131134 ServicePointManager . ServerCertificateValidationCallback -= ServerCertificateValidationCallback ;
132135#endif
133- }
134136 }
135137
136138 return null ;
0 commit comments