Skip to content
This repository was archived by the owner on Aug 13, 2018. It is now read-only.

Commit 7af89f2

Browse files
authored
Merge pull request #62 from firebug/feature/query-string-parsing
Query String parsing
2 parents 2021aa6 + baa0979 commit 7af89f2

File tree

8 files changed

+104
-0
lines changed

8 files changed

+104
-0
lines changed

chrome/locale/en-US/websocket-monitor.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ websocketmonitor.WAMP=WAMP
4747
# panel that displays MQTT messages.
4848
websocketmonitor.MQTT=MQTT
4949

50+
# LOCALIZATION NOTE (websocketmonitor.QueryString): A label used as a title for
51+
# side panel that displays messages formatted as a Query String (foo?bar=baz).
52+
websocketmonitor.QueryString=Query String
53+
5054
# LOCALIZATION NOTE (websocketmonitor.option.tabularView): A label and tooltip
5155
# used for a toolbar button that allows switching the frame list to
5256
# Tabular view

data/components/frame-list.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,13 @@ define(function (require, exports) {
211211
data: {"MQTT": mqtt},
212212
mode: "tiny"
213213
});
214+
} else if (this.props.config.enableQueryString !== false
215+
&& frame.queryString) {
216+
preview = TreeView({
217+
key: "preview-query",
218+
data: {"Query String": frame.queryString},
219+
mode: "tiny"
220+
});
214221
}
215222

216223
const label = (type == "send") ?

data/components/frame-table.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,12 @@ define(function (require, exports) {
208208
key: "preview-mqtt",
209209
data: {"MQTT": frame.mqtt},
210210
});
211+
} else if (this.props.config.enableQueryString !== false
212+
&& frame.queryString) {
213+
payload = TreeView({
214+
key: "preview-query",
215+
data: {"Query String": frame.queryString},
216+
});
211217
} else {
212218
// Fall back to showing a string
213219
payload = Str.cropString(frame.data.payload, 50);
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/* See license.txt for terms of usage */
2+
3+
"use strict";
4+
5+
define(function (require, exports) {
6+
// Dependencies
7+
const React = require("react");
8+
9+
// Firebug SDK
10+
const { Reps } = require("reps/repository");
11+
const { TreeView } = require("reps/tree-view");
12+
13+
// Shortcuts
14+
const { DIV } = Reps.DOM;
15+
16+
/**
17+
* Component responsible for rendering the Query String tab.
18+
*/
19+
let QueryStringTab = React.createClass({
20+
/** @lends QueryStringTab */
21+
22+
displayName: "QueryStringTab",
23+
24+
render: function () {
25+
let selectedFrame = this.props.selection || {};
26+
let data = selectedFrame.queryString;
27+
28+
return (
29+
DIV({className: "details"},
30+
TreeView({key: "QueryStringTabTree", data: data})
31+
)
32+
);
33+
}
34+
});
35+
36+
// Exports from this module
37+
exports.QueryStringTab = QueryStringTab;
38+
});
39+

data/components/sidebar.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ define(function (require, exports) {
1818
const { JSONTab } = createFactories(require("./json-tab"));
1919
const { WampTab } = createFactories(require("./wamp-tab"));
2020
const { MQTTTab } = createFactories(require("./mqtt-tab"));
21+
const { QueryStringTab } = createFactories(require("./query-string-tab"));
2122

2223
/**
2324
* @template This template represents a list of packets displayed
@@ -93,6 +94,14 @@ define(function (require, exports) {
9394
));
9495
}
9596

97+
if (selectedFrame && selectedFrame.queryString) {
98+
tabs.push(
99+
TabPanel({className: "mqtt", key: "queryString",
100+
title: Locale.$STR("websocketmonitor.QueryString")},
101+
QueryStringTab(this.props)
102+
));
103+
}
104+
96105
tabActive = Math.min(tabActive, tabs.length);
97106

98107
return (

data/view.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ define(function (require) {
6161
enableSockJs: Options.get("enableSockJs"),
6262
enableJson: Options.get("enableJson"),
6363
enableMqtt: Options.get("enableMqtt"),
64+
enableQueryString: Options.get("enableQueryString"),
6465
}
6566
});
6667

lib/wsm-panel.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ const WsmPanel = Class(
223223
data.wamp = this.decodeWampPacket(payload);
224224
data.json = this.decodeJsonPacket(payload);
225225
data.mqtt = this.decodeMqttPacket(payload);
226+
data.queryString = this.decodeQueryString(payload);
226227
},
227228

228229
// Socket.IO Parser
@@ -335,6 +336,36 @@ const WsmPanel = Class(
335336
}
336337
},
337338

339+
/**
340+
* Parse query strings
341+
*/
342+
decodeQueryString: function(data) {
343+
if (!prefs.enableQueryString) {
344+
return;
345+
}
346+
347+
// Check if the data matches foo?bar
348+
if (!/\w+\?.+/.test(data)) {
349+
return;
350+
}
351+
352+
const result = {};
353+
354+
var vars = data.substr(data.indexOf('?') + 1).split('&');
355+
vars.forEach(function(item) {
356+
var pair = item.split('=');
357+
358+
// ?foo&bar&baz is valid
359+
if (pair.length === 2) {
360+
result[pair[0]] = decodeURIComponent(pair[1]);
361+
} else {
362+
result[pair[0]] = undefined;
363+
}
364+
});
365+
366+
return result;
367+
},
368+
338369
// NetMonitor Overlay
339370

340371
/**

package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@
8282
"description": "Parse MQTT frames",
8383
"type": "bool",
8484
"value": true
85+
},
86+
{
87+
"name": "enableQueryString",
88+
"title": "Query string support",
89+
"description": "Parse query string frames (frames that look like foo&bar=baz)",
90+
"type": "bool",
91+
"value": true
8592
}
8693
]
8794
}

0 commit comments

Comments
 (0)