16
16
using System . Text ;
17
17
using System . Threading ;
18
18
using System . Threading . Tasks ;
19
+ using Elastic . Elasticsearch . Managed ;
19
20
using Elastic . Elasticsearch . Managed . ConsoleWriters ;
20
21
using ICSharpCode . SharpZipLib . GZip ;
21
22
using ICSharpCode . SharpZipLib . Tar ;
@@ -87,6 +88,9 @@ private HttpResponseMessage Call(
87
88
AutomaticDecompression =
88
89
DecompressionMethods . Deflate | DecompressionMethods . GZip | DecompressionMethods . None ,
89
90
} ;
91
+ if ( cluster . DetectedProxy != DetectedProxySoftware . None )
92
+ handler . Proxy = new WebProxy { Address = new Uri ( "http://localhost:8080" ) } ;
93
+
90
94
cluster . Writer . WriteDiagnostic (
91
95
$ "{{{nameof(Call)}}} [{ statusUrl } ] SSL: { cluster . ClusterConfiguration . EnableSsl } Security: { cluster . ClusterConfiguration . EnableSecurity } ") ;
92
96
if ( cluster . ClusterConfiguration . EnableSsl )
@@ -98,39 +102,37 @@ private HttpResponseMessage Call(
98
102
#endif
99
103
}
100
104
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 )
102
107
{
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
+ }
111
114
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
+ {
130
133
#if ! NETSTANDARD
131
134
ServicePointManager . ServerCertificateValidationCallback -= ServerCertificateValidationCallback ;
132
135
#endif
133
- }
134
136
}
135
137
136
138
return null ;
0 commit comments