I'm having trouble with my Firefox-Addon.
With my extension, I'd like to redirect requests that match a certain pattern. So far, the redirection is working fine with
httpChannel.redirectTo()
Now I'd like to add / modify the request headers for the redirection (as explained here: https://developer.mozilla.org/en-US/docs/Setting_HTTP_request_headers )
My code so far:
console.log("start");
const {Cu,Ci} = require('chrome');
Cu.import('resource://gre/modules/Services.jsm');
var httpRequestObserver =
{
observe: function(subject, topic, data)
{
var httpChannel, requestURL;
if (topic == "http-on-modify-request") {
httpChannel = subject.QueryInterface(Ci.nsIHttpChannel);
requestURL = httpChannel.URI.spec;
if (requestURL.indexOf('www.3und80.de') > -1) {
console.log("match url");
newURL = 'http://www.genialschenken.de/';
/*This has no effect*/
httpChannel.setRequestHeader("X-Hello", "World", false);
console.log("redirecting...");
httpChannel.redirectTo(Services.io.newURI(newURL, null, null));
}
return;
}
}
};
Services.obs.addObserver(httpRequestObserver, "http-on-modify-request", false);
Sadly, the line
httpChannel.setRequestHeader("X-Hello", "World", false);
has no effect. What am I doing wrong?
Thanks in advance!
From IRC:
@3und80 Let's research this more and develop an solution here.