@@ -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