2

I've written a custom subclass of NSURLProtocol, however it seems that whenever I use the protocol to load a request in UIWebView it assumes the data is content-type "text/html". Is there a way to specify that this content is actually something else (For instance "text/plain" or "image/png")?

BadPirate
  • 25,802
  • 10
  • 92
  • 123

2 Answers2

2

The content-type is actually carried by NSURLResponse, which you can modify by using the NSURLProtocolClient method URLProtocol:didReceiveResponse:cacheStoragePolicy: for instance, to set to text/plain

NSURLResponse *textResponse = [[NSURLResponse alloc] initWithURL:self.request.URL MIMEType:@"text/plain" expectedContentLength:100 textEncodingName:@"UTF-8"];
[self.client URLProtocol:self didReceiveResponse:textResponse cacheStoragePolicy:NSURLCacheStorageAllowedInMemoryOnly];
BadPirate
  • 25,802
  • 10
  • 92
  • 123
0

The content-type is carried by the NSMutableURLRequest.

[request setValue:@"image/png" forHTTPHeaderField:@"content-type"];
Daniel Amitay
  • 6,677
  • 7
  • 36
  • 43
  • Not quite the result I was looking for, this does seem to be useful for dictating the format of your request, I was looking at clarifying the format of the response. – BadPirate Feb 09 '11 at 19:27