| 60 | } |
| 61 | |
| 62 | export function getServerTimeHeader(timings?: Timings) { |
| 63 | if (!timings) return '' |
| 64 | return Object.entries(timings) |
| 65 | .map(([key, timingInfos]) => { |
| 66 | const dur = timingInfos |
| 67 | .reduce((acc, timingInfo) => { |
| 68 | const time = timingInfo.time ?? performance.now() - timingInfo.start |
| 69 | return acc + time |
| 70 | }, 0) |
| 71 | .toFixed(1) |
| 72 | const desc = timingInfos |
| 73 | .map((t) => t.desc) |
| 74 | .filter(Boolean) |
| 75 | .join(' & ') |
| 76 | return [ |
| 77 | key.replaceAll(/(:| |@|=|;|,|\/|\\)/g, '_'), |
| 78 | desc ? `desc=${JSON.stringify(desc)}` : null, |
| 79 | `dur=${dur}`, |
| 80 | ] |
| 81 | .filter(Boolean) |
| 82 | .join(';') |
| 83 | }) |
| 84 | .join(',') |
| 85 | } |
| 86 | |
| 87 | export function combineServerTimings(headers1: Headers, headers2: Headers) { |
| 88 | const newHeaders = new Headers(headers1) |