Skip to content

Commit

Permalink
Small cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeyzimarev committed May 22, 2024
1 parent 9117b7a commit 1aa5b02
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/RestSharp/Request/RestRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public RestRequest(Uri resource, Method method = Method.Get)

/// <summary>
/// Used by the default deserializers to determine where to start deserializing from.
/// Can be used to skip container or root elements that do not have corresponding deserialzation targets.
/// Can be used to skip container or root elements that do not have corresponding deserialization targets.
/// </summary>
public string? RootElement { get; set; }

Expand Down
20 changes: 8 additions & 12 deletions src/RestSharp/RestClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ namespace RestSharp;
/// <summary>
/// Client to translate RestRequests into Http requests and process response result
/// </summary>
// ReSharper disable once ClassWithVirtualMembersNeverInherited.Global
public partial class RestClient : IRestClient {
/// <summary>
/// Content types that will be sent in the Accept header. The list is populated from the known serializers.
Expand All @@ -55,11 +56,6 @@ public string[] AcceptedContentTypes {
/// <inheritdoc/>
public DefaultParameters DefaultParameters { get; }

[Obsolete("Use RestClientOptions.Authenticator instead")]
public IAuthenticator? Authenticator => Options.Authenticator;

// set => Options.Authenticator = value;

/// <summary>
/// Creates an instance of RestClient using the provided <see cref="RestClientOptions"/>
/// </summary>
Expand Down Expand Up @@ -226,7 +222,6 @@ public RestClient(
: this(new HttpClient(handler, disposeHandler), true, configureRestClient, configureSerialization) { }

static void ConfigureHttpClient(HttpClient httpClient, RestClientOptions options) {

// We will use Options.Timeout in ExecuteAsInternalAsync method
httpClient.Timeout = Timeout.InfiniteTimeSpan;

Expand Down Expand Up @@ -259,6 +254,7 @@ static void ConfigureHttpMessageHandler(HttpClientHandler handler, RestClientOpt
handler.AllowAutoRedirect = options.FollowRedirects;

#if NET
// ReSharper disable once InvertIf
if (!OperatingSystem.IsBrowser() && !OperatingSystem.IsIOS() && !OperatingSystem.IsTvOS()) {
#endif
if (handler.SupportsProxy) handler.Proxy = options.Proxy;
Expand All @@ -278,12 +274,12 @@ void ConfigureSerializers(ConfigureSerialization? configureSerialization) {
}

void ConfigureDefaultParameters(RestClientOptions options) {
if (options.UserAgent != null) {
if (!options.AllowMultipleDefaultParametersWithSameName
&& DefaultParameters.Any(parameter => parameter.Type == ParameterType.HttpHeader && parameter.Name == KnownHeaders.UserAgent))
DefaultParameters.RemoveParameter(KnownHeaders.UserAgent, ParameterType.HttpHeader);
DefaultParameters.AddParameter(Parameter.CreateParameter(KnownHeaders.UserAgent, options.UserAgent, ParameterType.HttpHeader));
}
if (options.UserAgent == null) return;

if (!options.AllowMultipleDefaultParametersWithSameName
&& DefaultParameters.Any(parameter => parameter.Type == ParameterType.HttpHeader && parameter.Name == KnownHeaders.UserAgent))
DefaultParameters.RemoveParameter(KnownHeaders.UserAgent, ParameterType.HttpHeader);
DefaultParameters.AddParameter(Parameter.CreateParameter(KnownHeaders.UserAgent, options.UserAgent, ParameterType.HttpHeader));
}

readonly bool _disposeHttpClient;
Expand Down

0 comments on commit 1aa5b02

Please sign in to comment.