Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
inspector: remove irrelevant code
  • Loading branch information
rubnogueira committed Dec 31, 2025
commit 520e278f40b061030e1f8e46ca9b0a0b4f13e188
45 changes: 0 additions & 45 deletions lib/internal/inspector/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const {
createBrotliDecompress,
createZstdDecompress,
} = require('zlib');
const { Buffer } = require('buffer');

const kInspectorRequestId = Symbol('kInspectorRequestId');
const kContentEncoding = Symbol('kContentEncoding');
Expand Down Expand Up @@ -78,19 +77,6 @@ function sniffMimeType(contentType) {
};
}

/**
* Gets the content encoding from the headers object.
* @param {object} headers - The response headers.
* @returns {string|undefined} - The content encoding (e.g., 'gzip', 'deflate', 'br', 'zstd').
*/
function getContentEncoding(headers = {}) {
const contentEncoding = headers['content-encoding'];
if (typeof contentEncoding === 'string') {
return StringPrototypeToLowerCase(contentEncoding);
}
return undefined;
}

/**
* Creates a decompression stream based on the content encoding.
* @param {string} encoding - The content encoding (e.g., 'gzip', 'deflate', 'br', 'zstd').
Expand All @@ -112,35 +98,6 @@ function createDecompressor(encoding) {
}
}

/**
* Decompresses a chunk of data based on the content encoding.
* @param {Buffer} chunk - The compressed data chunk.
* @param {string} encoding - The content encoding.
* @param {Function} callback - Callback with (error, decompressedChunk).
*/
function decompressChunk(chunk, encoding, callback) {
const decompressor = createDecompressor(encoding);
if (!decompressor) {
// No decompression needed, return original chunk
callback(null, chunk);
return;
}

const chunks = [];
decompressor.on('data', (decompressedChunk) => {
chunks.push(decompressedChunk);
});
decompressor.on('end', () => {
callback(null, Buffer.concat(chunks));
});
decompressor.on('error', (err) => {
// On decompression error, fall back to returning the original chunk
callback(null, chunk);
});

decompressor.end(chunk);
}

function registerDiagnosticChannels(listenerPairs) {
function enable() {
ArrayPrototypeForEach(listenerPairs, ({ 0: channel, 1: listener }) => {
Expand Down Expand Up @@ -168,7 +125,5 @@ module.exports = {
getNextRequestId,
registerDiagnosticChannels,
sniffMimeType,
getContentEncoding,
createDecompressor,
decompressChunk,
};
23 changes: 22 additions & 1 deletion test/parallel/test-inspector-network-http-compressed.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ const handleRequest = (req, res) => {
res.end(compressed);
}));
break;
case '/x-gzip':
setResponseHeaders(res, 'x-gzip');
res.writeHead(200);
zlib.gzip(plainTextBody, common.mustSucceed((compressed) => {
res.end(compressed);
}));
break;
case '/deflate':
setResponseHeaders(res, 'deflate');
res.writeHead(200);
Expand Down Expand Up @@ -119,7 +126,7 @@ async function testCompressedResponse(server, encoding, path) {
}, (res) => {
// Manually decompress the response to verify it works for user code
let decompressor;
if (encoding === 'gzip') {
if (encoding === 'gzip' || encoding === 'x-gzip') {
decompressor = zlib.createGunzip();
} else if (encoding === 'deflate') {
decompressor = zlib.createInflate();
Expand Down Expand Up @@ -165,6 +172,14 @@ async function testGzipHttps() {
await testCompressedResponse(httpsServer, 'gzip', '/gzip');
}

async function testXGzipHttp() {
await testCompressedResponse(httpServer, 'x-gzip', '/x-gzip');
}

async function testXGzipHttps() {
await testCompressedResponse(httpsServer, 'x-gzip', '/x-gzip');
}

async function testDeflateHttp() {
await testCompressedResponse(httpServer, 'deflate', '/deflate');
}
Expand Down Expand Up @@ -204,6 +219,12 @@ const testNetworkInspection = async () => {
await testGzipHttps();
session.removeAllListeners();

// Test x-gzip (alternate gzip encoding)
await testXGzipHttp();
session.removeAllListeners();
await testXGzipHttps();
session.removeAllListeners();

// Test deflate
await testDeflateHttp();
session.removeAllListeners();
Expand Down
23 changes: 22 additions & 1 deletion test/parallel/test-inspector-network-http2-compressed.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ const handleStream = common.mustCallAtLeast((stream, headers) => {
stream.end(compressed);
}));
break;
case '/x-gzip':
responseHeaders[http2.constants.HTTP2_HEADER_CONTENT_ENCODING] = 'x-gzip';
stream.respond(responseHeaders);
zlib.gzip(plainTextBody, common.mustSucceed((compressed) => {
stream.end(compressed);
}));
break;
case '/deflate':
responseHeaders[http2.constants.HTTP2_HEADER_CONTENT_ENCODING] = 'deflate';
stream.respond(responseHeaders);
Expand Down Expand Up @@ -121,7 +128,7 @@ async function testCompressedResponse(server, encoding, path) {

// Manually decompress the response to verify it works for user code
let decompressor;
if (encoding === 'gzip') {
if (encoding === 'gzip' || encoding === 'x-gzip') {
decompressor = zlib.createGunzip();
} else if (encoding === 'deflate') {
decompressor = zlib.createInflate();
Expand Down Expand Up @@ -180,6 +187,14 @@ async function testGzipHttp2Secure() {
await testCompressedResponse(http2SecureServer, 'gzip', '/gzip');
}

async function testXGzipHttp2() {
await testCompressedResponse(http2Server, 'x-gzip', '/x-gzip');
}

async function testXGzipHttp2Secure() {
await testCompressedResponse(http2SecureServer, 'x-gzip', '/x-gzip');
}

async function testDeflateHttp2() {
await testCompressedResponse(http2Server, 'deflate', '/deflate');
}
Expand Down Expand Up @@ -219,6 +234,12 @@ const testNetworkInspection = async () => {
await testGzipHttp2Secure();
session.removeAllListeners();

// Test x-gzip (alternate gzip encoding)
await testXGzipHttp2();
session.removeAllListeners();
await testXGzipHttp2Secure();
session.removeAllListeners();

// Test deflate
await testDeflateHttp2();
session.removeAllListeners();
Expand Down