I'd like to create a Firefox add-on that rewrites certain URLs. For example, if the page attempts to load a file http://my.com/foo.js, I want to rewrite the URL so that it loads from http://my-other.org/bar.js. And I don't want it to look like a 302 redirect, because the request might have originated from an XHR call, and I don't want the browser to deny the request on a redirect on the grounds that it's cross-domain.
I've looked in the TamperData and HttpFox source code to learn how to solve this. I've tried creating an observer that listens for http-on-modify-request, and within the listener, attempts to rewrite the URL. The problem is that the nsiHttpChannel object seems to let me do just about everything - override headers, cancel the request, capture the response, etc - except override the URL. Simply changing the content of the originalURI and URI attributes of nsiHttpChannel doesn't seem to work either.
The only promising pointer I could find was to the HTTPS-everywhere addon, but the code there is rather intricate, and it feels like there ought to be a simpler way to achieve this.