Showing posts with label afnetworking. Show all posts
Showing posts with label afnetworking. Show all posts

Monday, August 14, 2017

NSURLSessionDownloadTask switching from http to https

Leave a Comment

I have an AFHTTPSessionManager created NSURLSessionDownloadTask being used to download a video within an app that sometimes when initialized with an http:80 url will convert it to https:443. This is happening before any connection attempt is being made (I added a custom HTTP protocol class via NSURLSessionConfiguration to the session in order to log when the connection is being made).

By the time the request makes it to the

-(NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)response  

delegate method of my CustomHTTPProtocolDelegate class, the request has been changed to https.

App Transport Security is disabled (NSAllowsArbitraryLoads=true) and this behavior seems to be associated with a particular http-only server (other http-only server have no issue, and the connection is made as http on port 80).

Any idea of what could be going on? Anything else I could do to debug?

Here is how the download task is being created (including the debug custom protocol class):

    NSURLRequest *request = [NSURLRequest requestWithURL:url];     NSURLSessionConfiguration* config = [NSURLSessionConfiguration ephemeralSessionConfiguration];     config.protocolClasses = @[[CustomHTTPProtocol class]];     AFHTTPSessionManager *session = [[AFHTTPSessionManager manager] initWithSessionConfiguration:config];      self.downloadTask = [session downloadTaskWithRequest:request  progress:&progress destination:^NSURL *(NSURL *targetPath, NSURLResponse *response){ 

...

[UPDATE] This issue is causing us a number of headaches, so to help facilitate troubleshooting, I created a small test project to help narrow in on the problem. My simple project does two things, loads a url into a UIWebView and downloads a file using NSURLSessionDownloadTask. The urls for these actions follow this pattern: WebView URL: https://console.company.com/home.html Download URL: http://data.company.com/file.txt And those hostnames resolve to different IPs (different servers).

If I download the file before navigating the webview, then everything is fine, but if the webview loads its URL first, then the download URL will be switched to HTTPS automatically and the initial request for data will fail. One thought we had was that once iOS opens a TLS tunnel for the HTTPS connection that the webview is creating, that it tries to use that same tunnel for all subsequent *.company.com connections. Or at the very least, it assumes all *.company.com connections must also be TLS.

1 Answers

Answers 1

Figured it out. Both servers were sending a HSTS header for all subdomains. Because the networking layer under NSURLSession observes this header, the calls to the HTTP server were being upgraded to HTTPS prior to leaving the client.

Read More

Thursday, March 24, 2016

cocoa pods Dependency management

Leave a Comment

[!] Unable to satisfy the following requirements:

  • SDWebImage (= 3.7) required by DZNPhotoPickerController/Core (1.6.0)
  • AFNetworking (~> 3.0) required by Podfile
  • AFNetworking (~> 1.3.3) required by DZNPhotoPickerController (1.0.2)

PodFile

pod 'DZNPhotoPickerController' pod 'ZXingObjC', '~> 3.0' pod 'vfrReader','~>2.8.6' pod 'Mantle' pod 'PPSSignatureView' pod 'AFNetworking','~>3.0' pod 'JNKeychain' pod 'SVProgressHUD' pod 'ZipArchive' 

I want to update AFNetworking.

Help me to solve this

3 Answers

Answers 1

To fix this you might need to

Fork the DZNPhotoPickerController repo and modify the dependency in the Pod spec and then use your forked repo's git location in the pod file. Not a great solution for the long term but works.

For instance, The Pod spec here should have the line#33 which is

ss.dependency 'AFNetworking' 

should be changed to

ss.dependency 'AFNetworking', '~> 3.0'  

in your forked repo.

Then use in your Pod file as below

pod 'DZNPhotoPickerController', :git => 'https://github.com/yourUsername/DZNPhotoPickerController.git' 

Your forked repo is not guaranteed to work out of the box if the project relies on legacy dependency code, if any. In this particular case, if it uses any methods of AFNetworking that is removed in 3.0 it will not work.

Answers 2

To update a single AFNetworking pod,

pod update AFNetworking 

with above code, cocoapods will find a latest updated pod version and update your pod.

To update your all pods you can use

pod update 

this will update your all the pods.

Answers 3

The issue looks like 'DZNPhotoPickerController' has dependancy of ss.dependency 'AFNetworking', '~> 2.6.0' so when you are trying to update AFNetworking to version 3.0 it shows the wrong version error.

If you didn't check it recently the 'DZNPhotoPickerController' has also updated it's podspec to make AFNetworking to 3.0 so you should try pod update now it may fix your issue as both dependancy needs the same version

If the above and the fork 'DZNPhotoPickerController' in to newer one didn't work

  • Please remove the 'DZNPhotoPickerController' from the cocoapods
  • update the cocoapods by pod update
  • if it's successful add the 'DZNPhotoPickerController' dependancy again in the cocoapods and install that again it may solve your problem
Read More