17
17
using System . Runtime . CompilerServices ;
18
18
using RestSharp . Serializers ;
19
19
20
+ // ReSharper disable InvertIf
21
+
20
22
// ReSharper disable VirtualMemberCallInConstructor
21
23
#pragma warning disable 618
22
24
@@ -72,7 +74,7 @@ public RestClient(
72
74
}
73
75
74
76
ConfigureSerializers ( configureSerialization ) ;
75
- Options = new ReadOnlyRestClientOptions ( options ) ;
77
+ Options = new ReadOnlyRestClientOptions ( options ) ;
76
78
DefaultParameters = new DefaultParameters ( Options ) ;
77
79
78
80
if ( useClientFactory ) {
@@ -90,8 +92,12 @@ HttpClient GetClient() {
90
92
var handler = new HttpClientHandler ( ) ;
91
93
ConfigureHttpMessageHandler ( handler , options ) ;
92
94
var finalHandler = options . ConfigureMessageHandler ? . Invoke ( handler ) ?? handler ;
93
- var httpClient = new HttpClient ( finalHandler ) ;
95
+ var httpClient = new HttpClient ( finalHandler ) ;
94
96
ConfigureHttpClient ( httpClient , options ) ;
97
+
98
+ // We will use Options.Timeout in ExecuteAsInternalAsync method
99
+ httpClient . Timeout = Timeout . InfiniteTimeSpan ;
100
+
95
101
ConfigureDefaultParameters ( options ) ;
96
102
configureDefaultHeaders ? . Invoke ( httpClient . DefaultRequestHeaders ) ;
97
103
return httpClient ;
@@ -220,9 +226,6 @@ public RestClient(
220
226
: this ( new HttpClient ( handler , disposeHandler ) , true , configureRestClient , configureSerialization ) { }
221
227
222
228
static void ConfigureHttpClient ( HttpClient httpClient , RestClientOptions options ) {
223
- // We will use Options.Timeout in ExecuteAsInternalAsync method
224
- httpClient . Timeout = Timeout . InfiniteTimeSpan ;
225
-
226
229
if ( options . Expect100Continue != null ) httpClient . DefaultRequestHeaders . ExpectContinue = options . Expect100Continue ;
227
230
}
228
231
@@ -231,21 +234,21 @@ static void ConfigureHttpMessageHandler(HttpClientHandler handler, RestClientOpt
231
234
#if NET
232
235
if ( ! OperatingSystem . IsBrowser ( ) ) {
233
236
#endif
234
- handler . UseCookies = false ;
235
- handler . Credentials = options . Credentials ;
236
- handler . UseDefaultCredentials = options . UseDefaultCredentials ;
237
- handler . AutomaticDecompression = options . AutomaticDecompression ;
238
- handler . PreAuthenticate = options . PreAuthenticate ;
239
- if ( options . MaxRedirects . HasValue ) handler . MaxAutomaticRedirections = options . MaxRedirects . Value ;
240
-
241
- if ( options . RemoteCertificateValidationCallback != null )
242
- handler . ServerCertificateCustomValidationCallback =
243
- ( request , cert , chain , errors ) => options . RemoteCertificateValidationCallback ( request , cert , chain , errors ) ;
244
-
245
- if ( options . ClientCertificates != null ) {
246
- handler . ClientCertificates . AddRange ( options . ClientCertificates ) ;
247
- handler . ClientCertificateOptions = ClientCertificateOption . Manual ;
248
- }
237
+ handler . UseCookies = false ;
238
+ handler . Credentials = options . Credentials ;
239
+ handler . UseDefaultCredentials = options . UseDefaultCredentials ;
240
+ handler . AutomaticDecompression = options . AutomaticDecompression ;
241
+ handler . PreAuthenticate = options . PreAuthenticate ;
242
+ if ( options . MaxRedirects . HasValue ) handler . MaxAutomaticRedirections = options . MaxRedirects . Value ;
243
+
244
+ if ( options . RemoteCertificateValidationCallback != null )
245
+ handler . ServerCertificateCustomValidationCallback =
246
+ ( request , cert , chain , errors ) => options . RemoteCertificateValidationCallback ( request , cert , chain , errors ) ;
247
+
248
+ if ( options . ClientCertificates != null ) {
249
+ handler . ClientCertificates . AddRange ( options . ClientCertificates ) ;
250
+ handler . ClientCertificateOptions = ClientCertificateOption . Manual ;
251
+ }
249
252
#if NET
250
253
}
251
254
#endif
@@ -255,7 +258,7 @@ static void ConfigureHttpMessageHandler(HttpClientHandler handler, RestClientOpt
255
258
// ReSharper disable once InvertIf
256
259
if ( ! OperatingSystem . IsBrowser ( ) && ! OperatingSystem . IsIOS ( ) && ! OperatingSystem . IsTvOS ( ) ) {
257
260
#endif
258
- if ( handler . SupportsProxy ) handler . Proxy = options . Proxy ;
261
+ if ( handler . SupportsProxy ) handler . Proxy = options . Proxy ;
259
262
#if NET
260
263
}
261
264
#endif
@@ -274,8 +277,8 @@ void ConfigureSerializers(ConfigureSerialization? configureSerialization) {
274
277
void ConfigureDefaultParameters ( RestClientOptions options ) {
275
278
if ( options . UserAgent == null ) return ;
276
279
277
- if ( ! options . AllowMultipleDefaultParametersWithSameName
278
- && DefaultParameters . Any ( parameter => parameter . Type == ParameterType . HttpHeader && parameter . Name == KnownHeaders . UserAgent ) )
280
+ if ( ! options . AllowMultipleDefaultParametersWithSameName &&
281
+ DefaultParameters . Any ( parameter => parameter . Type == ParameterType . HttpHeader && parameter . Name == KnownHeaders . UserAgent ) )
279
282
DefaultParameters . RemoveParameter ( KnownHeaders . UserAgent , ParameterType . HttpHeader ) ;
280
283
DefaultParameters . AddParameter ( Parameter . CreateParameter ( KnownHeaders . UserAgent , options . UserAgent , ParameterType . HttpHeader ) ) ;
281
284
}
@@ -294,4 +297,4 @@ public void Dispose() {
294
297
Dispose ( true ) ;
295
298
GC . SuppressFinalize ( this ) ;
296
299
}
297
- }
300
+ }
0 commit comments