Note that there are some explanatory texts on larger screens.

plurals
  1. POReturn custom NSURLResponse class
    primarykey
    data
    text
    <p>I try to return an object of a subclass of NSURLResponse in my custom NSURLProtocol, but it seems the returned response is always exchanged by a normal NSURLResponse.</p> <p>This is the part of the NSURLProtocol where I return my custom TestURLResponse:</p> <pre><code>TestURLResponse* response = [[[TestURLResponse alloc] initWithURL: [[self request] URL] MIMEType: @"text/plain" expectedContentLength: 4 textEncodingName:@"UTF-8"] autorelease]; [self.client URLProtocol:self didReceiveResponse:response cacheStoragePolicy:NSURLCacheStorageNotAllowed]; [self.client URLProtocol:self didLoadData: [@"Test" dataUsingEncoding:NSUTF8StringEncoding]]; [self.client URLProtocolDidFinishLoading: self]; </code></pre> <p>When I read something with this protocol I expect to get the response of type TestURLResponse, but in the following code I always get a NSURLResponse:</p> <pre><code> NSURLRequest* request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"test://test"]]; NSURLResponse* response; [NSURLConnection sendSynchronousRequest:request returningResponse:&amp;response error:nil]; NSString *className = NSStringFromClass([response class]); UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:className message:className delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alertView show]; [alertView release]; </code></pre> <p>The whole test project can be downloaded at </p> <p><a href="http://ul.to/9yylk65s">http://ul.to/9yylk65s</a></p> <p>Right now I have no idea if I'm doing something wrong or if there is something broken. The documentation of NSURLProtocol states</p> <blockquote> <p>A protocol implementor may wish to create a custom, mutable NSURLResponse class to provide protocol specific information.</p> </blockquote> <p>but it seems to me, this isn't working at all.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload