title: Selective URL rewriting from within a Firefox add-on?
body: <p>I'd like to create a Firefox add-on that rewrites certain URLs. For example, if the page attempts to load a file <a href="http://my.com/foo.js" rel="nofollow">http://my.com/foo.js</a>, I want to rewrite the URL so that it loads from <a href="http://my-other.org/bar.js" rel="nofollow">http://my-other.org/bar.js</a>. 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.</p>
  
  <p>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.</p>
  
  <p>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.</p>