Reputation: 2043
I'm building a firefox addon and want to set a custom HTTP header. I've already done some googling and found Setting HTTP headers from a Firefox extension I however can't get it working.
I've tried placing it in my main.js and when that didn't work in one of my content scripts.
while in main.js the entire addon stops working, can't get a clear error from it though. When in the content script just that script stops working.
Can anyone help?
Upvotes: 2
Views: 3320
Reputation: 2602
For the addon-sdk you need to change that example a bit to look like this:
var chrome = require("chrome");
chrome.Cc["@mozilla.org/observer-service;1"].getService( chrome.Ci.nsIObserverService ).addObserver({
observe : function(subject, topic, data) {
var channel = subject.QueryInterface( chrome.Ci.nsIHttpChannel );
if ( /mysite/.test( channel.originalURI.host ) ) {
channel.setRequestHeader("x-mysite-extended", "true", false);
}
}
},"http-on-modify-request",false);
Note the mysite
, you'll want to replace that with your host site and the headers with your headers.
Upvotes: 7