/
githubmirror
/
node
Обзор
Документация
Войти
/
githubmirror
/
node
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
lib/internal/inspector/network.js
92 строки
2 KB
James M Snell
util: add non-throwing MIMEType.parse
05 авг 2026, 16:57
Не верифицирован
05 авг 2026, 16:57
9e59c1a
Код
Авторство
О чём код?
'use strict'; const { ArrayPrototypeForEach, NumberMAX_SAFE_INTEGER, StringPrototypeToLowerCase, Symbol, } = primordials; const dc = require('diagnostics_channel'); 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) { const mimeTypeObj = MIMEType.parse(contentType); const mimeType = StringPrototypeToLowerCase(mimeTypeObj?.essence || ''); const charset = StringPrototypeToLowerCase(mimeTypeObj?.params.get('charset') || ''); return { __proto__: null, mimeType, charset, }; } function registerDiagnosticChannels(listenerPairs) { function enable() { ArrayPrototypeForEach(listenerPairs, ({ 0: channel, 1: listener }) => { dc.subscribe(channel, listener); }); } function disable() { ArrayPrototypeForEach(listenerPairs, ({ 0: channel, 1: listener }) => { dc.unsubscribe(channel, listener); }); } return { enable, disable, }; } module.exports = { kInspectorRequestId, kResourceType, getMonotonicTime, getNextRequestId, registerDiagnosticChannels, sniffMimeType, };