| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 /** | 4 /** |
| 5 * @unrestricted | 5 * @unrestricted |
| 6 */ | 6 */ |
| 7 SDK.ServerTiming = class { | 7 SDK.ServerTiming = class { |
| 8 /** | 8 /** |
| 9 * @param {string} metric | 9 * @param {string} metric |
| 10 * @param {number} value | 10 * @param {?number} value |
| 11 * @param {string} description | 11 * @param {?string} description |
| 12 */ | 12 */ |
| 13 constructor(metric, value, description) { | 13 constructor(metric, value, description) { |
| 14 this.metric = metric; | 14 this.metric = metric; |
| 15 this.value = value; | 15 this.value = value; |
| 16 this.description = description; | 16 this.description = description; |
| 17 } | 17 } |
| 18 | 18 |
| 19 /** | 19 /** |
| 20 * @param {!Array<!SDK.NetworkRequest.NameValue>} headers | 20 * @param {!Array<!SDK.NetworkRequest.NameValue>} headers |
| 21 * @return {?Array<!SDK.ServerTiming>} | 21 * @return {?Array<!SDK.ServerTiming>} |
| (...skipping 10 matching lines...) Expand all Loading... |
| 32 function createFromHeaderValue(valueString) { | 32 function createFromHeaderValue(valueString) { |
| 33 // https://www.w3.org/TR/server-timing/ | 33 // https://www.w3.org/TR/server-timing/ |
| 34 var serverTimingMetricRegExp = | 34 var serverTimingMetricRegExp = |
| 35 /[ \t]*([\!\#\$\%\&\'\*\+\-\.\^\_\`\|\~0-9A-Za-z]+)[ \t]*(?:=[ \t]*(\d
+(?:\.\d+)?))?[ \t]*(?:;[ \t]*(?:"([^"]+)"|([\!\#\$\%\&\'\*\+\-\.\^\_\`\|\~0-9A-
Za-z]+)))?[ \t]*(?:,(.*))?/; | 35 /[ \t]*([\!\#\$\%\&\'\*\+\-\.\^\_\`\|\~0-9A-Za-z]+)[ \t]*(?:=[ \t]*(\d
+(?:\.\d+)?))?[ \t]*(?:;[ \t]*(?:"([^"]+)"|([\!\#\$\%\&\'\*\+\-\.\^\_\`\|\~0-9A-
Za-z]+)))?[ \t]*(?:,(.*))?/; |
| 36 var metricMatch; | 36 var metricMatch; |
| 37 var result = []; | 37 var result = []; |
| 38 while (valueString && (metricMatch = serverTimingMetricRegExp.exec(valueSt
ring))) { | 38 while (valueString && (metricMatch = serverTimingMetricRegExp.exec(valueSt
ring))) { |
| 39 var metric = metricMatch[1]; | 39 var metric = metricMatch[1]; |
| 40 var value = metricMatch[2]; | 40 var value = metricMatch[2]; |
| 41 var description = metricMatch[3] || metricMatch[4]; | 41 var description = metricMatch[3] || metricMatch[4]; |
| 42 if (value !== null) | 42 if (value !== undefined) |
| 43 value = Math.abs(parseFloat(metricMatch[2])); | 43 value = Math.abs(parseFloat(metricMatch[2])); |
| 44 valueString = metricMatch[5]; // comma delimited headers | 44 valueString = metricMatch[5]; // comma delimited headers |
| 45 if (value === undefined || isNaN(value)) |
| 46 value = null; |
| 45 result.push(new SDK.ServerTiming(metric, value, description)); | 47 result.push(new SDK.ServerTiming(metric, value, description)); |
| 46 } | 48 } |
| 47 return result; | 49 return result; |
| 48 } | 50 } |
| 49 | 51 |
| 50 var serverTimings = rawServerTimingHeaders.reduce((memo, header) => { | 52 var serverTimings = rawServerTimingHeaders.reduce((memo, header) => { |
| 51 var timing = createFromHeaderValue(header.value); | 53 var timing = createFromHeaderValue(header.value); |
| 52 Array.prototype.push.apply(memo, timing); | 54 Array.prototype.push.apply(memo, timing); |
| 53 return memo; | 55 return memo; |
| 54 }, []); | 56 }, []); |
| 55 serverTimings.sort((a, b) => a.metric.toLowerCase().compareTo(b.metric.toLow
erCase())); | 57 serverTimings.sort((a, b) => a.metric.toLowerCase().compareTo(b.metric.toLow
erCase())); |
| 56 return serverTimings; | 58 return serverTimings; |
| 57 } | 59 } |
| 58 }; | 60 }; |
| OLD | NEW |