Repository navigation
Description
Context
Set-Cookie headers are silently stripped from responses on iOS / Mac Catalyst when HttpClient is backed by NSUrlSessionHandler (the MAUI default). NSURLSession consumes the cookie into NSHTTPCookieStorage.SharedStorage before the header is surfaced to .NET, so RestSharp's ParseResponseCookies finds nothing to parse and RestResponse.Cookies is empty.
RestSharp can't fix this in the core library without either pulling iOS workload dependencies into a netstandard2.0 package (unacceptable) or adopting a cookie-pooling strategy that re-introduces cross-tenant cookie leaks (the very reason UseCookies = false is the default).
The fix is to suppress NSURLSession's native cookie handling so the header reaches .NET intact. This belongs in the docs.
See #2168 (root-cause discussion) and #2385 (duplicate with the cleanest reproducer).
What to add
A page under "Advanced topics" (or near "Cookies") titled something like iOS / MAUI cookie handling with:
-
Symptom description:
Set-Cookiemissing on iOS, works on Android/Windows/Linux. -
Root cause one-liner: NSURLSession intercepts the header before .NET sees it.
-
The recipe:
#if IOS || MACCATALYST using Foundation; var options = new RestClientOptions(baseUrl) { ConfigureMessageHandler = _ => { var config = NSUrlSessionConfiguration.DefaultSessionConfiguration; config.HttpCookieStorage = null; config.HttpCookieAcceptPolicy = NSHttpCookieAcceptPolicy.Never; return new NSUrlSessionHandler(config); } }; #endif
-
Why this preserves multi-tenant safety: no cookie storage anywhere except RestSharp's per-request
CookieContainer, so cookies cannot leak between calls or between tenants sharing aRestClient. -
What not to do: set
HttpClientHandler.UseCookies = truewith a sharedCookieContainer. It "works" but pools cookies across every call made on that client — broken for multi-tenant use.
Acceptance criteria
- New page in the Docusaurus site, linked from the cookies section.
- Includes the recipe verbatim and the rationale.
- Cross-linked from Cookies are not added to cookie container when running on iOS #2168 and any future iOS cookie issues.
Activity
amirhmd commentedon Jul 2, 2026
Hi @alexeyzimarev — following up on this whenever you get a chance to look. I've addressed the handler-configuration note from the automated review. Happy to make any further adjustments. Thanks!
Add iOS/MAUI cookie handling docs (#2393)