Re: Why does NSURLSession return NSURLResponse instead of NSHTTPURLResponse
Re: Why does NSURLSession return NSURLResponse instead of NSHTTPURLResponse
- Subject: Re: Why does NSURLSession return NSURLResponse instead of NSHTTPURLResponse
- From: email@hidden
- Date: Thu, 19 Oct 2017 16:39:28 -0400
Thanks for the replies everyone,
to answer some of the questions:
> On Oct 18, 2017, at 3:53 AM, Quinn The Eskimo! <email@hidden> wrote:
>
> Some questions / suggestions for moving this forward:
>
> * Do you have any NSURLProtocol subclasses in play here?
No other custom URL protocols involved
>
> * Are you sure that the crash is because you got an NSURLResponse? If you
> have some other problem you could get a similar looking crash. In
> Objective-C I typically write this:
>
> NSHTTPURLResponse * httpResponse = (NSHTTPURLResponse *) response;
> assert([httpResponse isKindOfClass:[NSHTTPURLResponse class]);
>
> so I’d trap this error immediately.
>
> * You could add a trap like this:
>
> assert([response.URL.scheme isEqual:@"http"]);
I put both asserts in, with the 'https' check first, and it always caught on
the class check.
>
> * You might want to enable a CFNetwork diagnostic log, per QA1887. If you
> can reproduce the crash with that logging enabled, it might reveal something
> interesting.
>
> <https://developer.apple.com/library/content/qa/qa1887/_index.html>
>
This was helpful.
The diagnostic showed that it was returning a cached response, so I looked
further into my code that adds to the cache.
In order to avoid hitting our server for future GETs, I use a custom
NSURLCache, that is also set to be used on the URL session's configuration;
when I push new data up to our server, I pre-cache the data to that URL cache
by creating a NSCachedURLResponse along with some additional metadata for
housekeeping purposes.
I think the problem was in the order I was adding the cached response relative
to the session request - the cached response would get added soon after the
session task was initiated, but before its completion block was called, which
seemed to make the session pick up that cached response at some point. Moving
the caching step to within the completion block solved the issue in my case.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden