Map Custom URL protocol to HTTP (using NSURLProtocol?)

Posted by Francisco Ryan Tolmasky I on Stack Overflow See other posts from Stack Overflow or by Francisco Ryan Tolmasky I
Published on 2010-05-12T06:51:25Z Indexed on 2010/05/12 6:54 UTC
Read the original article Hit count: 324

Filed under:
|
|

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!

© Stack Overflow or respective owner

Related posts about cocoa

Related posts about webkit