简体   繁体   English

从Firefox扩展中取消HTTP GET请求

[英]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. 我有一个firefox扩展,它监听“http-on-modify-request”并检查来自firefox的所有GET请求。 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. 我希望能够取消请求(比如向页面返回失败代码)或修改请求的URI但似乎无法做到。 the nsiHttpChannel object just doesn't allow it - for instance 例如,nsiHttpChannel对象不允许它

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). 不工作(你不能修改URI)。

So how do you both intercept and modify http GET requests in a firefox extension. 那么你如何在firefox扩展中拦截修改 http GET请求。

delete httpChannel; just deletes the variable, sort of like saying httpChannel = undefined; 只是删除变量,有点像说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. 类似地,您的第二个想法是将变量设置为指向新的nsIHttpChannel实例,但旧请求仍未更改。

To modify the request, use its properties and methods. 要修改请求,请使用其属性和方法。 See nsIHttpChannel or nsIChannel or nsIRequest . 请参见nsIHttpChannelnsIChannelnsIRequest 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. 正如您所说,您无法修改URI,因此您可能希望取消它(请参阅下文)并将其替换为新URI。 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() 要取消它,请使用nsIRequest.cancel()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM