Cancel HTTP GET Request from Firefox Extension

I have a firefox extension that listens for "http-on-modify-request" and checks for all GET requests coming from firefox. I would like to be able to cancel the request (for example, return a failure code to the page) or change the request URI, but cannot do this. the nsiHttpChannel object simply does not allow this - for example

delete httpChannel; 

or redirecting to an empty request

 httpChannel = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(Components.interfaces.nsIXMLHttpRequest); 

do not work (and you cannot change the URI).

So how do you both intercept and modify HTTP GET requests in the Firefox extension.

+7
source share
1 answer

delete httpChannel; just removes the variable, sort of like httpChannel = undefined; . The request itself does not change. Likewise, your second idea is simply setting a variable to point to a new instance of nsIHttpChannel, but the old request still hasn't changed.

To modify a query, use its properties and methods. See nsIHttpChannel or nsIChannel or nsIRequest . As you say, you cannot change the URI to cancel it (see below) and replace it with a new one. I don’t know exactly how to do this, but I think one of these three pages has an answer.

To undo it, use nsIRequest.cancel ()

+9
source

All Articles