I'm new to writing Mozilla extensions and would like to write a
Javascript extension which selectively modifies the URL of an HTTP
request before the request is performed. Rewriting the links after a
page has been loaded won't work because I also need to intercept URLs
which are dynamically generated by Javascript (yuck) -- so it needs to
happen on-the-fly.

I've looked at handling the "http-on-modify-request" and changing the
Host request header
but that doesn't seem to work.

Here`s a sample of my code.

var urlObserver= {
  observe: function(subject, topic, data){
    if (topic == "http-on-modify-request") {
      var httpChannel =
subject.QueryInterface(Components.interfaces.nsIHttpChannel);
                        if
(httpChannel.getRequestHeader("Host").toLowerCase().indexOf("doit.com") !
= -1){
                                        httpChannel.setRequestHeader("Host", 
"otherurl.com", false);
                        httpChannel.setRequestHeader("Referer", "", false);
        }else{
                if (logger){
                                logger.logInfo("Not Found...");
                                }
        }
    }
  }
};

var observerService = Components.classes["@mozilla.org/observer-
service;1"]
                                                                                
.getService(Components.interfaces.nsIObserverService);
observerService.addObserver(urlObserver, "http-on-modify-request",
false);


I`ll really appreciate if anyone can point me in the right direction,
thanks...
_______________________________________________
dev-tech-network mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-network

Reply via email to