Skip to content

Commit a678302

Browse files
author
Daniel Herzog
committed
Adding syntax highlighting for multipart boundary; Fixed some speclinks that had additional spaces
1 parent 3b82440 commit a678302

File tree

2 files changed

+27
-20
lines changed

2 files changed

+27
-20
lines changed

src/network/network_details_templates.js

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ window.templates.network || (window.templates.network = {});
55

66
(function(templates) {
77

8+
var HTTP_BOUNDARY_CLASS = "http-token-type-boundary";
9+
810
templates._wrap_col_or_row = function(wrap)
911
{
1012
// Wraps either ["elem", "text"] in a column
@@ -16,9 +18,13 @@ templates._wrap_col_or_row = function(wrap)
1618
return ["tr", ["td", wrap, "colspan", "2"]];
1719
};
1820

19-
templates._wrap_pre = function(str)
21+
templates._wrap_pre = function(str, additional_classname)
2022
{
21-
return ["pre", str, "class", "mono"];
23+
var classname = "mono";
24+
if (additional_classname)
25+
classname += " " + additional_classname;
26+
27+
return ["pre", str, "class", classname];
2228
};
2329

2430
templates.details = function(entry, left_val, do_raw)
@@ -70,14 +76,14 @@ templates._details_content = function(entry, do_raw)
7076
["tr",
7177
["th", ui_strings.S_HTTP_LABEL_METHOD + ":"],
7278
["td", entry.touched_network ? entry.last_method : ui_strings.S_RESOURCE_ALL_NOT_APPLICABLE],
73-
"data-spec", "http#" + entry.last_method
79+
"data-spec", "http#" + (entry.last_method).trim()
7480
],
7581
["tr",
7682
["th", ui_strings.M_NETWORK_REQUEST_DETAIL_STATUS + ":"],
7783
["td",
7884
entry.touched_network && responsecode ? String(responsecode) : ui_strings.S_RESOURCE_ALL_NOT_APPLICABLE
7985
],
80-
"data-spec", "http#" + entry.current_responsecode
86+
"data-spec", "http#" + (entry.current_responsecode).trim()
8187
]
8288
],
8389
entry.touched_network ? [] : this.did_not_touch_network(entry),
@@ -149,14 +155,14 @@ templates._make_header_template_func = function(is_request_headers)
149155
var attrs = ["class", "header-token-type-" + cls.HTTPHeaderTokenizer.classnames[token[TYPE]]];
150156
if (token[TYPE] === cls.HTTPHeaderTokenizer.types.NAME)
151157
{
152-
attrs.extend(["data-spec", "http#" + token[STR]]);
158+
attrs.extend(["data-spec", "http#" + (token[STR]).trim()]);
153159
}
154160
else
155161
if (token[TYPE] === cls.HTTPHeaderTokenizer.types.FIRST_LINE_PART)
156162
{
157163
if (firstline_tokens in add_data_spec)
158164
{
159-
attrs.extend(["data-spec", "http#" + token[STR]])
165+
attrs.extend(["data-spec", "http#" + (token[STR]).trim()]);
160166
}
161167
firstline_tokens++;
162168
}
@@ -187,7 +193,7 @@ templates._request_headers = function(req, do_raw)
187193
var map_func = this._make_header_template_func(true);
188194
return [
189195
["h2", ui_strings.S_NETWORK_REQUEST_DETAIL_REQUEST_TITLE],
190-
["pre", req.header_tokens.map(map_func), "class", "mono"]
196+
this._wrap_pre(req.header_tokens.map(map_func))
191197
];
192198
}
193199
}
@@ -231,7 +237,7 @@ templates._response_headers = function(resp, do_raw)
231237
var map_func = this._make_header_template_func(false);
232238
return [
233239
["h2", ui_strings.S_NETWORK_REQUEST_DETAIL_RESPONSE_TITLE],
234-
["pre", resp.header_tokens.map(map_func), "class", "mono"]
240+
this._wrap_pre(resp.header_tokens.map(map_func))
235241
];
236242
}
237243
return [];
@@ -252,14 +258,14 @@ templates.headers_list = function(headers, do_raw)
252258
{
253259
map_func = function(header)
254260
{
255-
return this._wrap_pre([["span", header.name + ":", "data-spec", "http#" + header.name], ["span", " " + header.value]]);
256-
};
261+
return this._wrap_pre([["span", header.name + ":", "data-spec", "http#" + (header.name).trim()], ["span", " " + header.value]]);
262+
}.bind(this);
257263
}
258264
else
259265
{
260266
map_func = function(header)
261267
{
262-
return [["th", header.name + ":", "data-spec", "http#" + header.name], ["td", header.value]];
268+
return [["th", header.name + ":", "data-spec", "http#" + (header.name).trim()], ["td", header.value]];
263269
};
264270
}
265271
return headers.map(map_func);
@@ -280,26 +286,26 @@ templates._request_body = function(req, do_raw)
280286
for (var n = 0, part; part = req.requestbody.partList[n]; n++)
281287
{
282288
if (use_raw_boundary && n === 0)
283-
ret.push(this._wrap_pre(req.boundary));
289+
ret.push(this._wrap_pre(req.boundary, HTTP_BOUNDARY_CLASS));
284290

285291
ret.extend(this.headers_list(part.headerList, do_raw));
286292
ret.push(this._wrap_pre("\n"));
287293
if (part.content && part.content.stringData)
288-
ret.push(["pre", part.content.stringData, "class", "mono network-body"]);
294+
ret.push(this._wrap_pre(part.content.stringData, "mono network-body"));
289295
else
290296
ret.push(["p", ui_strings.S_NETWORK_N_BYTE_BODY.replace("%s", part.contentLength)]);
291297

292298
if (n < req.requestbody.partList.length - 1)
293-
ret.push(use_raw_boundary ? this._wrap_pre(req.boundary) : ["hr"]);
299+
ret.push(use_raw_boundary ? this._wrap_pre(req.boundary, HTTP_BOUNDARY_CLASS) : ["hr"]);
294300
else if (use_raw_boundary)
295-
ret.push(this._wrap_pre(req.boundary + "--\n"));
301+
ret.push(this._wrap_pre(req.boundary + "--\n", HTTP_BOUNDARY_CLASS));
296302
}
297303
}
298304
else if (req.requestbody.mimeType.startswith("application/x-www-form-urlencoded"))
299305
{
300306
if (do_raw)
301307
{
302-
ret.push(["pre", req.requestbody.content.stringData, "class", "mono network-body"]);
308+
ret.push(this._wrap_pre(req.requestbody.content.stringData, "network-body"));
303309
}
304310
else
305311
{
@@ -325,7 +331,7 @@ templates._request_body = function(req, do_raw)
325331
var type = cls.ResourceUtil.mime_to_type(req.requestbody.mimeType);
326332
if (["markup", "script", "css", "text"].contains(type))
327333
{
328-
ret.push(["pre", req.requestbody.content.stringData, "class", "mono network-body"]);
334+
ret.push(this._wrap_pre(req.requestbody.content.stringData, "network-body"));
329335
}
330336
else
331337
{
@@ -350,7 +356,7 @@ templates._request_body = function(req, do_raw)
350356

351357
templates._response_body = function(resp, do_raw, is_last)
352358
{
353-
var ret = [this._wrap_pre("\n")]; // todo: no, then it's (really) empty there shouldn't be a separator either.
359+
var ret = [this._wrap_pre("\n")]; // todo: no, then it's (really) empty there shouldn't be a separator either. For images it looks a bit wrong too, since the img elem makes its own space too.
354360

355361
var classname = "";
356362
if (resp.body_unavailable ||
@@ -375,7 +381,7 @@ templates._response_body = function(resp, do_raw, is_last)
375381
if (["script", "markup", "css", "text"].contains(resp.logger_entry_type))
376382
{
377383
ret.push(
378-
["pre", resp.responsebody.content.stringData, "class", "network-body mono"]
384+
this._wrap_pre(resp.responsebody.content.stringData, "network-body")
379385
);
380386
}
381387
else if (resp.logger_entry_type == "image")

src/network/network_style.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,8 @@
282282
font-weight: bold;
283283
}
284284

285-
.network_logger .header-token-type-name
285+
.network_logger .header-token-type-name,
286+
.network_logger .http-token-type-boundary
286287
{
287288
color: #006C0E;
288289
}

0 commit comments

Comments
 (0)