public class NetworkEventReporterImpl extends java.lang.Object implements NetworkEventReporter
NetworkEventReporter which allows callers to inform the Stetho
system of network traffic. Callers can safely eagerly access this class and store a
reference if they wish. When WebKit Inspector clients are connected, the internal
implementation will be automatically wired up to them.NetworkEventReporter.InspectorHeaders, NetworkEventReporter.InspectorRequest, NetworkEventReporter.InspectorResponse| Modifier and Type | Method and Description |
|---|---|
void |
dataReceived(java.lang.String requestId,
int dataLength,
int encodedDataLength)
Indicates that raw data was received from the network.
|
void |
dataSent(java.lang.String requestId,
int dataLength,
int encodedDataLength)
Indicates that raw data was sent over the network.
|
static NetworkEventReporter |
get()
Static accessor allowing callers to easily hook into the WebKit Inspector system without
creating dependencies on the main Stetho initialization code path.
|
void |
httpExchangeFailed(java.lang.String requestId,
java.lang.String errorText)
Indicates that communication with the server has failed.
|
java.io.InputStream |
interpretResponseStream(java.lang.String requestId,
java.lang.String contentType,
java.lang.String contentEncoding,
java.io.InputStream availableInputStream,
ResponseHandler responseHandler)
Intercept the stream as given by the underlying HTTP library that contains the body of the
response.
|
boolean |
isEnabled()
Returns true if there is at least one peer listening for network events; false otherwise.
|
void |
requestWillBeSent(NetworkEventReporter.InspectorRequest request)
Indicates that a request is about to be sent, but has not yet been delivered over the wire.
|
void |
responseHeadersReceived(NetworkEventReporter.InspectorResponse response)
Indicates that a response message was just received from the network, but the body
has not yet been read.
|
void |
responseReadFailed(java.lang.String requestId,
java.lang.String errorText)
Indicates that there was a failure while reading from response stream.
|
void |
responseReadFinished(java.lang.String requestId)
Indicates that the response stream has been fully exhausted and the request is now
complete.
|
public static NetworkEventReporter get()
public boolean isEnabled()
NetworkEventReporterisEnabled in interface NetworkEventReporterpublic void requestWillBeSent(NetworkEventReporter.InspectorRequest request)
NetworkEventReporterrequestWillBeSent in interface NetworkEventReporterrequest - Request descriptor.public void responseHeadersReceived(NetworkEventReporter.InspectorResponse response)
NetworkEventReporterresponseHeadersReceived in interface NetworkEventReporterresponse - Response descriptor.public java.io.InputStream interpretResponseStream(java.lang.String requestId,
java.lang.String contentType,
java.lang.String contentEncoding,
java.io.InputStream availableInputStream,
ResponseHandler responseHandler)
NetworkEventReporter
We will internally signal a failure if there is an IOException received while reading
from the stream.
Do not invoke NetworkEventReporter.httpExchangeFailed(String, String) after calling this method.
interpretResponseStream in interface NetworkEventReporterrequestId - Unique identifier for the request as per NetworkEventReporter.InspectorRequest.id()contentType - The Content-Type header value that was specified in
NetworkEventReporter.InspectorResponse. This header is used to determine the appropriate
storage format for the body. For instance, image/* is necessary to cause
images to appear in the Inspector UI.contentEncoding - The Content-Encoding header value that was specified in
NetworkEventReporter.InspectorResponse. This header is used to determine what type of decompression
is to be applied when delivering the raw response stream to the debugging interface.
If null, no decompression will be used.availableInputStream - Response stream if applicable ("HEAD" for instance does not have a body).
null otherwise.responseHandler - Callback to forward stream events back to the relevant event reporter
methods. Recommend using DefaultResponseHandler for most callers.InputStream that has been intercepted if WebkitInspector is active and enabled
otherwise it will return inputStreampublic void httpExchangeFailed(java.lang.String requestId,
java.lang.String errorText)
NetworkEventReporterNetworkEventReporter.interpretResponseStream(java.lang.String, java.lang.String, java.lang.String, java.io.InputStream, com.facebook.stetho.inspector.network.ResponseHandler). After
NetworkEventReporter.interpretResponseStream(java.lang.String, java.lang.String, java.lang.String, java.io.InputStream, com.facebook.stetho.inspector.network.ResponseHandler) is called we will reporting any
IOException during reading from the InputStream.httpExchangeFailed in interface NetworkEventReporterrequestId - Unique identifier for the request as per NetworkEventReporter.InspectorRequest.id()errorText - Text to report for the error; using Throwable.toString() is
recommended.public void responseReadFinished(java.lang.String requestId)
NetworkEventReporterNetworkEventReporter.interpretResponseStream(java.lang.String, java.lang.String, java.lang.String, java.io.InputStream, com.facebook.stetho.inspector.network.ResponseHandler) with DefaultResponseHandler
(as is recommended), this method will be invoked automatically for you.responseReadFinished in interface NetworkEventReporterrequestId - Unique identifier for the request as per NetworkEventReporter.InspectorRequest.id()public void responseReadFailed(java.lang.String requestId,
java.lang.String errorText)
NetworkEventReporterNetworkEventReporter.interpretResponseStream(java.lang.String, java.lang.String, java.lang.String, java.io.InputStream, com.facebook.stetho.inspector.network.ResponseHandler) with DefaultResponseHandler (as is recommended),
this method will be invoked automatically for you.responseReadFailed in interface NetworkEventReporterrequestId - Unique identifier for the request as per NetworkEventReporter.InspectorRequest.id()errorText - Text to report for the error; using Throwable.toString() is
recommended.public void dataSent(java.lang.String requestId,
int dataLength,
int encodedDataLength)
NetworkEventReporterInvoking this method is optional and merely provides additional timing metrics and actual payload sizes to the Inspector UI.
dataSent in interface NetworkEventReporterrequestId - Unique identifier for the request as per NetworkEventReporter.InspectorRequest.id()dataLength - Uncompressed data segment lengthencodedDataLength - Compressed data segment lengthpublic void dataReceived(java.lang.String requestId,
int dataLength,
int encodedDataLength)
NetworkEventReporterdataReceived in interface NetworkEventReporterNetworkEventReporter.dataSent(java.lang.String, int, int)