-
Notifications
You must be signed in to change notification settings - Fork 602
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
Fix for issue #174 - NSURLSessionTask completion block not called when not following redirects #175
Conversation
Thanks for the PR 👍 Looks ace! 👌 Could you please:
Thanks! |
When `-[NSURLSessionTaskDelegate URLSession:task:willPerformHTTPRedirection:newRequest:completionHandler:]` calls its completion handler with `nil` to indicate that the redirect should not be followed, the completion handler from `-[NSURLSession dataTaskWithRequest:completionHandler:]` is normally called with the actual redirect response itself. But when using OHTTPStubs such that a stub returns a redirect response, the task’s completion handler block is simply never called. - Ensure `OHHTTPStubsProtocol` finishes redirect responses fully when not following redirects. - Update `NSURLSessionTests` to exercise this behaviour. - Fix `AFNetworkingTests` test that had been looking for the incorrect behaviour.
Rebased and changelog updated. I also squashed it all into one commit and rewrote the commit message to describe the issue better. |
@adurdin In an effort to try and follow Moya's Contributor Guidelines, and to thank your for your recent contribution to |
Thank you, but I’ll decline. I’m not using |
@adurdin: Noted 😉 |
Ok, thanks! |
The standard behaviour of NSURLSession, when its delegate says not to follow redirects, and when no custom NSURLProtocol is managing things is to call the completion block with the actual redirect response, its data, and a nil error.
These commits fix OHHTTPStubsProtocol to implement the same behaviour. The behaviour when the delegate says to follow redirects is unchanged.
Note that Apple’s CustomHTTPProtocol sample code instead completes the redirect response with an NSURLErrorCancelled error, diverging from the standard behaviour.