netfox
netfox copied to clipboard
NFXProtocol makes requests with Alamofire and canceled redirects hang until they timeout
I have ran across an interesting problem in an app that has Netfox integrated.
When I implement the following method from the URLSessionDataDelegate protocol, the Netfox's implementation of URLProtocol will make the request hang until the timeoutInterval is reached and then it's reported as a timeout, even though the request is actually made.
What's interesting is that it only hangs if I call the completion handler with nil as a means to not allow the redirect. If I call it with the newRequest, everything works as expected.
func urlSession(_ session: URLSession, task: URLSessionTask, willPerformHTTPRedirection response: HTTPURLResponse, newRequest request: URLRequest, completionHandler: @escaping (URLRequest?) -> Void) {
completionHandler(nil) // if redirect is allowed, everything works
}
I have created a sample project demonstrating this issue: https://github.com/tomaskraina/NFXProtocolPlayground
However, my knowledge regarding URLProtocol is not yet that advanced to fix this issue.
Update: I've added another test case covering a request made using Alamofire. Turns out, it's only when using Alamofire the request times out.
It seems that when using just URLSession & URLSessionDataDelegate the all the redirects are followed automatically, without URLSessionDataDelegate even being called.
I ran into the same problem using URLSession and URLSessionDataDelegate
did someone found the solution? looks like I'm facing the same issue on some devices