我的 Firefox-Addon 有问题。
使用我的扩展程序,我想重定向与特定模式匹配的请求。到目前为止,重定向工作正常
httpChannel.redirectTo()
现在我想添加/修改重定向的请求标头(如此处所述:https ://developer.mozilla.org/en-US/docs/Setting_HTTP_request_headers )
到目前为止我的代码:
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);
可悲的是,这条线
httpChannel.setRequestHeader("X-Hello", "World", false);
没有效果。我究竟做错了什么?
提前致谢!