GeezerVison is showing github.com — Revert "inspector: fix compressed responses" · nodejs/node@a27052f
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/internal/inspector/network.js -30Lines changed: 0 additions & 30 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -10,15 +10,8 @@ const { | 10 | 10 | const dc = require('diagnostics_channel'); | 11 | 11 | const { now } = require('internal/perf/utils'); | 12 | 12 | const { MIMEType } = require('internal/mime'); | 13 | | -const { | 14 | | - createGunzip, | 15 | | - createInflate, | 16 | | - createBrotliDecompress, | 17 | | - createZstdDecompress, | 18 | | -} = require('zlib'); | 19 | 13 |
| 20 | 14 | const kInspectorRequestId = Symbol('kInspectorRequestId'); | 21 | | -const kContentEncoding = Symbol('kContentEncoding'); | 22 | 15 |
| 23 | 16 | // https://chromedevtools.github.io/devtools-protocol/1-3/Network/#type-ResourceType | 24 | 17 | const kResourceType = { | @@ -77,27 +70,6 @@ function sniffMimeType(contentType) { | 77 | 70 | }; | 78 | 71 | } | 79 | 72 |
| 80 | | -/** | 81 | | - * Creates a decompression stream based on the content encoding. | 82 | | - * @param {string} encoding - The content encoding (e.g., 'gzip', 'deflate', 'br', 'zstd'). | 83 | | - * @returns {import('stream').Transform|null} - A decompression stream or null if encoding is not supported. | 84 | | - */ | 85 | | -function createDecompressor(encoding) { | 86 | | - switch (encoding) { | 87 | | - case 'gzip': | 88 | | - case 'x-gzip': | 89 | | - return createGunzip(); | 90 | | - case 'deflate': | 91 | | - return createInflate(); | 92 | | - case 'br': | 93 | | - return createBrotliDecompress(); | 94 | | - case 'zstd': | 95 | | - return createZstdDecompress(); | 96 | | - default: | 97 | | - return null; | 98 | | - } | 99 | | -} | 100 | | - | 101 | 73 | function registerDiagnosticChannels(listenerPairs) { | 102 | 74 | function enable() { | 103 | 75 | ArrayPrototypeForEach(listenerPairs, ({ 0: channel, 1: listener }) => { | @@ -119,11 +91,9 @@ function registerDiagnosticChannels(listenerPairs) { | 119 | 91 |
| 120 | 92 | module.exports = { | 121 | 93 | kInspectorRequestId, | 122 | | - kContentEncoding, | 123 | 94 | kResourceType, | 124 | 95 | getMonotonicTime, | 125 | 96 | getNextRequestId, | 126 | 97 | registerDiagnosticChannels, | 127 | 98 | sniffMimeType, | 128 | | - createDecompressor, | 129 | 99 | }; |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/inspector/network_http.js +17-66Lines changed: 17 additions & 66 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -10,13 +10,11 @@ const { | 10 | 10 |
| 11 | 11 | const { | 12 | 12 | kInspectorRequestId, | 13 | | - kContentEncoding, | 14 | 13 | kResourceType, | 15 | 14 | getMonotonicTime, | 16 | 15 | getNextRequestId, | 17 | 16 | registerDiagnosticChannels, | 18 | 17 | sniffMimeType, | 19 | | - createDecompressor, | 20 | 18 | } = require('internal/inspector/network'); | 21 | 19 | const { Network } = require('inspector'); | 22 | 20 | const EventEmitter = require('events'); | @@ -29,7 +27,6 @@ const convertHeaderObject = (headers = {}) => { | 29 | 27 | let host; | 30 | 28 | let charset; | 31 | 29 | let mimeType; | 32 | | - let contentEncoding; | 33 | 30 | const dict = {}; | 34 | 31 | for (const { 0: key, 1: value } of ObjectEntries(headers)) { | 35 | 32 | const lowerCasedKey = key.toLowerCase(); | @@ -41,9 +38,6 @@ const convertHeaderObject = (headers = {}) => { | 41 | 38 | charset = result.charset; | 42 | 39 | mimeType = result.mimeType; | 43 | 40 | } | 44 | | - if (lowerCasedKey === 'content-encoding') { | 45 | | - contentEncoding = typeof value === 'string' ? value.toLowerCase() : undefined; | 46 | | - } | 47 | 41 | if (typeof value === 'string') { | 48 | 42 | dict[key] = value; | 49 | 43 | } else if (ArrayIsArray(value)) { | @@ -56,7 +50,7 @@ const convertHeaderObject = (headers = {}) => { | 56 | 50 | dict[key] = String(value); | 57 | 51 | } | 58 | 52 | } | 59 | | - return [dict, host, charset, mimeType, contentEncoding]; | | 53 | + return [dict, host, charset, mimeType]; | 60 | 54 | }; | 61 | 55 |
| 62 | 56 | /** | @@ -111,10 +105,7 @@ function onClientResponseFinish({ request, response }) { | 111 | 105 | return; | 112 | 106 | } | 113 | 107 |
| 114 | | - const { 0: headers, 2: charset, 3: mimeType, 4: contentEncoding } = convertHeaderObject(response.headers); | 115 | | - | 116 | | - // Store content encoding on the request for later use | 117 | | - request[kContentEncoding] = contentEncoding; | | 108 | + const { 0: headers, 2: charset, 3: mimeType } = convertHeaderObject(response.headers); | 118 | 109 |
| 119 | 110 | Network.responseReceived({ | 120 | 111 | requestId: request[kInspectorRequestId], | @@ -130,64 +121,24 @@ function onClientResponseFinish({ request, response }) { | 130 | 121 | }, | 131 | 122 | }); | 132 | 123 |
| 133 | | - // Create a decompressor if the response is compressed | 134 | | - const decompressor = createDecompressor(contentEncoding); | 135 | | - | 136 | | - if (decompressor) { | 137 | | - // Pipe decompressed data to DevTools | 138 | | - decompressor.on('data', (decompressedChunk) => { | 139 | | - Network.dataReceived({ | 140 | | - requestId: request[kInspectorRequestId], | 141 | | - timestamp: getMonotonicTime(), | 142 | | - dataLength: decompressedChunk.byteLength, | 143 | | - encodedDataLength: decompressedChunk.byteLength, | 144 | | - data: decompressedChunk, | 145 | | - }); | 146 | | - }); | 147 | | - | 148 | | - // Handle decompression errors gracefully - fall back to raw data | 149 | | - decompressor.on('error', () => { | 150 | | - // If decompression fails, the raw data has already been sent via the fallback | 151 | | - }); | 152 | | - | 153 | | - // Unlike response.on('data', ...), this does not put the stream into flowing mode. | 154 | | - EventEmitter.prototype.on.call(response, 'data', (chunk) => { | 155 | | - // Feed the chunk into the decompressor | 156 | | - decompressor.write(chunk); | 157 | | - }); | 158 | | - | 159 | | - // Wait until the response body is consumed by user code. | 160 | | - response.once('end', () => { | 161 | | - // End the decompressor stream | 162 | | - decompressor.end(); | 163 | | - decompressor.once('end', () => { | 164 | | - Network.loadingFinished({ | 165 | | - requestId: request[kInspectorRequestId], | 166 | | - timestamp: getMonotonicTime(), | 167 | | - }); | 168 | | - }); | 169 | | - }); | 170 | | - } else { | 171 | | - // No decompression needed, send data directly | 172 | | - // Unlike response.on('data', ...), this does not put the stream into flowing mode. | 173 | | - EventEmitter.prototype.on.call(response, 'data', (chunk) => { | 174 | | - Network.dataReceived({ | 175 | | - requestId: request[kInspectorRequestId], | 176 | | - timestamp: getMonotonicTime(), | 177 | | - dataLength: chunk.byteLength, | 178 | | - encodedDataLength: chunk.byteLength, | 179 | | - data: chunk, | 180 | | - }); | | 124 | + // Unlike response.on('data', ...), this does not put the stream into flowing mode. | | 125 | + EventEmitter.prototype.on.call(response, 'data', (chunk) => { | | 126 | + Network.dataReceived({ | | 127 | + requestId: request[kInspectorRequestId], | | 128 | + timestamp: getMonotonicTime(), | | 129 | + dataLength: chunk.byteLength, | | 130 | + encodedDataLength: chunk.byteLength, | | 131 | + data: chunk, | 181 | 132 | }); | | 133 | + }); | 182 | 134 |
| 183 | | - // Wait until the response body is consumed by user code. | 184 | | - response.once('end', () => { | 185 | | - Network.loadingFinished({ | 186 | | - requestId: request[kInspectorRequestId], | 187 | | - timestamp: getMonotonicTime(), | 188 | | - }); | | 135 | + // Wait until the response body is consumed by user code. | | 136 | + response.once('end', () => { | | 137 | + Network.loadingFinished({ | | 138 | + requestId: request[kInspectorRequestId], | | 139 | + timestamp: getMonotonicTime(), | 189 | 140 | }); | 190 | | - } | | 141 | + }); | 191 | 142 | } | 192 | 143 |
| 193 | 144 | module.exports = registerDiagnosticChannels([ | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/inspector/network_http2.js +18-66Lines changed: 18 additions & 66 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -10,18 +10,15 @@ const { | 10 | 10 |
| 11 | 11 | const { | 12 | 12 | kInspectorRequestId, | 13 | | - kContentEncoding, | 14 | 13 | kResourceType, | 15 | 14 | getMonotonicTime, | 16 | 15 | getNextRequestId, | 17 | 16 | registerDiagnosticChannels, | 18 | 17 | sniffMimeType, | 19 | | - createDecompressor, | 20 | 18 | } = require('internal/inspector/network'); | 21 | 19 | const { Network } = require('inspector'); | 22 | 20 | const { | 23 | 21 | HTTP2_HEADER_AUTHORITY, | 24 | | - HTTP2_HEADER_CONTENT_ENCODING, | 25 | 22 | HTTP2_HEADER_CONTENT_TYPE, | 26 | 23 | HTTP2_HEADER_COOKIE, | 27 | 24 | HTTP2_HEADER_METHOD, | @@ -45,7 +42,6 @@ function convertHeaderObject(headers = {}) { | 45 | 42 | let statusCode; | 46 | 43 | let charset; | 47 | 44 | let mimeType; | 48 | | - let contentEncoding; | 49 | 45 | const dict = {}; | 50 | 46 |
| 51 | 47 | for (const { 0: key, 1: value } of ObjectEntries(headers)) { | @@ -65,8 +61,6 @@ function convertHeaderObject(headers = {}) { | 65 | 61 | const result = sniffMimeType(value); | 66 | 62 | charset = result.charset; | 67 | 63 | mimeType = result.mimeType; | 68 | | - } else if (lowerCasedKey === HTTP2_HEADER_CONTENT_ENCODING) { | 69 | | - contentEncoding = typeof value === 'string' ? value.toLowerCase() : undefined; | 70 | 64 | } | 71 | 65 |
| 72 | 66 | if (typeof value === 'string') { | @@ -84,7 +78,7 @@ function convertHeaderObject(headers = {}) { | 84 | 78 |
| 85 | 79 | const url = `${scheme}://${authority}${path}`; | 86 | 80 |
| 87 | | - return [dict, url, method, statusCode, charset, mimeType, contentEncoding]; | | 81 | + return [dict, url, method, statusCode, charset, mimeType]; | 88 | 82 | } | 89 | 83 |
| 90 | 84 | /** | @@ -200,16 +194,7 @@ function onClientStreamFinish({ stream, headers }) { | 200 | 194 | return; | 201 | 195 | } | 202 | 196 |
| 203 | | - const { | 204 | | - 0: convertedHeaderObject, | 205 | | - 3: statusCode, | 206 | | - 4: charset, | 207 | | - 5: mimeType, | 208 | | - 6: contentEncoding, | 209 | | - } = convertHeaderObject(headers); | 210 | | - | 211 | | - // Store content encoding on the stream for later use | 212 | | - stream[kContentEncoding] = contentEncoding; | | 197 | + const { 0: convertedHeaderObject, 3: statusCode, 4: charset, 5: mimeType } = convertHeaderObject(headers); | 213 | 198 |
| 214 | 199 | Network.responseReceived({ | 215 | 200 | requestId: stream[kInspectorRequestId], | @@ -225,56 +210,23 @@ function onClientStreamFinish({ stream, headers }) { | 225 | 210 | }, | 226 | 211 | }); | 227 | 212 |
| 228 | | - // Create a decompressor if the response is compressed | 229 | | - const decompressor = createDecompressor(contentEncoding); | 230 | | - | 231 | | - if (decompressor) { | 232 | | - // Pipe decompressed data to DevTools | 233 | | - decompressor.on('data', (decompressedChunk) => { | 234 | | - Network.dataReceived({ | 235 | | - requestId: stream[kInspectorRequestId], | 236 | | - timestamp: getMonotonicTime(), | 237 | | - dataLength: decompressedChunk.byteLength, | 238 | | - encodedDataLength: decompressedChunk.byteLength, | 239 | | - data: decompressedChunk, | 240 | | - }); | 241 | | - }); | 242 | | - | 243 | | - // Handle decompression errors gracefully | 244 | | - decompressor.on('error', () => { | 245 | | - // If decompression fails, the raw data has already been sent via the fallback | | 213 | + // Unlike stream.on('data', ...), this does not put the stream into flowing mode. | | 214 | + EventEmitter.prototype.on.call(stream, 'data', (chunk) => { | | 215 | + /** | | 216 | + * When a chunk of the response body has been received, cache it until `getResponseBody` request | | 217 | + * https://chromedevtools.github.io/devtools-protocol/1-3/Network/#method-getResponseBody or | | 218 | + * stream it with `streamResourceContent` request. | | 219 | + * https://chromedevtools.github.io/devtools-protocol/tot/Network/#method-streamResourceContent | | 220 | + */ | | 221 | + | | 222 | + Network.dataReceived({ | | 223 | + requestId: stream[kInspectorRequestId], | | 224 | + timestamp: getMonotonicTime(), | | 225 | + dataLength: chunk.byteLength, | | 226 | + encodedDataLength: chunk.byteLength, | | 227 | + data: chunk, | 246 | 228 | }); | 247 | | - | 248 | | - // Unlike stream.on('data', ...), this does not put the stream into flowing mode. | 249 | | - EventEmitter.prototype.on.call(stream, 'data', (chunk) => { | 250 | | - // Feed the chunk into the decompressor | 251 | | - decompressor.write(chunk); | 252 | | - }); | 253 | | - | 254 | | - // End the decompressor when the stream closes | 255 | | - stream.once('end', () => { | 256 | | - decompressor.end(); | 257 | | - }); | 258 | | - } else { | 259 | | - // No decompression needed, send data directly | 260 | | - // Unlike stream.on('data', ...), this does not put the stream into flowing mode. | 261 | | - EventEmitter.prototype.on.call(stream, 'data', (chunk) => { | 262 | | - /** | 263 | | - * When a chunk of the response body has been received, cache it until `getResponseBody` request | 264 | | - * https://chromedevtools.github.io/devtools-protocol/1-3/Network/#method-getResponseBody or | 265 | | - * stream it with `streamResourceContent` request. | 266 | | - * https://chromedevtools.github.io/devtools-protocol/tot/Network/#method-streamResourceContent | 267 | | - */ | 268 | | - | 269 | | - Network.dataReceived({ | 270 | | - requestId: stream[kInspectorRequestId], | 271 | | - timestamp: getMonotonicTime(), | 272 | | - dataLength: chunk.byteLength, | 273 | | - encodedDataLength: chunk.byteLength, | 274 | | - data: chunk, | 275 | | - }); | 276 | | - }); | 277 | | - } | | 229 | + }); | 278 | 230 | } | 279 | 231 |
| 280 | 232 | /** | |
|