I have encountered an issue with NSURLSession when a request to "http" results in a redirection to "https" with the same host and path (HTTP status code 302). In this case the delegate method "URLSession:task:willPerformHTTPRedirection:newRequest:completionHandler:" is not(!) called. For other redirections the delegate methods is called as expected.
In my App I'm using UIWebView to access web sites and NSURLProtocol to do filtering and other stuff, so I can see the details of the network traffic.
Is there a worksround available for this? Am I doing something wrong? Why is NSURLSession forgetting to call the delegate method in this case?
Right now I'm checking in the delegate method "URLSession:dataTask:didReceiveResponse:completionHandler:" if the URL of the response has a different URL scheme ("https") than the initial request - if yes I call "[URLProtocolClient URLProtocol:wasRedirectedToRequest:request redirectResponse:]" in my NSURLProtocol class to "simulate" the missing redirection notification, so the caller (UIWebView) gets notified. But I'm not sure if this has some negative side effects, especially because I'm not yet sure if I've found all circumstances under which this bug within NSURLSession occurs and what exactly UIWebView is doing when it receives a redirection notification.