netfox icon indicating copy to clipboard operation
netfox copied to clipboard

NFXProtocol makes requests with Alamofire and canceled redirects hang until they timeout

Open tomaskraina opened this issue 5 years ago • 4 comments

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
    }

tomaskraina avatar Nov 19 '19 08:11 tomaskraina

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.

tomaskraina avatar Nov 19 '19 08:11 tomaskraina

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.

tomaskraina avatar Nov 19 '19 09:11 tomaskraina

I ran into the same problem using URLSession and URLSessionDataDelegate

jstubenrauch avatar Apr 26 '20 13:04 jstubenrauch

did someone found the solution? looks like I'm facing the same issue on some devices

rnkyr avatar Oct 18 '21 15:10 rnkyr