0

我的 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);

没有效果。我究竟做错了什么?

提前致谢!

4

1 回答 1

0

来自 IRC:

00:58 堕落的诺伊达:nsIChannelEventSink

00:58 堕落和 nsIInterfaceRequestor

00:59 Fallen 我没看链接

01:00 堕落的诺伊达:http: //mxr.mozilla.org/comm-central/source/calendar/providers/caldav/calDavCalendar.js#2828

@3und80 让我们对此进行更多研究并在这里开发解决方案。

于 2014-11-28T11:51:12.163 回答