Map Custom URL protocol to HTTP (using NSURLProtocol?)
- by Francisco Ryan Tolmasky I
I have an application using a WebKit WebView and I'd like to map URL's that are loaded in this WebView with a custom URL protocol to a different HTTP URL. For example, say I am loading:
custom://path/to/resource
I would like to internally actually load:
http://something-else.com/path/to/resource
In other words, the custom protocol serves almost as a shorthand. I can't however use -webView:resource:willSendRequest:redirectResponse:fromDataSource:, because I want WebKit to actually believe this is the URL in question, not to simply redirect from one to the other.
So far I've been attempting to use a custom NSURLProtocol subclass. However, this is proving trickier than I first thought because, at least to my understanding, I will have to do the actual loading myself in the NSURLProtocol subclass' startLoading method. I'd like a way to just hand off the work to the existing HTTP protocol loader, but I can't find an easy way to do this.
Does anyone have a recommendation for this, or perhaps an alternative way to solve this issue?
Thanks!