Skip to content

Commit dcb11c0

Browse files
committed
Fix the http client timeout
1 parent 63daee1 commit dcb11c0

File tree

4 files changed

+27
-1647
lines changed

4 files changed

+27
-1647
lines changed

SECURITY.md

Lines changed: 0 additions & 19 deletions
This file was deleted.

package.json

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/RestSharp/RestClient.cs

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
using System.Runtime.CompilerServices;
1818
using RestSharp.Serializers;
1919

20+
// ReSharper disable InvertIf
21+
2022
// ReSharper disable VirtualMemberCallInConstructor
2123
#pragma warning disable 618
2224

@@ -72,7 +74,7 @@ public RestClient(
7274
}
7375

7476
ConfigureSerializers(configureSerialization);
75-
Options = new ReadOnlyRestClientOptions(options);
77+
Options = new ReadOnlyRestClientOptions(options);
7678
DefaultParameters = new DefaultParameters(Options);
7779

7880
if (useClientFactory) {
@@ -90,8 +92,12 @@ HttpClient GetClient() {
9092
var handler = new HttpClientHandler();
9193
ConfigureHttpMessageHandler(handler, options);
9294
var finalHandler = options.ConfigureMessageHandler?.Invoke(handler) ?? handler;
93-
var httpClient = new HttpClient(finalHandler);
95+
var httpClient = new HttpClient(finalHandler);
9496
ConfigureHttpClient(httpClient, options);
97+
98+
// We will use Options.Timeout in ExecuteAsInternalAsync method
99+
httpClient.Timeout = Timeout.InfiniteTimeSpan;
100+
95101
ConfigureDefaultParameters(options);
96102
configureDefaultHeaders?.Invoke(httpClient.DefaultRequestHeaders);
97103
return httpClient;
@@ -220,9 +226,6 @@ public RestClient(
220226
: this(new HttpClient(handler, disposeHandler), true, configureRestClient, configureSerialization) { }
221227

222228
static void ConfigureHttpClient(HttpClient httpClient, RestClientOptions options) {
223-
// We will use Options.Timeout in ExecuteAsInternalAsync method
224-
httpClient.Timeout = Timeout.InfiniteTimeSpan;
225-
226229
if (options.Expect100Continue != null) httpClient.DefaultRequestHeaders.ExpectContinue = options.Expect100Continue;
227230
}
228231

@@ -231,21 +234,21 @@ static void ConfigureHttpMessageHandler(HttpClientHandler handler, RestClientOpt
231234
#if NET
232235
if (!OperatingSystem.IsBrowser()) {
233236
#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+
}
249252
#if NET
250253
}
251254
#endif
@@ -255,7 +258,7 @@ static void ConfigureHttpMessageHandler(HttpClientHandler handler, RestClientOpt
255258
// ReSharper disable once InvertIf
256259
if (!OperatingSystem.IsBrowser() && !OperatingSystem.IsIOS() && !OperatingSystem.IsTvOS()) {
257260
#endif
258-
if (handler.SupportsProxy) handler.Proxy = options.Proxy;
261+
if (handler.SupportsProxy) handler.Proxy = options.Proxy;
259262
#if NET
260263
}
261264
#endif
@@ -274,8 +277,8 @@ void ConfigureSerializers(ConfigureSerialization? configureSerialization) {
274277
void ConfigureDefaultParameters(RestClientOptions options) {
275278
if (options.UserAgent == null) return;
276279

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))
279282
DefaultParameters.RemoveParameter(KnownHeaders.UserAgent, ParameterType.HttpHeader);
280283
DefaultParameters.AddParameter(Parameter.CreateParameter(KnownHeaders.UserAgent, options.UserAgent, ParameterType.HttpHeader));
281284
}
@@ -294,4 +297,4 @@ public void Dispose() {
294297
Dispose(true);
295298
GC.SuppressFinalize(this);
296299
}
297-
}
300+
}

0 commit comments

Comments
 (0)