Skip to content

Commit 18230ff

Browse files
committed
Btw fix the repeatedly added agent header
Assign the Expected100 header only if the provided value is not null
1 parent 76449e5 commit 18230ff

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

src/RestSharp/RestClient.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,11 @@ public RestClient(HttpMessageHandler handler, bool disposeHandler = true) : this
125125

126126
void ConfigureHttpClient(HttpClient httpClient) {
127127
if (Options.MaxTimeout > 0) httpClient.Timeout = TimeSpan.FromMilliseconds(Options.MaxTimeout);
128-
httpClient.DefaultRequestHeaders.UserAgent.ParseAdd(Options.UserAgent);
129-
httpClient.DefaultRequestHeaders.ExpectContinue = Options.Expect100Continue;
128+
if (httpClient.DefaultRequestHeaders.UserAgent.All(x => x.Product.Name != "RestSharp")) {
129+
httpClient.DefaultRequestHeaders.UserAgent.ParseAdd(Options.UserAgent);
130+
}
131+
if (Options.Expect100Continue != null)
132+
httpClient.DefaultRequestHeaders.ExpectContinue = Options.Expect100Continue;
130133
}
131134

132135
void ConfigureHttpMessageHandler(HttpClientHandler handler) {

src/RestSharp/RestClientOptions.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,20 +70,20 @@ public RestClientOptions(string baseUrl) : this(new Uri(Ensure.NotEmptyString(ba
7070
/// </summary>
7171
public X509CertificateCollection? ClientCertificates { get; set; }
7272

73-
public IWebProxy? Proxy { get; set; }
74-
public CacheControlHeaderValue? CachePolicy { get; set; }
75-
public bool FollowRedirects { get; set; } = true;
73+
public IWebProxy? Proxy { get; set; }
74+
public CacheControlHeaderValue? CachePolicy { get; set; }
75+
public bool FollowRedirects { get; set; } = true;
7676
public bool? Expect100Continue { get; set; } = null;
77-
public CookieContainer? CookieContainer { get; set; }
78-
public string UserAgent { get; set; } = DefaultUserAgent;
79-
77+
public CookieContainer? CookieContainer { get; set; }
78+
public string UserAgent { get; set; } = DefaultUserAgent;
79+
8080
/// <summary>
8181
/// Maximum request duration in milliseconds. When the request timeout is specified using <seealso cref="RestRequest.Timeout"/>,
8282
/// the lowest value between the client timeout and request timeout will be used.
8383
/// </summary>
84-
public int MaxTimeout { get; set; }
85-
86-
public Encoding Encoding { get; set; } = Encoding.UTF8;
84+
public int MaxTimeout { get; set; }
85+
86+
public Encoding Encoding { get; set; } = Encoding.UTF8;
8787

8888
[Obsolete("Use MaxTimeout instead")]
8989
public int Timeout {
@@ -129,4 +129,4 @@ public int Timeout {
129129
/// This properly allows to override the default behavior.
130130
/// </summary>
131131
public bool AllowMultipleDefaultParametersWithSameName { get; set; }
132-
}
132+
}

0 commit comments

Comments
 (0)