Bug 1437435 - adding comments to isBase64 method, cleaning up whitespace and unnecessary code. r=Honza.
MozReview-Commit-ID: HETtcTqyQpT
--- a/devtools/client/netmonitor/src/components/ResponsePanel.js
+++ b/devtools/client/netmonitor/src/components/ResponsePanel.js
@@ -49,18 +49,16 @@ class ResponsePanel extends Component {
this.state = {
imageDimensions: {
width: 0,
height: 0,
},
};
this.updateImageDimemsions = this.updateImageDimemsions.bind(this);
- this.isBase64 = this.isBase64.bind(this);
- this.isJSON = this.isJSON.bind(this);
}
componentDidMount() {
let { request, connector } = this.props;
fetchNetworkUpdatePacket(connector.requestData, request, ["responseContent"]);
}
componentWillReceiveProps(nextProps) {
@@ -71,21 +69,24 @@ 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.
isBase64(response) {
try {
return btoa(atob(response)) == response;
- } catch(err) {
+ } 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
@@ -94,17 +95,17 @@ class ResponsePanel extends Component {
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