Bug 1437435 - editing multi-line comments for isBase64, isJSON method, and other parts of the component. r=Honza
MozReview-Commit-ID: 2mIz0FV8pSM
--- a/devtools/client/netmonitor/src/components/ResponsePanel.js
+++ b/devtools/client/netmonitor/src/components/ResponsePanel.js
@@ -25,17 +25,17 @@ const JSON_FILTER_TEXT = L10N.getStr("js
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 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 {
static get propTypes() {
return {
request: PropTypes.object.isRequired,
openLink: PropTypes.func,
@@ -69,58 +69,67 @@ class ResponsePanel extends Component {
updateImageDimemsions({ target }) {
this.setState({
imageDimensions: {
width: target.naturalWidth,
height: target.naturalHeight,
},
});
}
- // Takes the response passed to the isJSON method by decoding and encoding
- // it to base 64. The final string is compared with the original response,
- // and returns true if the strings are the same. If the responses are not
- // the same, or an error is thrown, the method will return false.
+
+ /**
+ * The response passed to the isJSON method is decoded then encoded
+ * to base 64. The final string is compared with the original response,
+ * and returns true if the strings are the same. If the responses are not
+ * the same, or an error is thrown, the method will return false.
+ */
isBase64(response) {
try {
return btoa(atob(response)) == response;
} catch (err) {
return false;
}
}
- // Handle json, which we tentatively identify by checking the 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.
+ /**
+ * Handle json, which we tentatively identify by checking the 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) {
let json, error;
try {
json = JSON.parse(response);
} catch (err) {
try {
if (this.isBase64(response)) {
json = JSON.parse(atob(response));
}
} catch (err64) {
error = err;
}
}
if (/\bjson/.test(mimeType) || json) {
- // Extract the actual json substring in case this might be a "JSONP".
- // This regex basically parses a function call and captures the
- // function name and arguments in two separate groups.
+ /**
+ * the actual json substring in case this might be a "JSONP".
+ * This regex basically parses a function call and captures the
+ * function name and arguments in two separate groups.
+ */
let jsonpRegex = /^\s*([\w$]+)\s*\(\s*([^]*)\s*\)\s*;?\s*$/;
let [, jsonpCallback, jsonp] = response.match(jsonpRegex) || [];
let result = {};
- // Make sure this is a valid JSON object first. If so, nicely display
- // the parsing results in a tree view.
+ /**
+ * Make sure this is a valid JSON object first. If so, nicely display
+ * the parsing results in a tree view.
+ */
if (jsonpCallback && jsonp) {
error = null;
try {
json = JSON.parse(jsonp);
} catch (err) {
error = err;
}
}