@@ -27,8 +27,6 @@ namespace RestSharp;
2727/// Client to translate RestRequests into Http requests and process response result
2828/// </summary>
2929public partial class RestClient : IDisposable {
30- public CookieContainer CookieContainer { get ; }
31-
3230 /// <summary>
3331 /// Content types that will be sent in the Accept header. The list is populated from the known serializers.
3432 /// If you need to send something else by default, set this property to a different value.
@@ -51,7 +49,6 @@ public RestClient(RestClientOptions options, Action<HttpRequestHeaders>? configu
5149 UseDefaultSerializers ( ) ;
5250
5351 Options = options ;
54- CookieContainer = Options . CookieContainer ?? new CookieContainer ( ) ;
5552 _disposeHttpClient = true ;
5653
5754 var handler = new HttpClientHandler ( ) ;
@@ -71,23 +68,27 @@ public RestClient() : this(new RestClientOptions()) { }
7168
7269 /// <inheritdoc />
7370 /// <summary>
74- /// Sets the BaseUrl property for requests made by this client instance
71+ /// Creates an instance of RestClient using a specific BaseUrl for requests made by this client instance
7572 /// </summary>
76- /// <param name="baseUrl"></param>
73+ /// <param name="baseUrl">Base URI for the new client </param>
7774 public RestClient ( Uri baseUrl ) : this ( new RestClientOptions { BaseUrl = baseUrl } ) { }
7875
7976 /// <inheritdoc />
8077 /// <summary>
81- /// Sets the BaseUrl property for requests made by this client instance
78+ /// Creates an instance of RestClient using a specific BaseUrl for requests made by this client instance
8279 /// </summary>
83- /// <param name="baseUrl"></param>
80+ /// <param name="baseUrl">Base URI for this new client as a string </param>
8481 public RestClient ( string baseUrl ) : this ( new Uri ( Ensure . NotEmptyString ( baseUrl , nameof ( baseUrl ) ) ) ) { }
8582
83+ /// <summary>
84+ /// Creates an instance of RestClient using a shared HttpClient and does not allocate one internally.
85+ /// </summary>
86+ /// <param name="httpClient">HttpClient to use</param>
87+ /// <param name="disposeHttpClient">True to dispose of the client, false to assume the caller does (defaults to false)</param>
8688 public RestClient ( HttpClient httpClient , bool disposeHttpClient = false ) {
8789 UseDefaultSerializers ( ) ;
8890
8991 HttpClient = httpClient ;
90- CookieContainer = new CookieContainer ( ) ;
9192 Options = new RestClientOptions ( ) ;
9293 _disposeHttpClient = disposeHttpClient ;
9394
@@ -96,15 +97,16 @@ public RestClient(HttpClient httpClient, bool disposeHttpClient = false) {
9697 }
9798 }
9899
100+ /// <summary>
101+ /// Creates an instance of RestClient using a shared HttpClient and specific RestClientOptions and does not allocate one internally.
102+ /// </summary>
103+ /// <param name="httpClient">HttpClient to use</param>
104+ /// <param name="options">RestClient options to use</param>
105+ /// <param name="disposeHttpClient">True to dispose of the client, false to assume the caller does (defaults to false)</param>
99106 public RestClient ( HttpClient httpClient , RestClientOptions options , bool disposeHttpClient = false ) {
100- if ( options . CookieContainer != null ) {
101- throw new ArgumentException ( "Custom cookie container cannot be added to the HttpClient instance" , nameof ( options . CookieContainer ) ) ;
102- }
103-
104107 UseDefaultSerializers ( ) ;
105108
106109 HttpClient = httpClient ;
107- CookieContainer = new CookieContainer ( ) ;
108110 Options = options ;
109111 _disposeHttpClient = disposeHttpClient ;
110112
@@ -133,9 +135,9 @@ void ConfigureHttpClient(HttpClient httpClient) {
133135 }
134136
135137 void ConfigureHttpMessageHandler ( HttpClientHandler handler ) {
138+ handler . UseCookies = false ;
136139 handler . Credentials = Options . Credentials ;
137140 handler . UseDefaultCredentials = Options . UseDefaultCredentials ;
138- handler . CookieContainer = CookieContainer ;
139141 handler . AutomaticDecompression = Options . AutomaticDecompression ;
140142 handler . PreAuthenticate = Options . PreAuthenticate ;
141143 handler . AllowAutoRedirect = Options . FollowRedirects ;
0 commit comments