Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
tomaskraina opened this issue Nov 19, 2019 · 4 comments
Labels

Comments

@tomaskraina
Copy link

tomaskraina commented Nov 19, 2019

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 tomaskraina changed the title NFXProtocol makes requests with forbidden redirect hang until they timeout NFXProtocol makes requests with disallowed redirects hang until they timeout Nov 19, 2019
@tomaskraina
Copy link
Author

tomaskraina commented Nov 19, 2019

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
Copy link
Author

tomaskraina commented Nov 19, 2019

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 tomaskraina changed the title NFXProtocol makes requests with disallowed redirects hang until they timeout NFXProtocol makes requests with Alamofire and cancalled redirects hang until they timeout Nov 19, 2019
@tomaskraina tomaskraina changed the title NFXProtocol makes requests with Alamofire and cancalled redirects hang until they timeout NFXProtocol makes requests with Alamofire and canceled redirects hang until they timeout Nov 20, 2019
@jstubenrauch
Copy link

I ran into the same problem using URLSession and URLSessionDataDelegate

@rnkyr
Copy link

rnkyr commented Oct 18, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants