| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,13 +1,16 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | ||
| 3 | 3 | const { | |
| 4 | + ArrayPrototypeForEach, | ||
| 4 | 5 | NumberMAX_SAFE_INTEGER, | |
| 5 | 6 | StringPrototypeToLowerCase, | |
| 6 | 7 | Symbol, | |
| 7 | 8 | } = primordials; | |
| 8 | 9 | ||
| 10 | + const dc = require('diagnostics_channel'); | ||
| 9 | 11 | const { now } = require('internal/perf/utils'); | |
| 10 | 12 | const { MIMEType } = require('internal/mime'); | |
| 13 | + | ||
| 11 | 14 | const kInspectorRequestId = Symbol('kInspectorRequestId'); | |
| 12 | 15 | ||
| 13 | 16 | // https://chromedevtools.github.io/devtools-protocol/1-3/Network/#type-ResourceType | |
@@ -67,10 +70,30 @@ function sniffMimeType(contentType) { | |||
| 67 | 70 | }; | |
| 68 | 71 | } | |
| 69 | 72 | ||
| 73 | + function registerDiagnosticChannels(listenerPairs) { | ||
| 74 | + function enable() { | ||
| 75 | + ArrayPrototypeForEach(listenerPairs, ({ 0: channel, 1: listener }) => { | ||
| 76 | + dc.subscribe(channel, listener); | ||
| 77 | + }); | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + function disable() { | ||
| 81 | + ArrayPrototypeForEach(listenerPairs, ({ 0: channel, 1: listener }) => { | ||
| 82 | + dc.unsubscribe(channel, listener); | ||
| 83 | + }); | ||
| 84 | + } | ||
| 85 | + | ||
| 86 | + return { | ||
| 87 | + enable, | ||
| 88 | + disable, | ||
| 89 | + }; | ||
| 90 | + } | ||
| 91 | + | ||
| 70 | 92 | module.exports = { | |
| 71 | 93 | kInspectorRequestId, | |
| 72 | 94 | kResourceType, | |
| 73 | 95 | getMonotonicTime, | |
| 74 | 96 | getNextRequestId, | |
| 97 | + registerDiagnosticChannels, | ||
| 75 | 98 | sniffMimeType, | |
| 76 | 99 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,9 +13,9 @@ const { | |||
| 13 | 13 | kResourceType, | |
| 14 | 14 | getMonotonicTime, | |
| 15 | 15 | getNextRequestId, | |
| 16 | + registerDiagnosticChannels, | ||
| 16 | 17 | sniffMimeType, | |
| 17 | 18 | } = require('internal/inspector/network'); | |
| 18 | - const dc = require('diagnostics_channel'); | ||
| 19 | 19 | const { Network } = require('inspector'); | |
| 20 | 20 | ||
| 21 | 21 | const kRequestUrl = Symbol('kRequestUrl'); | |
@@ -129,19 +129,8 @@ function onClientResponseFinish({ request, response }) { | |||
| 129 | 129 | }); | |
| 130 | 130 | } | |
| 131 | 131 | ||
| 132 | - function enable() { | ||
| 133 | - dc.subscribe('http.client.request.created', onClientRequestCreated); | ||
| 134 | - dc.subscribe('http.client.request.error', onClientRequestError); | ||
| 135 | - dc.subscribe('http.client.response.finish', onClientResponseFinish); | ||
| 136 | - } | ||
| 137 | - | ||
| 138 | - function disable() { | ||
| 139 | - dc.unsubscribe('http.client.request.created', onClientRequestCreated); | ||
| 140 | - dc.unsubscribe('http.client.request.error', onClientRequestError); | ||
| 141 | - dc.unsubscribe('http.client.response.finish', onClientResponseFinish); | ||
| 142 | - } | ||
| 143 | - | ||
| 144 | - module.exports = { | ||
| 145 | - enable, | ||
| 146 | - disable, | ||
| 147 | - }; | ||
| 132 | + module.exports = registerDiagnosticChannels([ | ||
| 133 | + ['http.client.request.created', onClientRequestCreated], | ||
| 134 | + ['http.client.request.error', onClientRequestError], | ||
| 135 | + ['http.client.response.finish', onClientResponseFinish], | ||
| 136 | + ]); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,9 +13,9 @@ const { | |||
| 13 | 13 | kResourceType, | |
| 14 | 14 | getMonotonicTime, | |
| 15 | 15 | getNextRequestId, | |
| 16 | + registerDiagnosticChannels, | ||
| 16 | 17 | sniffMimeType, | |
| 17 | 18 | } = require('internal/inspector/network'); | |
| 18 | - const dc = require('diagnostics_channel'); | ||
| 19 | 19 | const { Network } = require('inspector'); | |
| 20 | 20 | const { | |
| 21 | 21 | HTTP2_HEADER_AUTHORITY, | |
@@ -170,21 +170,9 @@ function onClientStreamClose({ stream }) { | |||
| 170 | 170 | }); | |
| 171 | 171 | } | |
| 172 | 172 | ||
| 173 | - function enable() { | ||
| 174 | - dc.subscribe('http2.client.stream.created', onClientStreamCreated); | ||
| 175 | - dc.subscribe('http2.client.stream.error', onClientStreamError); | ||
| 176 | - dc.subscribe('http2.client.stream.finish', onClientStreamFinish); | ||
| 177 | - dc.subscribe('http2.client.stream.close', onClientStreamClose); | ||
| 178 | - } | ||
| 179 | - | ||
| 180 | - function disable() { | ||
| 181 | - dc.unsubscribe('http2.client.stream.created', onClientStreamCreated); | ||
| 182 | - dc.unsubscribe('http2.client.stream.error', onClientStreamError); | ||
| 183 | - dc.unsubscribe('http2.client.stream.finish', onClientStreamFinish); | ||
| 184 | - dc.unsubscribe('http2.client.stream.close', onClientStreamClose); | ||
| 185 | - } | ||
| 186 | - | ||
| 187 | - module.exports = { | ||
| 188 | - enable, | ||
| 189 | - disable, | ||
| 190 | - }; | ||
| 173 | + module.exports = registerDiagnosticChannels([ | ||
| 174 | + ['http2.client.stream.created', onClientStreamCreated], | ||
| 175 | + ['http2.client.stream.error', onClientStreamError], | ||
| 176 | + ['http2.client.stream.finish', onClientStreamFinish], | ||
| 177 | + ['http2.client.stream.close', onClientStreamClose], | ||
| 178 | + ]); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,9 +10,9 @@ const { | |||
| 10 | 10 | kResourceType, | |
| 11 | 11 | getMonotonicTime, | |
| 12 | 12 | getNextRequestId, | |
| 13 | + registerDiagnosticChannels, | ||
| 13 | 14 | sniffMimeType, | |
| 14 | 15 | } = require('internal/inspector/network'); | |
| 15 | - const dc = require('diagnostics_channel'); | ||
| 16 | 16 | const { Network } = require('inspector'); | |
| 17 | 17 | const { Buffer } = require('buffer'); | |
| 18 | 18 | ||
@@ -239,31 +239,14 @@ function onWebSocketClose({ websocket }) { | |||
| 239 | 239 | }); | |
| 240 | 240 | } | |
| 241 | 241 | ||
| 242 | - function enable() { | ||
| 243 | - dc.subscribe('undici:request:create', onClientRequestStart); | ||
| 244 | - dc.subscribe('undici:request:error', onClientRequestError); | ||
| 245 | - dc.subscribe('undici:request:headers', onClientResponseHeaders); | ||
| 246 | - dc.subscribe('undici:request:trailers', onClientResponseFinish); | ||
| 247 | - dc.subscribe('undici:request:bodyChunkSent', onClientRequestBodyChunkSent); | ||
| 248 | - dc.subscribe('undici:request:bodySent', onClientRequestBodySent); | ||
| 249 | - dc.subscribe('undici:request:bodyChunkReceived', onClientRequestBodyChunkReceived); | ||
| 250 | - dc.subscribe('undici:websocket:open', onWebSocketOpen); | ||
| 251 | - dc.subscribe('undici:websocket:close', onWebSocketClose); | ||
| 252 | - } | ||
| 253 | - | ||
| 254 | - function disable() { | ||
| 255 | - dc.unsubscribe('undici:request:create', onClientRequestStart); | ||
| 256 | - dc.unsubscribe('undici:request:error', onClientRequestError); | ||
| 257 | - dc.unsubscribe('undici:request:headers', onClientResponseHeaders); | ||
| 258 | - dc.unsubscribe('undici:request:trailers', onClientResponseFinish); | ||
| 259 | - dc.unsubscribe('undici:request:bodyChunkSent', onClientRequestBodyChunkSent); | ||
| 260 | - dc.unsubscribe('undici:request:bodySent', onClientRequestBodySent); | ||
| 261 | - dc.unsubscribe('undici:request:bodyChunkReceived', onClientRequestBodyChunkReceived); | ||
| 262 | - dc.unsubscribe('undici:websocket:open', onWebSocketOpen); | ||
| 263 | - dc.unsubscribe('undici:websocket:close', onWebSocketClose); | ||
| 264 | - } | ||
| 265 | - | ||
| 266 | - module.exports = { | ||
| 267 | - enable, | ||
| 268 | - disable, | ||
| 269 | - }; | ||
| 242 | + module.exports = registerDiagnosticChannels([ | ||
| 243 | + ['undici:request:create', onClientRequestStart], | ||
| 244 | + ['undici:request:error', onClientRequestError], | ||
| 245 | + ['undici:request:headers', onClientResponseHeaders], | ||
| 246 | + ['undici:request:trailers', onClientResponseFinish], | ||
| 247 | + ['undici:request:bodyChunkSent', onClientRequestBodyChunkSent], | ||
| 248 | + ['undici:request:bodySent', onClientRequestBodySent], | ||
| 249 | + ['undici:request:bodyChunkReceived', onClientRequestBodyChunkReceived], | ||
| 250 | + ['undici:websocket:open', onWebSocketOpen], | ||
| 251 | + ['undici:websocket:close', onWebSocketClose], | ||
| 252 | + ]); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments