如何从nsITraceableChannel获取网址? [英] How to get an url from nsITraceableChannel?
问题描述
nsITraceableChannel,拦截HTTP流量,和主演在
$ b $ pre $
观察:function(aSubject,aTopic,aData){
if(aTopic ==http- on-examine-response){
var newListener = new TracingListener();
Subject.QueryInterface(Ci.nsITraceableChannel);
newListener.originalListener = aSubject.setNewListener(newListener);
$ / code $ / pre
现在我想知道如何从课程?它说了关于nsIHttpChannel的一些信息,但是我不知道怎么去解决这个问题。 nsIChannel
有一个 .URI
成员,您可以查询。你仍然需要QI到 nsIChannel
或者任何真正的子接口( nsITraceableChannel
不能从< code $> nsIChannel 尽管有名字)。 aSubject = aSubject.QueryInterface(Ci。 nsIChannel);
var uri = aSubject.URI;
//在任何其他解析器步骤之前请求的原始URI
//和/或重定向。
var ouri = aSubject.originalURI;
编辑
QueryInterface
确定会返回一些内容。在合同之后,它返回一个对这个
转换到所请求的接口(如果实现)的引用。 JS-XPCOM桥接了它,因此存储在JS封装器中,一个对象实现了一个特定的接口(同样发生在 instanceof
顺便说一句)。 b
$ b
ch = Services.io.newChannel(https://google.com/,null,null);
console.log(ch.toString());
//[xpconnect wrapped nsIChannel]
ch.QueryInterface(Ci.nsITraceableChannel);
console.log(ch.toString());
//[xpconnect wrapped(nsISupports,nsIChannel,nsITraceableChannel)]
console.log(ch instanceof Ci.nsIUploadChannel);
// true
console.log(ch.toString());
//[xpconnect wrapped(nsISupports,nsIChannel,nsITraceableChannel,nsIUploadChannel)]
//变量ch已知可以实现这四个给定的接口。
所以,实际上您不需要存储 .QueryInterface
,但这是常见的做法。另外,如果一个对象实现了多个定义相同(从JS的视角)方法的接口,那么使用调用的结果可能会非常方便。
无法通过一次调用查询两个接口。但我不认为有多个 .QueryInterface()
(和/或 instanceof
)调用有任何问题。
So, after reading nsITraceableChannel and nsITraceableChannel, Intercept HTTP Traffic, and starring at
observe: function(aSubject, aTopic, aData) {
if (aTopic == "http-on-examine-response") {
var newListener = new TracingListener();
aSubject.QueryInterface(Ci.nsITraceableChannel);
newListener.originalListener = aSubject.setNewListener(newListener);
}
}
I now wonder: how to get an exact url from aSubject? It says something about nsIHttpChannel, but I don't know how to get to that either.
nsIChannel
has an .URI
member which you can query. You'll still need to QI to nsIChannel
or any of the true sub-interfaces (nsITraceableChannel
does not inherit from nsIChannel
despite the name).
aSubject = aSubject.QueryInterface(Ci.nsIChannel);
var uri = aSubject.URI;
// original URI that was requested before any other resolver steps
// and/or redirects.
var ouri = aSubject.originalURI;
Edit
QueryInterface()
sure returns something. Following the contract it returns a reference to this
cast to the requested interface (if implemented). The JS-XPCOM bridge picks up on it and therefore stores in the JS-wrapper that an object implements a certain interface (same happens with instanceof
BTW).
ch = Services.io.newChannel("https://google.com/", null, null);
console.log(ch.toString());
// "[xpconnect wrapped nsIChannel]"
ch.QueryInterface(Ci.nsITraceableChannel);
console.log(ch.toString());
// "[xpconnect wrapped (nsISupports, nsIChannel, nsITraceableChannel)]"
console.log(ch instanceof Ci.nsIUploadChannel);
// true
console.log(ch.toString());
// "[xpconnect wrapped (nsISupports, nsIChannel, nsITraceableChannel, nsIUploadChannel)]"
// the variable "ch" is known to implement the four given interfaces at this point.
So, practically you don't need to store the result of .QueryInterface
, but it is common practice that you do. Also, using the result of the call may come handy if an object implements multiple interfaces that define the same (from the point-of-view of JS) methods.
You cannot query two interfaces with one call. But I don't think there is any issue with doing multiple .QueryInterface()
(and/or instanceof
) calls.
这篇关于如何从nsITraceableChannel获取网址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!