firefox插件更改响应代码

msa*_*gel 6 firefox firefox-addon firefox-addon-sdk

我有一个扩展,检查http-on-examine-response侦听器中的响应.在听众可以通过改变头的HTTPChannel,并通过nsITraceableChannel我们可以改变响应内容.

但是如何在http-on-examine-response监听器中更改响应代码(例如从407到200)?

一些代码:

const { Ci, Cu, Cc, Cr } = require('chrome');

Cu.import('resource://gre/modules/Services.jsm');

var observer = {
  observe: function(aSubject, aTopic, aData) {
    if (aTopic == 'http-on-examine-response') {
        console.log('we are in observer http-on-examine-response');
        var httpChannel = aSubject.QueryInterface(Ci.nsIHttpChannel);
        if(httpChannel.responseStatus == 407){
            httpChannel.responseStatus = 200; // <-- this is not working
        }
    }

  }
};

Services.obs.addObserver(observer, 'http-on-examine-response', false);


exports.onUnload = function (aData, aReason) {
  Services.obs.removeObserver(observer, 'http-on-examine-response');
};
Run Code Online (Sandbox Code Playgroud)