Skip to content

Commit a27052f

Browse files
authored
Revert "inspector: fix compressed responses"
This reverts commit 186c7a9. PR-URL: #61502Fixes: #61501 Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 5e104c8 commit a27052f

5 files changed

Lines changed: 35 additions & 703 deletions

File tree

‎lib/internal/inspector/network.js‎

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,8 @@ const {
1010
constdc=require('diagnostics_channel');
1111
const{ now }=require('internal/perf/utils');
1212
const{ MIMEType }=require('internal/mime');
13-
const{
14-
createGunzip,
15-
createInflate,
16-
createBrotliDecompress,
17-
createZstdDecompress,
18-
}=require('zlib');
1913

2014
constkInspectorRequestId=Symbol('kInspectorRequestId');
21-
constkContentEncoding=Symbol('kContentEncoding');
2215

2316
// https://chromedevtools.github.io/devtools-protocol/1-3/Network/#type-ResourceType
2417
constkResourceType={
@@ -77,27 +70,6 @@ function sniffMimeType(contentType) {
7770
};
7871
}
7972

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-
functioncreateDecompressor(encoding){
86-
switch(encoding){
87-
case'gzip':
88-
case'x-gzip':
89-
returncreateGunzip();
90-
case'deflate':
91-
returncreateInflate();
92-
case'br':
93-
returncreateBrotliDecompress();
94-
case'zstd':
95-
returncreateZstdDecompress();
96-
default:
97-
returnnull;
98-
}
99-
}
100-
10173
functionregisterDiagnosticChannels(listenerPairs){
10274
functionenable(){
10375
ArrayPrototypeForEach(listenerPairs,({0: channel,1: listener})=>{
@@ -119,11 +91,9 @@ function registerDiagnosticChannels(listenerPairs) {
11991

12092
module.exports={
12193
kInspectorRequestId,
122-
kContentEncoding,
12394
kResourceType,
12495
getMonotonicTime,
12596
getNextRequestId,
12697
registerDiagnosticChannels,
12798
sniffMimeType,
128-
createDecompressor,
12999
};

‎lib/internal/inspector/network_http.js‎

Lines changed: 17 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,11 @@ const {
1010

1111
const{
1212
kInspectorRequestId,
13-
kContentEncoding,
1413
kResourceType,
1514
getMonotonicTime,
1615
getNextRequestId,
1716
registerDiagnosticChannels,
1817
sniffMimeType,
19-
createDecompressor,
2018
}=require('internal/inspector/network');
2119
const{ Network }=require('inspector');
2220
constEventEmitter=require('events');
@@ -29,7 +27,6 @@ const convertHeaderObject = (headers = {}) => {
2927
lethost;
3028
letcharset;
3129
letmimeType;
32-
letcontentEncoding;
3330
constdict={};
3431
for(const{0: key,1: value}ofObjectEntries(headers)){
3532
constlowerCasedKey=key.toLowerCase();
@@ -41,9 +38,6 @@ const convertHeaderObject = (headers = {}) => {
4138
charset=result.charset;
4239
mimeType=result.mimeType;
4340
}
44-
if(lowerCasedKey==='content-encoding'){
45-
contentEncoding=typeofvalue==='string' ? value.toLowerCase() : undefined;
46-
}
4741
if(typeofvalue==='string'){
4842
dict[key]=value;
4943
}elseif(ArrayIsArray(value)){
@@ -56,7 +50,7 @@ const convertHeaderObject = (headers = {}) => {
5650
dict[key]=String(value);
5751
}
5852
}
59-
return[dict,host,charset,mimeType,contentEncoding];
53+
return[dict,host,charset,mimeType];
6054
};
6155

6256
/**
@@ -111,10 +105,7 @@ function onClientResponseFinish({ request, response }) {
111105
return;
112106
}
113107

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);
118109

119110
Network.responseReceived({
120111
requestId: request[kInspectorRequestId],
@@ -130,64 +121,24 @@ function onClientResponseFinish({ request, response }) {
130121
},
131122
});
132123

133-
// Create a decompressor if the response is compressed
134-
constdecompressor=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,
181132
});
133+
});
182134

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(),
189140
});
190-
}
141+
});
191142
}
192143

193144
module.exports=registerDiagnosticChannels([

‎lib/internal/inspector/network_http2.js‎

Lines changed: 18 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,15 @@ const {
1010

1111
const{
1212
kInspectorRequestId,
13-
kContentEncoding,
1413
kResourceType,
1514
getMonotonicTime,
1615
getNextRequestId,
1716
registerDiagnosticChannels,
1817
sniffMimeType,
19-
createDecompressor,
2018
}=require('internal/inspector/network');
2119
const{ Network }=require('inspector');
2220
const{
2321
HTTP2_HEADER_AUTHORITY,
24-
HTTP2_HEADER_CONTENT_ENCODING,
2522
HTTP2_HEADER_CONTENT_TYPE,
2623
HTTP2_HEADER_COOKIE,
2724
HTTP2_HEADER_METHOD,
@@ -45,7 +42,6 @@ function convertHeaderObject(headers = {}) {
4542
letstatusCode;
4643
letcharset;
4744
letmimeType;
48-
letcontentEncoding;
4945
constdict={};
5046

5147
for(const{0: key,1: value}ofObjectEntries(headers)){
@@ -65,8 +61,6 @@ function convertHeaderObject(headers = {}) {
6561
constresult=sniffMimeType(value);
6662
charset=result.charset;
6763
mimeType=result.mimeType;
68-
}elseif(lowerCasedKey===HTTP2_HEADER_CONTENT_ENCODING){
69-
contentEncoding=typeofvalue==='string' ? value.toLowerCase() : undefined;
7064
}
7165

7266
if(typeofvalue==='string'){
@@ -84,7 +78,7 @@ function convertHeaderObject(headers = {}) {
8478

8579
consturl=`${scheme}://${authority}${path}`;
8680

87-
return[dict,url,method,statusCode,charset,mimeType,contentEncoding];
81+
return[dict,url,method,statusCode,charset,mimeType];
8882
}
8983

9084
/**
@@ -200,16 +194,7 @@ function onClientStreamFinish({ stream, headers }) {
200194
return;
201195
}
202196

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);
213198

214199
Network.responseReceived({
215200
requestId: stream[kInspectorRequestId],
@@ -225,56 +210,23 @@ function onClientStreamFinish({ stream, headers }) {
225210
},
226211
});
227212

228-
// Create a decompressor if the response is compressed
229-
constdecompressor=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,
246228
});
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+
});
278230
}
279231

280232
/**

0 commit comments

Comments
 (0)