I am trying to get the HTTP response by reading the response header. But I am not able to retrieve anything. What I am missing exactly? Here is my code in index.js
var {Cc, Ci} = require("chrome");
var httpRequestObserver =
{
init: function() {
var observerService = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
observerService.addObserver(this, "http-on-examine-response", false);
},
observe: function(subject, topic, data)
{
if (topic == "http-on-examine-response") {
subject.QueryInterface(Ci.nsIHttpChannel);
this.onExamineResponse(subject);
}
},
onExamineResponse: function (oHttp)
{
console.log("Header :"+JSON.stringify(oHttp));
try
{
var header_value = oHttp.getResponseHeader("<the_header_that_i_need>");
// URI is the nsIURI of the response you're looking at
// and spec gives you the full URL string
var url = oHttp.URI.spec;
}
catch(err)
{
console.log(err);
}
}
};
httpRequestObserver.init();
I get reference from this stackoverflow and several online blogs.:- Firefox add-on SDK: Get http response headers
Edited
I Checked for the values in console.
- subject is coming as ()
- data is coming as null