nsIHttpChannel
.
nsISupports
最后修改于Gecko 1.9.0.4 使用这个接口的典型方式如下:
- 注册“http-on-examine-response”通知来跟综全部 HTTP 响应;
- 跳过重定义 (
responseStatus
= 3xx on nsIHttpChannel),否则你可能最终有两个监听视(listeners)注册通道(channel); - QI the channel passed as the "
subject
" to your observer tonsITraceableChannel
, and replace the defaultnsIStreamListener
(that passes the data to the original requester - e.g. to XMLHttpRequest or to the browser tab that made the request) with your own implementation (see "Implementing nsIStreamListener" below).
之后,你的 nsIStreamListener 实现将会获取到响应数据(response data),并且能够传递数据到原始的 nsIStreamListener(可能会修改它)。
See nsITraceableChannel, Intercept HTTP Traffic for a more detailed description with code samples.
See Modify URL before loading page in firefox for an overview of how to modify a request before it is made.
Method overview
nsIStreamListener setNewListener(in nsIStreamListener aListener); |
Methods
setNewListener()
用一个新的来替换该通道的当前监听器,返回先前分配给该通道的监听器。
nsIStreamListener setNewListener( in nsIStreamListener aListener );
参数
-
aListener
-
An
nsIStreamListener
to be notified of events on the HTTP channel.
返回值
该通道的前一个监听器。Each listener call through to the previous listener for every call, in order to establish a call chain to allow all interested parties a chance to act on each event.
实现 nsIStreamListener
一个 nsIStreamListener
接口传递给 setNewListener()
需要实现下列的方法,这是通过调用(这些方法)来通知它在 HTTP stream 上发生的事件:
onStartRequest
:一个 HTTP 请求开始。onDataAvailable:
数据到达 HTTP 通道(HTTP channel)。onStopRequest
:HTTP 请求结束。
onStartRequest
.Channels may restrict when you may replace the listener. In particular, listeners typically should not be replaced after onStartRequest
has been called.