mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00

Support undici sent and received data inspection in Chrome DevTools. PR-URL: https://github.com/nodejs/node/pull/58953 Reviewed-By: Ryuhei Shima <shimaryuhei@gmail.com> Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
76 lines
1.6 KiB
JavaScript
76 lines
1.6 KiB
JavaScript
'use strict';
|
|
|
|
const {
|
|
NumberMAX_SAFE_INTEGER,
|
|
StringPrototypeToLowerCase,
|
|
Symbol,
|
|
} = primordials;
|
|
|
|
const { now } = require('internal/perf/utils');
|
|
const { MIMEType } = require('internal/mime');
|
|
const kInspectorRequestId = Symbol('kInspectorRequestId');
|
|
|
|
// https://chromedevtools.github.io/devtools-protocol/1-3/Network/#type-ResourceType
|
|
const kResourceType = {
|
|
Document: 'Document',
|
|
Stylesheet: 'Stylesheet',
|
|
Image: 'Image',
|
|
Media: 'Media',
|
|
Font: 'Font',
|
|
Script: 'Script',
|
|
TextTrack: 'TextTrack',
|
|
XHR: 'XHR',
|
|
Fetch: 'Fetch',
|
|
Prefetch: 'Prefetch',
|
|
EventSource: 'EventSource',
|
|
WebSocket: 'WebSocket',
|
|
Manifest: 'Manifest',
|
|
SignedExchange: 'SignedExchange',
|
|
Ping: 'Ping',
|
|
CSPViolationReport: 'CSPViolationReport',
|
|
Preflight: 'Preflight',
|
|
Other: 'Other',
|
|
};
|
|
|
|
/**
|
|
* Return a monotonically increasing time in seconds since an arbitrary point in the past.
|
|
* @returns {number}
|
|
*/
|
|
function getMonotonicTime() {
|
|
return now() / 1000;
|
|
}
|
|
|
|
let requestId = 0;
|
|
function getNextRequestId() {
|
|
if (requestId === NumberMAX_SAFE_INTEGER) {
|
|
requestId = 0;
|
|
}
|
|
return `node-network-event-${++requestId}`;
|
|
};
|
|
|
|
function sniffMimeType(contentType) {
|
|
let mimeType;
|
|
let charset;
|
|
try {
|
|
const mimeTypeObj = new MIMEType(contentType);
|
|
mimeType = StringPrototypeToLowerCase(mimeTypeObj.essence || '');
|
|
charset = StringPrototypeToLowerCase(mimeTypeObj.params.get('charset') || '');
|
|
} catch {
|
|
mimeType = '';
|
|
charset = '';
|
|
}
|
|
|
|
return {
|
|
__proto__: null,
|
|
mimeType,
|
|
charset,
|
|
};
|
|
}
|
|
|
|
module.exports = {
|
|
kInspectorRequestId,
|
|
kResourceType,
|
|
getMonotonicTime,
|
|
getNextRequestId,
|
|
sniffMimeType,
|
|
};
|