Skip to content

Instantly share code, notes, and snippets.

@IsaAliev
Created December 28, 2019 18:56
Show Gist options
  • Save IsaAliev/236abd3f8f9751b79f1527215ed4f326 to your computer and use it in GitHub Desktop.
Save IsaAliev/236abd3f8f9751b79f1527215ed4f326 to your computer and use it in GitHub Desktop.
public func urlSession(_ session: URLSession, task: URLSessionTask, willPerformHTTPRedirection response: HTTPURLResponse, newRequest request: URLRequest, completionHandler: @escaping (URLRequest?) -> Void) {
guard let newRequest = (request as NSURLRequest).mutableCopy() as? NSMutableURLRequest else {
completionHandler(request)
return
}
if let cookies = HTTPCookieStorage.shared.cookies {
newRequest.allHTTPHeaderFields = HTTPCookie.requestHeaderFields(with: cookies)
completionHandler(newRequest as URLRequest)
return
}
completionHandler(request)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment