This interface is used to allow intercepting of HTTP traffic. It is implemented by nsIHttpChannel.
Inherits from: nsISupports Last changed in Gecko

The typical way to use this interface is as follows:

After that your nsIStreamListener implementation will get the response data and will be able to pass the data on to the original nsIStreamListener (possibly modifying it).

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);



Replaces the channel's current listener with a new one, returning the listener previously assigned to the channel.

nsIStreamListener setNewListener(
  in nsIStreamListener aListener
An nsIStreamListener to be notified of events on the HTTP channel.
Return value

The previous listener for the 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.

Implementing nsIStreamListener

The nsIStreamListener passed to setNewListener() should implement the following methods, which are called to notify it of events that occur on the HTTP stream:

  • onStartRequest: An HTTP request is beginning.
  • onDataAvailable: Data is arriving on the HTTP channel.
  • onStopRequest: The HTTP request is ending.
Note: It is critical that you pass along requests to the previous listener as soon as possible -- especially for onStartRequest.

Channels may restrict when you may replace the listener. In particular, listeners typically should not be replaced after onStartRequest has been called.

Document Tags and Contributors

Last updated by: Sheppy,