Bug 1159078 - Display a useful message in network monitor response tab when response body is truncated. r=Honza
authorMartin Koroknay <koroknay@gmail.com>
Tue, 05 Mar 2019 13:55:07 +0000
changeset 520249 24a48c47224236b2aeaba54d39d509b34dbd188c
parent 520248 0bd2a637efa3b877d7145fe9d186afa6550e3ef2
child 520250 a70132c4c444ca959970fbc9bd6674d04c9586e4
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersHonza
bugs1159078
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1159078 - Display a useful message in network monitor response tab when response body is truncated. r=Honza Previously when a JSON response's size was over the limit specified in pref devtools.netmonitor.responseBodyLimit, when inspecting this response in the Network Monitor one simply saw a JSON parse error message. This was due to the fact that the response was truncated in this view and thus no longer a valid JSON, even if the actual response was a valid JSON. Of course the actual response could have been invalid in the first place -- there was no way to know. This patch will ensure that in such cases a truncation warning message is displayed instead of a parse error message, thus avoiding a likely misleading parse error message. Differential Revision: https://phabricator.services.mozilla.com/D19302
devtools/client/locales/en-US/netmonitor.properties
devtools/client/netmonitor/src/components/ResponsePanel.js
--- a/devtools/client/locales/en-US/netmonitor.properties
+++ b/devtools/client/locales/en-US/netmonitor.properties
@@ -126,16 +126,21 @@ jsonFilterText=Filter properties
 # LOCALIZATION NOTE (jsonScopeName): This is the text displayed
 # in the response tab of the network details pane for a JSON scope.
 jsonScopeName=JSON
 
 # LOCALIZATION NOTE (jsonpScopeName): This is the text displayed
 # in the response tab of the network details pane for a JSONP scope.
 jsonpScopeName=JSONP → callback %S()
 
+# LOCALIZATION NOTE (responseTruncated): This is the text displayed
+# in the response tab of the network details pane when the response is over
+# the truncation limit and thus was truncated.
+responseTruncated=Response has been truncated
+
 # LOCALIZATION NOTE (responsePreview): This is the text displayed
 # in the response tab of the network details pane for an HTML preview.
 responsePreview=Preview
 
 # LOCALIZATION NOTE (networkMenu.sortedAsc): This is the tooltip displayed
 # in the network table toolbar, for any column that is sorted ascending.
 networkMenu.sortedAsc=Sorted ascending
 
--- a/devtools/client/netmonitor/src/components/ResponsePanel.js
+++ b/devtools/client/netmonitor/src/components/ResponsePanel.js
@@ -2,16 +2,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
 const { Component, createFactory } = require("devtools/client/shared/vendor/react");
 const dom = require("devtools/client/shared/vendor/react-dom-factories");
 const PropTypes = require("devtools/client/shared/vendor/react-prop-types");
+const Services = require("Services");
 const { L10N } = require("../utils/l10n");
 const {
   decodeUnicodeBase64,
   fetchNetworkUpdatePacket,
   formDataURI,
   getUrlBaseName,
 } = require("../utils/request-utils");
 const { Filters } = require("../utils/filter-predicates");
@@ -22,16 +23,17 @@ const PropertiesView = createFactory(req
 const { div, img } = dom;
 const JSON_SCOPE_NAME = L10N.getStr("jsonScopeName");
 const JSON_FILTER_TEXT = L10N.getStr("jsonFilterText");
 const RESPONSE_IMG_NAME = L10N.getStr("netmonitor.response.name");
 const RESPONSE_IMG_DIMENSIONS = L10N.getStr("netmonitor.response.dimensions");
 const RESPONSE_IMG_MIMETYPE = L10N.getStr("netmonitor.response.mime");
 const RESPONSE_PAYLOAD = L10N.getStr("responsePayload");
 const RESPONSE_PREVIEW = L10N.getStr("responsePreview");
+const RESPONSE_TRUNCATED = L10N.getStr("responseTruncated");
 
 const JSON_VIEW_MIME_TYPE = "application/vnd.mozilla.json.view";
 
 /**
  * Response panel component
  * Displays the GET parameters and POST data of a request
  */
 class ResponsePanel extends Component {
@@ -97,18 +99,28 @@ class ResponsePanel extends Component {
    * MIME type for "json" after any word boundary. This works
    * for the standard "application/json", and also for custom
    * types like "x-bigcorp-json". Additionally, we also
    * directly parse the response text content to verify whether
    * it's json or not, to handle responses incorrectly labeled
    * as text/plain instead.
    */
   isJSON(mimeType, response) {
+    const limit = Services.prefs.getIntPref("devtools.netmonitor.responseBodyLimit");
+    const { request } = this.props;
     let json, error;
 
+    // Check if the response has been truncated, in which case no parse should
+    // be attempted.
+    if (limit <= request.responseContent.content.size) {
+      const result = {};
+      result.error = RESPONSE_TRUNCATED;
+      return result;
+    }
+
     try {
       json = JSON.parse(response);
     } catch (err) {
       if (this.isBase64(response)) {
         try {
           json = JSON.parse(atob(response));
         } catch (err64) {
           error = err;