Skip to content

Commit

Permalink
fix(iOS): Send cookies with resource requests (#1803)
Browse files Browse the repository at this point in the history
* iOS cookie available for resource requests

* Missig brace added

Co-authored-by: niwani <[email protected]>
  • Loading branch information
nikitawani07 and niwani authored Mar 10, 2021
1 parent dd315bc commit 1f089ba
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions apple/RNCWebView.m
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,16 @@ - (void)visitSource
}
[_webView loadHTMLString:html baseURL:baseURL];
return;
}
//Add cookie for subsequent resource requests sent by page itself, if cookie was set in headers on WebView
NSString *headerCookie = [RCTConvert NSString:_source[@"headers"][@"cookie"]];
if(headerCookie) {
NSDictionary *headers = [NSDictionary dictionaryWithObjectsAndKeys:headerCookie,@"Set-Cookie",nil];
NSURL *urlString = [NSURL URLWithString:_source[@"uri"]];
NSArray *httpCookies = [NSHTTPCookie cookiesWithResponseHeaderFields:headers forURL:urlString];
for (NSHTTPCookie *httpCookie in httpCookies) {
[_webView.configuration.websiteDataStore.httpCookieStore setCookie:httpCookie completionHandler:nil];
}
}

NSURLRequest *request = [self requestForSource:_source];
Expand Down

0 comments on commit 1f089ba

Please sign in to comment.