Redirecting from a URL protocol

Christiaan Hofman <[email protected]> Fri, 8 Oct 2010 17:25:12 +0200
Newsgroups gmane.comp.macosx.devel
Message-ID <[email protected]>
Hi list,

I am trying to implement an NSURLProtocol subclass that should redirect certain custom URLs to some other (standard) URL, for instance to a file: URL pointing to a file inside the app bundle. It is not clear to me how to achieve this, and there is very little documentation and sample code about implementing NSURLProtocol, apart from the generic URL loading docs I could only find one sample that loads from some data rather than redirecting. And of course I tried Google and all without much success. 

What I seem to understand is that somehow I have to call -[NSURLProtocolClient URLProtocol:wasRedirectedToRequest:redirectResponse:] at some point, but it is not clear precisely how and where. Should I do that in -[NSURLProtocol startLoading]? In particular it is not clear what the redirectProtocol parameter should be. Also it is not clear to me whether and when I should call other client protocol methods.

Could anyone help me in pointing out how to do that, perhaps pointing to some sample code?

thanks,
Christiaan