Skip to content

Commit fd06cd3

Browse files
committed
Refactor parsing of WPT HAR entry extensions.
Minor differences to output, e.g. ”yes” for ”Was pushed” instead of just ”1”.
1 parent da80c7a commit fd06cd3

File tree

2 files changed

+27
-36
lines changed

2 files changed

+27
-36
lines changed

Diff for: src/ts/waterfall/details-overlay/extract-details-keys.ts

+26-30
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,11 @@ import {
66
import {Entry, Header} from "../../typing/har";
77
import {WaterfallEntry} from "../../typing/waterfall";
88

9-
/** get experimental feature (usually WebPageTest) */
10-
let getExp = (harEntry: Entry, name: string): string => {
11-
return harEntry[name] || harEntry["_" + name] || harEntry.request[name] || harEntry.request["_" + name] || "";
9+
const byteSizeProperty = (title: string, input: string | number): KvTuple => {
10+
return [title, parseAndFormat(input, parsePositive, formatBytes)];
1211
};
13-
14-
/** get experimental feature and format it as byte */
15-
let getExpAsByte = (harEntry: Entry, name: string): string => {
16-
let resp = parseInt(getExp(harEntry, name), 10);
17-
return (isNaN(resp) || resp <= 0) ? "" : formatBytes(resp);
12+
const countProperty = (title: string, input: string | number): KvTuple => {
13+
return [title, parseAndFormat(input, parsePositive)];
1814
};
1915

2016
function parseGeneralDetails(entry: WaterfallEntry, requestID: number): KvTuple[] {
@@ -28,7 +24,7 @@ function parseGeneralDetails(entry: WaterfallEntry, requestID: number): KvTuple[
2824
["Server IPAddress", harEntry.serverIPAddress],
2925
["Connection", harEntry.connection],
3026
["Browser Priority", harEntry._priority || harEntry._initialPriority],
31-
["Was pushed", harEntry._was_pushed],
27+
["Was pushed", parseAndFormat(harEntry._was_pushed, parsePositive, () => "yes")],
3228
["Initiator (Loaded by)", harEntry._initiator],
3329
["Initiator Line", harEntry._initiator_line],
3430
["Host", getHeader(harEntry.request.headers, "Host")],
@@ -37,16 +33,16 @@ function parseGeneralDetails(entry: WaterfallEntry, requestID: number): KvTuple[
3733
["Expires", harEntry._expires],
3834
["Cache Time", parseAndFormat(harEntry._cache_time, parsePositive)],
3935
["CDN Provider", harEntry._cdn_provider],
40-
["ObjectSize", parseAndFormat(harEntry._objectSize, parsePositive, formatBytes)],
41-
["Bytes In (downloaded)", getExpAsByte(harEntry, "bytesIn")],
42-
["Bytes Out (uploaded)", getExpAsByte(harEntry, "bytesOut")],
43-
["JPEG Scan Count", parseAndFormat(harEntry._jpeg_scan_count, parsePositive)],
44-
["Gzip Total", getExpAsByte(harEntry, "gzip_total")],
45-
["Gzip Save", getExpAsByte(harEntry, "gzip_save")],
46-
["Minify Total", getExpAsByte(harEntry, "minify_total")],
47-
["Minify Save", getExpAsByte(harEntry, "minify_save")],
48-
["Image Total", getExpAsByte(harEntry, "image_total")],
49-
["Image Save", getExpAsByte(harEntry, "image_save")],
36+
byteSizeProperty("ObjectSize", harEntry._objectSize),
37+
byteSizeProperty("Bytes In (downloaded)", harEntry._bytesIn),
38+
byteSizeProperty("Bytes Out (uploaded)", harEntry._bytesOut),
39+
byteSizeProperty("JPEG Scan Count", harEntry._jpeg_scan_count),
40+
byteSizeProperty("Gzip Total", harEntry._gzip_total),
41+
byteSizeProperty("Gzip Save", harEntry._gzip_save),
42+
byteSizeProperty("Minify Total", harEntry._minify_total),
43+
byteSizeProperty("Minify Save", harEntry._minify_save),
44+
byteSizeProperty("Image Total", harEntry._image_total),
45+
byteSizeProperty("Image Save", harEntry._image_save),
5046
];
5147
}
5248

@@ -58,9 +54,9 @@ function parseRequestDetails(harEntry: Entry): KvTuple[] {
5854
return [
5955
["Method", request.method],
6056
["HTTP Version", request.httpVersion],
61-
["Bytes Out (uploaded)", getExpAsByte(harEntry, "bytesOut")],
62-
["Headers Size", parseAndFormat(request.headersSize, parseNonNegative, formatBytes)],
63-
["Body Size", parseAndFormat(request.bodySize, parseNonNegative, formatBytes)],
57+
byteSizeProperty("Bytes Out (uploaded)", harEntry._bytesOut),
58+
byteSizeProperty("Headers Size", request.headersSize),
59+
byteSizeProperty("Body Size", request.bodySize),
6460
["Comment", request.comment],
6561
stringHeader("User-Agent"),
6662
stringHeader("Host"),
@@ -72,8 +68,8 @@ function parseRequestDetails(harEntry: Entry): KvTuple[] {
7268
stringHeader("If-Modified-Since"),
7369
stringHeader("If-Range"),
7470
stringHeader("If-Unmodified-Since"),
75-
["Querystring parameters count", parseAndFormat(request.queryString.length, parsePositive)],
76-
["Cookies count", request.cookies.length],
71+
countProperty("Querystring parameters count", request.queryString.length),
72+
countProperty("Cookies count", request.cookies.length),
7773
];
7874
}
7975

@@ -98,18 +94,18 @@ function parseResponseDetails(harEntry: Entry): KvTuple[] {
9894
return [
9995
["Status", response.status + " " + response.statusText],
10096
["HTTP Version", response.httpVersion],
101-
["Bytes In (downloaded)", getExpAsByte(harEntry, "bytesIn")],
102-
["Headers Size", parseAndFormat(response.headersSize, parseNonNegative, formatBytes)],
103-
["Body Size", parseAndFormat(response.bodySize, parseNonNegative, formatBytes)],
97+
byteSizeProperty("Bytes In (downloaded)", harEntry._bytesIn),
98+
byteSizeProperty("Headers Size", response.headersSize),
99+
byteSizeProperty("Body Size", response.bodySize),
104100
["Content-Type", contentType],
105101
stringHeader("Cache-Control"),
106102
stringHeader("Content-Encoding"),
107103
dateHeader("Expires"),
108104
dateHeader("Last-Modified"),
109105
stringHeader("Pragma"),
110-
["Content-Length", parseAndFormat(contentLength, parseNonNegative, formatBytes)],
106+
byteSizeProperty("Content-Length", contentLength),
111107
["Content Size", (contentLength !== content.size.toString() ? formatBytes(content.size) : "")],
112-
["Content Compression", parseAndFormat(content.compression, parsePositive, formatBytes)],
108+
byteSizeProperty("Content Compression", content.compression),
113109
stringHeader("Connection"),
114110
stringHeader("ETag"),
115111
stringHeader("Accept-Patch"),
@@ -146,7 +142,7 @@ function parseTimings(entry: WaterfallEntry): KvTuple[] {
146142
}
147143

148144
/** Key/Value pair in array `["key", "value"]` */
149-
export type KvTuple = [string, string|number];
145+
export type KvTuple = [string, string];
150146

151147
/**
152148
* Data to show in overlay tabs

Diff for: src/ts/waterfall/details-overlay/html-details-body.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,8 @@ function makeDefinitionList(dlKeyValues: KvTuple[], addClass: boolean = false) {
99
let className = key.toLowerCase().replace(/[^a-z-]/g, "");
1010
return `class="${className || "no-colour"}"`;
1111
};
12-
const isValidTuple = (tuple: KvTuple): boolean => {
13-
const value = tuple[1];
14-
return (typeof value === "string" && value.length > 0) ||
15-
(typeof value === "number" && !(value === 0 || value === -1));
16-
};
1712
return dlKeyValues
18-
.filter(isValidTuple)
13+
.filter((tuple: KvTuple) => !tuple[1])
1914
.map((tuple) => `
2015
<dt ${makeClass(tuple[0])}>${tuple[0]}</dt>
2116
<dd>${tuple[1]}</dd>

0 commit comments

Comments
 (0)