fix(iOS): Send cookies with resource requests (#1803)

* iOS cookie available for resource requests

* Missig brace added

Co-authored-by: niwani <niwani@microsoft.com>
This commit is contained in:
nikitawani07
2021-03-10 10:11:09 +01:00
committed by GitHub
co-authored by niwani
parent dd315bcf87
commit 1f089baa40
+10
View File
@@ -543,6 +543,16 @@ static NSDictionary* customCertificatesForHost;
}
[_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];