Bug 1653743 - Send request body event for service workers r=jdescottes

Differential Revision: https://phabricator.services.mozilla.com/D84340
This commit is contained in:
Hubert Boma Manilla 2020-08-05 12:09:44 +00:00
parent c5a68f389a
commit 7c093a6ed4

View File

@ -476,9 +476,9 @@ NetworkObserver.prototype = {
const fromServiceWorker = this.interceptedChannels.has(channel);
this.interceptedChannels.delete(channel);
// If this is a cached response, there never was a request event
// so we need to construct one here so the frontend gets all the
// expected events.
// If this is a cached response (which are also emitted by service worker requests),
// there never was a request event so we need to construct one here
// so the frontend gets all the expected events.
let httpActivity = this.createOrGetActivityObject(channel);
if (!httpActivity.owner) {
httpActivity = this._createNetworkEvent(channel, {
@ -486,6 +486,12 @@ NetworkObserver.prototype = {
fromServiceWorker: fromServiceWorker,
});
}
// We need to send the request body to the frontend for
// the faked (cached/service worker request) event.
this._onRequestBodySent(httpActivity);
this._sendRequestBody(httpActivity);
httpActivity.owner.addResponseStart(
{
httpVersion: response.httpVersion,
@ -569,20 +575,7 @@ NetworkObserver.prototype = {
switch (activitySubtype) {
case gActivityDistributor.ACTIVITY_SUBTYPE_REQUEST_BODY_SENT:
this._onRequestBodySent(httpActivity);
if (httpActivity.sentBody !== null) {
const limit = Services.prefs.getIntPref(
"devtools.netmonitor.requestBodyLimit"
);
const size = httpActivity.sentBody.length;
if (size > limit && limit > 0) {
httpActivity.sentBody = httpActivity.sentBody.substr(0, limit);
}
httpActivity.owner.addRequestPostData({
text: httpActivity.sentBody,
size: size,
});
httpActivity.sentBody = null;
}
this._sendRequestBody(httpActivity);
break;
case gActivityDistributor.ACTIVITY_SUBTYPE_RESPONSE_HEADER:
this._onResponseHeader(httpActivity, extraStringData);
@ -1517,6 +1510,23 @@ NetworkObserver.prototype = {
};
},
_sendRequestBody: function(httpActivity) {
if (httpActivity.sentBody !== null) {
const limit = Services.prefs.getIntPref(
"devtools.netmonitor.requestBodyLimit"
);
const size = httpActivity.sentBody.length;
if (size > limit && limit > 0) {
httpActivity.sentBody = httpActivity.sentBody.substr(0, limit);
}
httpActivity.owner.addRequestPostData({
text: httpActivity.sentBody,
size: size,
});
httpActivity.sentBody = null;
}
},
/**
* Suspend observer activity. This is called when the Network monitor actor stops
* listening.