I am trying to return a subclass object of NSURLResponse to my custom NSURLProtocol, but it seems that the response returned is always exchanged with the regular NSURLResponse.
This is part of NSURLProtocol where I return my custom TestURLResponse request:
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];
When I read something with this protocol, I expect to get a response like TestURLResponse, but in the following code I always get the NSURLResponse message:
NSURLRequest* request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"test://test"]];
NSURLResponse* response;
[NSURLConnection sendSynchronousRequest:request returningResponse:&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];
The entire test project can be downloaded to
http://ul.to/9yylk65s
Right now I have no idea that I am doing something wrong or if something is broken. NSURLProtocol state documentation.
The protocol designer may wish to create a custom, mutable NSURLResponse class to provide protocol related information.
, .