@@ -27,8 +27,6 @@ namespace RestSharp;
27
27
/// Client to translate RestRequests into Http requests and process response result
28
28
/// </summary>
29
29
public partial class RestClient : IDisposable {
30
- public CookieContainer CookieContainer { get ; }
31
-
32
30
/// <summary>
33
31
/// Content types that will be sent in the Accept header. The list is populated from the known serializers.
34
32
/// 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
51
49
UseDefaultSerializers ( ) ;
52
50
53
51
Options = options ;
54
- CookieContainer = Options . CookieContainer ?? new CookieContainer ( ) ;
55
52
_disposeHttpClient = true ;
56
53
57
54
var handler = new HttpClientHandler ( ) ;
@@ -71,23 +68,27 @@ public RestClient() : this(new RestClientOptions()) { }
71
68
72
69
/// <inheritdoc />
73
70
/// <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
75
72
/// </summary>
76
- /// <param name="baseUrl"></param>
73
+ /// <param name="baseUrl">Base URI for the new client </param>
77
74
public RestClient ( Uri baseUrl ) : this ( new RestClientOptions { BaseUrl = baseUrl } ) { }
78
75
79
76
/// <inheritdoc />
80
77
/// <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
82
79
/// </summary>
83
- /// <param name="baseUrl"></param>
80
+ /// <param name="baseUrl">Base URI for this new client as a string </param>
84
81
public RestClient ( string baseUrl ) : this ( new Uri ( Ensure . NotEmptyString ( baseUrl , nameof ( baseUrl ) ) ) ) { }
85
82
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>
86
88
public RestClient ( HttpClient httpClient , bool disposeHttpClient = false ) {
87
89
UseDefaultSerializers ( ) ;
88
90
89
91
HttpClient = httpClient ;
90
- CookieContainer = new CookieContainer ( ) ;
91
92
Options = new RestClientOptions ( ) ;
92
93
_disposeHttpClient = disposeHttpClient ;
93
94
@@ -96,15 +97,16 @@ public RestClient(HttpClient httpClient, bool disposeHttpClient = false) {
96
97
}
97
98
}
98
99
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>
99
106
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
-
104
107
UseDefaultSerializers ( ) ;
105
108
106
109
HttpClient = httpClient ;
107
- CookieContainer = new CookieContainer ( ) ;
108
110
Options = options ;
109
111
_disposeHttpClient = disposeHttpClient ;
110
112
@@ -134,9 +136,9 @@ void ConfigureHttpClient(HttpClient httpClient) {
134
136
}
135
137
136
138
void ConfigureHttpMessageHandler ( HttpClientHandler handler ) {
139
+ handler . UseCookies = false ;
137
140
handler . Credentials = Options . Credentials ;
138
141
handler . UseDefaultCredentials = Options . UseDefaultCredentials ;
139
- handler . CookieContainer = CookieContainer ;
140
142
handler . AutomaticDecompression = Options . AutomaticDecompression ;
141
143
handler . PreAuthenticate = Options . PreAuthenticate ;
142
144
handler . AllowAutoRedirect = Options . FollowRedirects ;
0 commit comments