Cookies set in a redirect response are not persisted

删除回忆录丶 提交于 2019-12-13 01:38:16

问题


This appears to be a related issue only on iOS: since updating React Native from 0.55 to 0.57. adding credentials: 'include' helps, but this flag does not help if you reopen the app. Cookie will be deleted after app relaunch.

Below link actually proposes a PR release around this, but even that is not resolving the error. https://github.com/facebook/react-native/commit/a6860487947ae0957f5dfa4979e92bc7740fecb0

This is addition to the file react-native/Libraries/Network/RCTHTTPRequestHandler.mm

- (void)URLSession:(NSURLSession *)session
              task:(NSURLSessionTask *)task
willPerformHTTPRedirection:(NSHTTPURLResponse *)response
        newRequest:(NSURLRequest *)request
 completionHandler:(void (^)(NSURLRequest *))completionHandler
{
  // Add the cookies to the new request
  // This is necessary because we're not letting iOS handle cookies by itself
  NSMutableURLRequest *nextRequest = [request mutableCopy];

  NSArray<NSHTTPCookie *> *cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:request.URL];
  nextRequest.allHTTPHeaderFields = [NSHTTPCookie requestHeaderFieldsWithCookies:cookies];
  completionHandler(nextRequest);
}

来源:https://stackoverflow.com/questions/54163056/cookies-set-in-a-redirect-response-are-not-persisted

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!