dbukowski / DBDebugToolkit

Set of easy to use debugging tools for iOS developers & QA engineers.
MIT License
1.27k stars 114 forks source link

NSURLSession redirection handling broken #22

Closed TheDom closed 2 years ago

TheDom commented 6 years ago

We use AFNetworking and have code like the following

let httpSessionManager = AFHTTPSessionManager(baseURL: baseURL)
httpSessionManager.setTaskWillPerformHTTPRedirectionBlock { urlSession, task, response, request in
  return someCheck
    ? request
    : nil // Stop following redirect
}

After we integrated DBDebugToolkit we noticed that this block was not getting called anymore. Disabling networking logging via DBDebugToolkit.setNetworkRequestsLoggingEnabled(false) fixes the issue.

I looked at AFNetworking's related code (part 1, part 2) and it does not seem to do anything special which leads me to believe that this is a general issue.

Please let me know if additional information is needed to reproduce this behavior.

dbukowski commented 6 years ago

Hi, thanks for reporting that. I’m currently on vacation, so I will be able to take a look at it at the end of August. But for now, it could be helpful if you could tell me what iOS version you’re checking, as the requests logging works a little bit differently on iOS 9.

TheDom commented 6 years ago

Thank you for the quick reply, I appreciate it! :) We encountered this with Xcode 9.4.1 on the iOS 11.4 simulator.

dbukowski commented 5 years ago

First of all - sorry for a late response.

I can't reproduce that issue. Would it be possible to provide a small repo showing that problem? Or maybe you (or anyone else facing this issue) could add the needed code in DBURLProtocol.m? Probably it is needed to implement the - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task willPerformHTTPRedirection:(NSHTTPURLResponse *)response newRequest:(NSURLRequest *)newRequest completionHandler:(void (^)(NSURLRequest *))completionHandler method there. You could take a look for example here to see the implementation of that method in a NSURLProtocol subclass.

For now I'm labeling this issue with "help needed". PRs are welcome! 😉

TheDom commented 5 years ago

Thanks for looking into this issue!

While I am currently not able to look into a solution myself, I was able to put together a sample project as requested: DBDebugToolkitIssue22Sample.zip. Just open AppDelegate.swift for the relevant code. Please let me know if you have any further questions. 😃