Firefox addon change response code

I have an extension that checks the response in the http-on-examine-response listener. In the listener, you can change the headers through httpChannel and through nsITraceableChannel we can change the content of the response.

But how to change the response code (for example, from 407 to 200) in the http-on-examine-response listener?

Some codes:

 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'); }; 
+7
firefox firefox-addon firefox-addon-sdk
source share

All Articles