Skip to content

Commit 17a3532

Browse files
Proposed fix for #1765 (#1782)
* Fix for #1765
1 parent 5550efb commit 17a3532

File tree

3 files changed

+23
-14
lines changed

3 files changed

+23
-14
lines changed

src/Directory.Build.props

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,10 @@
1616
<GenerateDocumentationFile>true</GenerateDocumentationFile>
1717
<NoWarn>$(NoWarn);1591</NoWarn>
1818
</PropertyGroup>
19-
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
20-
<MinVerSkip>true</MinVerSkip>
21-
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
22-
</PropertyGroup>
2319

2420
<ItemGroup>
2521
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All"/>
26-
<PackageReference Include="MinVer" Version="2.5.0" PrivateAssets="All"/>
22+
<PackageReference Include="MinVer" Version="3.0.0" PrivateAssets="All"/>
2723
<PackageReference Include="JetBrains.Annotations" Version="2021.3.0" PrivateAssets="All"/>
2824
</ItemGroup>
2925
<ItemGroup>

src/RestSharp/Request/RequestContent.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ void AddPostParameters(ParametersCollection? postParameters) {
162162
var formContent = new FormUrlEncodedContent(
163163
_request.Parameters
164164
.Where(x => x.Type == ParameterType.GetOrPost)
165-
.Select(x => new KeyValuePair<string, string>(x.Name!, x.Value!.ToString()!))
165+
.Select(x => new KeyValuePair<string, string>(x.Name!, x.Value!.ToString()!))!
166166
);
167167
Content = formContent;
168168
}

src/RestSharp/RestClient.cs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public partial class RestClient : IDisposable {
4545

4646
HttpClient HttpClient { get; }
4747

48-
internal RestClientOptions Options { get; }
48+
public RestClientOptions Options { get; }
4949

5050
public RestClient(RestClientOptions options, Action<HttpRequestHeaders>? configureDefaultHeaders = null) {
5151
UseDefaultSerializers();
@@ -83,19 +83,32 @@ public RestClient(Uri baseUrl) : this(new RestClientOptions { BaseUrl = baseUrl
8383
/// <param name="baseUrl"></param>
8484
public RestClient(string baseUrl) : this(new Uri(Ensure.NotEmptyString(baseUrl, nameof(baseUrl)))) { }
8585

86-
public RestClient(HttpClient httpClient, RestClientOptions? options = null, bool disposeHttpClient = false) {
87-
if (options?.CookieContainer != null) {
86+
public RestClient(HttpClient httpClient, bool disposeHttpClient = false) {
87+
UseDefaultSerializers();
88+
89+
HttpClient = httpClient;
90+
CookieContainer = new CookieContainer();
91+
Options = new RestClientOptions();
92+
_disposeHttpClient = disposeHttpClient;
93+
94+
if (httpClient.BaseAddress != null) {
95+
Options.BaseUrl = httpClient.BaseAddress;
96+
}
97+
}
98+
99+
public RestClient(HttpClient httpClient, RestClientOptions options, bool disposeHttpClient = false) {
100+
if (options.CookieContainer != null) {
88101
throw new ArgumentException("Custom cookie container cannot be added to the HttpClient instance", nameof(options.CookieContainer));
89102
}
90103

91104
UseDefaultSerializers();
92105

93106
HttpClient = httpClient;
94-
Options = options ?? new RestClientOptions();
95107
CookieContainer = new CookieContainer();
108+
Options = options;
96109
_disposeHttpClient = disposeHttpClient;
97110

98-
if (httpClient.BaseAddress != null && Options.BaseUrl == null) {
111+
if (httpClient.BaseAddress != null && options.BaseUrl == null) {
99112
Options.BaseUrl = httpClient.BaseAddress;
100113
}
101114

@@ -108,7 +121,7 @@ public RestClient(HttpClient httpClient, RestClientOptions? options = null, bool
108121
/// </summary>
109122
/// <param name="handler">Message handler instance to use for HttpClient</param>
110123
/// <param name="disposeHandler">Dispose the handler when disposing RestClient, true by default</param>
111-
public RestClient(HttpMessageHandler handler, bool disposeHandler = true) : this(new HttpClient(handler, disposeHandler), null, true) { }
124+
public RestClient(HttpMessageHandler handler, bool disposeHandler = true) : this(new HttpClient(handler, disposeHandler), true) { }
112125

113126
void ConfigureHttpClient(HttpClient httpClient) {
114127
if (Options.Timeout > 0) httpClient.Timeout = TimeSpan.FromMilliseconds(Options.Timeout);
@@ -159,7 +172,7 @@ public RestClient AddDefaultParameter(Parameter parameter) {
159172
);
160173

161174
if (!Options.AllowMultipleDefaultParametersWithSameName &&
162-
!MultiParameterTypes.Contains(parameter.Type) &&
175+
!MultiParameterTypes.Contains(parameter.Type) &&
163176
DefaultParameters.Any(x => x.Name == parameter.Name)) {
164177
throw new ArgumentException("A default parameters with the same name has already been added", nameof(parameter));
165178
}
@@ -218,4 +231,4 @@ public void Dispose() {
218231
Dispose(true);
219232
GC.SuppressFinalize(this);
220233
}
221-
}
234+
}

0 commit comments

Comments
 (0)