Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cancel an HTTP GET request from Firefox Extension

I have a firefox extension that listens to "http-on-modify-request" and inspects all GET requests coming from firefox. I'd like to be able to cancel the request (say return a fail code to the page) or modify the URI of the request but can't seem to do it. the nsiHttpChannel object just doesn't allow it - for instance

delete httpChannel;

or reseting to an empty request

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

don't work (and you can't modify the URI).

So how do you both intercept and modify http GET requests in a firefox extension.

like image 792
Anthony Bak Avatar asked Jan 25 '11 20:01

Anthony Bak


People also ask

How do I open HTTP request maker in Firefox?

Press Ctrl+Shift+Y to show the sidebar and make your own HTTP request.


1 Answers

delete httpChannel; just deletes the variable, sort of like saying httpChannel = undefined;. The request itself is unchanged. Similarly, your second idea just sets the variable to point at a new nsIHttpChannel instance, but the old request is still unchanged.

To modify the request, use its properties and methods. See nsIHttpChannel or nsIChannel or nsIRequest. As you say, you can't modify the URI so you might want to cancel it (see below) and replace it with a new one. I'm not sure exactly how to do that but I imagine one of those three pages has the answer.

To cancel it, use nsIRequest.cancel()

like image 106
Tyler Avatar answered Sep 27 '22 21:09

Tyler