I\'ve been trying at this for a long time now, and no good results.
var myObserver = {
observe: function(subject, topic, data)
{
if (topic == \"h
I am under the impression that you cannot do this at this level - I tried a variety of methods of externally "tricking" the code that calls for a nsIHttpChannel to be created (example at end of post).
What I would recommend is if you want a redirect, contact the channel's owner window (which works 99% of the time), and instruct it to redirect. I know that it's not going to behave the same, but since I don't know exactly why you're doing this, this will externally (to the user) appear to be doing the same thing as what you ask.
Here's the basics of what I was trying:
if(aTopic == "http-on-examine-response") {
var request = aSubject.QueryInterface(Components.interfaces.nsIHttpChannel);
if(!request.URI.spec.match("^http://www.apple.com/")) {
var ios = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
var ch = ios.newChannel("http://www.apple.com/", null, null);
var listener = {
QueryInterface : XPCOMUtils.generateQI([Ci.nsIChannelEventSink]),
onDataAvailable: function() {},
onStopRequest: function() {},
onStartRequest: function() {}
};
ch.asyncOpen(listener,null);
var eventSink = request.notificationCallbacks.getInterface(Ci.nsIChannelEventSink);
eventSink.asyncOnChannelRedirect(request,ch,Ci.nsIChannelEventSink.REDIRECT_INTERNAL,function() {});
}