我有一个扩展程序正在检查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');
};