@@ -45,7 +45,7 @@ public partial class RestClient : IDisposable {
45
45
46
46
HttpClient HttpClient { get ; }
47
47
48
- internal RestClientOptions Options { get ; }
48
+ public RestClientOptions Options { get ; }
49
49
50
50
public RestClient ( RestClientOptions options , Action < HttpRequestHeaders > ? configureDefaultHeaders = null ) {
51
51
UseDefaultSerializers ( ) ;
@@ -83,19 +83,32 @@ public RestClient(Uri baseUrl) : this(new RestClientOptions { BaseUrl = baseUrl
83
83
/// <param name="baseUrl"></param>
84
84
public RestClient ( string baseUrl ) : this ( new Uri ( Ensure . NotEmptyString ( baseUrl , nameof ( baseUrl ) ) ) ) { }
85
85
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 ) {
88
101
throw new ArgumentException ( "Custom cookie container cannot be added to the HttpClient instance" , nameof ( options . CookieContainer ) ) ;
89
102
}
90
103
91
104
UseDefaultSerializers ( ) ;
92
105
93
106
HttpClient = httpClient ;
94
- Options = options ?? new RestClientOptions ( ) ;
95
107
CookieContainer = new CookieContainer ( ) ;
108
+ Options = options ;
96
109
_disposeHttpClient = disposeHttpClient ;
97
110
98
- if ( httpClient . BaseAddress != null && Options . BaseUrl == null ) {
111
+ if ( httpClient . BaseAddress != null && options . BaseUrl == null ) {
99
112
Options . BaseUrl = httpClient . BaseAddress ;
100
113
}
101
114
@@ -108,7 +121,7 @@ public RestClient(HttpClient httpClient, RestClientOptions? options = null, bool
108
121
/// </summary>
109
122
/// <param name="handler">Message handler instance to use for HttpClient</param>
110
123
/// <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 ) { }
112
125
113
126
void ConfigureHttpClient ( HttpClient httpClient ) {
114
127
if ( Options . Timeout > 0 ) httpClient . Timeout = TimeSpan . FromMilliseconds ( Options . Timeout ) ;
@@ -159,7 +172,7 @@ public RestClient AddDefaultParameter(Parameter parameter) {
159
172
) ;
160
173
161
174
if ( ! Options . AllowMultipleDefaultParametersWithSameName &&
162
- ! MultiParameterTypes . Contains ( parameter . Type ) &&
175
+ ! MultiParameterTypes . Contains ( parameter . Type ) &&
163
176
DefaultParameters . Any ( x => x . Name == parameter . Name ) ) {
164
177
throw new ArgumentException ( "A default parameters with the same name has already been added" , nameof ( parameter ) ) ;
165
178
}
@@ -218,4 +231,4 @@ public void Dispose() {
218
231
Dispose ( true ) ;
219
232
GC . SuppressFinalize ( this ) ;
220
233
}
221
- }
234
+ }
0 commit comments