Tony Tony - 6 months ago 28
Javascript Question

Read http Headers for extension

I want to get the complete information of a http header when a http request has made by using http-on-modify-request.

Example of the information i want to get:

enter image description here

i have this code:

myObserver.prototype = {
observe: function(subject, topic, data) {

if("http-on-modify-request"){
var httpChannel =
subject.QueryInterface(Components.interfaces.nsIHttpChannel);
alert("URI: " + httpChannel.originalURI.spec);
alert("User-Agent: " + httpChannel.getRequestHeader('user-agent'));
}

},
register: function() {
var observerService = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
observerService.addObserver(this, "http-on-modify-request", false);
},
unregister: function() {
var observerService = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
observerService.removeObserver(this, "http-on-modify-request");
}
}

Answer

I never used a way of getting them all at once, but you should be able to get them individually with the way you are doing.

I tried it too for the referer, but it didn't work, but i found that if you do:

 httpChannel.referrer.host 

(referrer has two r's), it shows the address of the referer.

Additionally, you might want to take a look at the source code of httpfox, it does what you are trying to do.

You might find additional help in this link: nsITraceableChannel, Intercept HTTP Traffic | Software is hard

And this one: Howto: XHR Listening by a Firefox Addon

Comments