in stetho/src/main/java/com/facebook/stetho/inspector/network/NetworkEventReporterImpl.java [70:108]
public void requestWillBeSent(InspectorRequest request) {
NetworkPeerManager peerManager = getPeerManagerIfEnabled();
if (peerManager != null) {
Network.Request requestJSON = new Network.Request();
requestJSON.url = request.url();
requestJSON.method = request.method();
requestJSON.headers = formatHeadersAsJSON(request);
requestJSON.postData = readBodyAsString(peerManager, request);
// Hack to use the initiator of SCRIPT to generate a fake call stack that includes
// the request's "friendly" name.
String requestFriendlyName = request.friendlyName();
Integer requestPriority = request.friendlyNameExtra();
Network.Initiator initiatorJSON = new Network.Initiator();
initiatorJSON.type = Network.InitiatorType.SCRIPT;
initiatorJSON.stackTrace = new ArrayList<Console.CallFrame>();
initiatorJSON.stackTrace.add(new Console.CallFrame(requestFriendlyName,
requestFriendlyName,
requestPriority != null ? requestPriority : 0 /* lineNumber */,
0 /* columnNumber */));
Network.RequestWillBeSentParams params = new Network.RequestWillBeSentParams();
params.requestId = request.id();
params.frameId = "1";
params.loaderId = "1";
params.documentURL = request.url();
params.request = requestJSON;
params.timestamp = stethoNow() / 1000.0;
params.initiator = initiatorJSON;
params.redirectResponse = null;
// Type is now required as of at least WebKit Inspector rev @188492. If you don't send
// it, Chrome will refuse to draw the row in the Network tab until the response is
// received (providing the type). This delay is very noticable on slow networks.
params.type = Page.ResourceType.OTHER;
peerManager.sendNotificationToPeers("Network.requestWillBeSent", params);
}
}