@@ -65,6 +65,12 @@ const handleStream = common.mustCallAtLeast((stream, headers) => {
6565 stream . respond ( responseHeaders ) ;
6666 stream . end ( plainTextBody ) ;
6767 break ;
68+ case '/invalid-gzip' :
69+ // Send invalid data with gzip content-encoding to trigger decompression error
70+ responseHeaders [ http2 . constants . HTTP2_HEADER_CONTENT_ENCODING ] = 'gzip' ;
71+ stream . respond ( responseHeaders ) ;
72+ stream . end ( 'this is not valid gzip data' ) ;
73+ break ;
6874 default :
6975 assert . fail ( `Unexpected path: ${ path } ` ) ;
7076 }
@@ -102,6 +108,44 @@ function verifyLoadingFinished({ method, params }) {
102108 return params ;
103109}
104110
111+ async function testInvalidCompressedResponse ( server ) {
112+ const port = server . address ( ) . port ;
113+ const secure = server === http2SecureServer ;
114+ const origin = ( secure ? 'https' : 'http' ) + `://localhost:${ port } ` ;
115+ const path = '/invalid-gzip' ;
116+ const url = `${ origin } ${ path } ` ;
117+
118+ const responseReceivedFuture = once ( session , 'Network.responseReceived' )
119+ . then ( ( [ event ] ) => verifyResponseReceived ( event , { url } ) ) ;
120+
121+ await new Promise ( ( resolve ) => {
122+ const client = http2 . connect ( origin , {
123+ rejectUnauthorized : false ,
124+ } ) ;
125+
126+ const req = client . request ( {
127+ [ http2 . constants . HTTP2_HEADER_PATH ] : path ,
128+ [ http2 . constants . HTTP2_HEADER_METHOD ] : 'GET' ,
129+ } ) ;
130+
131+ // Consume the response to trigger the decompression error in inspector
132+ req . on ( 'data' , ( ) => { } ) ;
133+ req . on ( 'end' , ( ) => {
134+ client . close ( ) ;
135+ resolve ( ) ;
136+ } ) ;
137+ req . on ( 'error' , ( ) => {
138+ client . close ( ) ;
139+ resolve ( ) ;
140+ } ) ;
141+ req . end ( ) ;
142+ } ) ;
143+
144+ await responseReceivedFuture ;
145+ // Note: loadingFinished is not emitted when decompression fails,
146+ // but this test ensures the error handler is triggered for coverage.
147+ }
148+
105149async function testCompressedResponse ( server , encoding , path ) {
106150 const port = server . address ( ) . port ;
107151 const secure = server === http2SecureServer ;
@@ -179,89 +223,47 @@ async function testCompressedResponse(server, encoding, path) {
179223 assert . strictEqual ( responseBody . body , plainTextBody ) ;
180224}
181225
182- async function testGzipHttp2 ( ) {
183- await testCompressedResponse ( http2Server , 'gzip' , '/gzip' ) ;
184- }
185-
186- async function testGzipHttp2Secure ( ) {
187- await testCompressedResponse ( http2SecureServer , 'gzip' , '/gzip' ) ;
188- }
189-
190- async function testXGzipHttp2 ( ) {
191- await testCompressedResponse ( http2Server , 'x-gzip' , '/x-gzip' ) ;
192- }
193-
194- async function testXGzipHttp2Secure ( ) {
195- await testCompressedResponse ( http2SecureServer , 'x-gzip' , '/x-gzip' ) ;
196- }
197-
198- async function testDeflateHttp2 ( ) {
199- await testCompressedResponse ( http2Server , 'deflate' , '/deflate' ) ;
200- }
201-
202- async function testDeflateHttp2Secure ( ) {
203- await testCompressedResponse ( http2SecureServer , 'deflate' , '/deflate' ) ;
204- }
205-
206- async function testBrotliHttp2 ( ) {
207- await testCompressedResponse ( http2Server , 'br' , '/br' ) ;
208- }
209-
210- async function testBrotliHttp2Secure ( ) {
211- await testCompressedResponse ( http2SecureServer , 'br' , '/br' ) ;
212- }
213-
214- async function testZstdHttp2 ( ) {
215- await testCompressedResponse ( http2Server , 'zstd' , '/zstd' ) ;
216- }
217-
218- async function testZstdHttp2Secure ( ) {
219- await testCompressedResponse ( http2SecureServer , 'zstd' , '/zstd' ) ;
220- }
221-
222- async function testPlainHttp2 ( ) {
223- await testCompressedResponse ( http2Server , null , '/plain' ) ;
224- }
225-
226- async function testPlainHttp2Secure ( ) {
227- await testCompressedResponse ( http2SecureServer , null , '/plain' ) ;
228- }
229-
230226const testNetworkInspection = async ( ) => {
231227 // Test gzip
232- await testGzipHttp2 ( ) ;
228+ await testCompressedResponse ( http2Server , 'gzip' , '/gzip' ) ;
233229 session . removeAllListeners ( ) ;
234- await testGzipHttp2Secure ( ) ;
230+ await testCompressedResponse ( http2SecureServer , 'gzip' , '/gzip' ) ;
235231 session . removeAllListeners ( ) ;
236232
237233 // Test x-gzip (alternate gzip encoding)
238- await testXGzipHttp2 ( ) ;
234+ await testCompressedResponse ( http2Server , 'x-gzip' , '/x-gzip' ) ;
239235 session . removeAllListeners ( ) ;
240- await testXGzipHttp2Secure ( ) ;
236+ await testCompressedResponse ( http2SecureServer , 'x-gzip' , '/x-gzip' ) ;
241237 session . removeAllListeners ( ) ;
242238
243239 // Test deflate
244- await testDeflateHttp2 ( ) ;
240+ await testCompressedResponse ( http2Server , 'deflate' , '/deflate' ) ;
245241 session . removeAllListeners ( ) ;
246- await testDeflateHttp2Secure ( ) ;
242+ await testCompressedResponse ( http2SecureServer , 'deflate' , '/deflate' ) ;
247243 session . removeAllListeners ( ) ;
248244
249245 // Test brotli
250- await testBrotliHttp2 ( ) ;
246+ await testCompressedResponse ( http2Server , 'br' , '/br' ) ;
251247 session . removeAllListeners ( ) ;
252- await testBrotliHttp2Secure ( ) ;
248+ await testCompressedResponse ( http2SecureServer , 'br' , '/br' ) ;
253249 session . removeAllListeners ( ) ;
254250
255251 // Test zstd
256- await testZstdHttp2 ( ) ;
252+ await testCompressedResponse ( http2Server , 'zstd' , '/zstd' ) ;
257253 session . removeAllListeners ( ) ;
258- await testZstdHttp2Secure ( ) ;
254+ await testCompressedResponse ( http2SecureServer , 'zstd' , '/zstd' ) ;
259255 session . removeAllListeners ( ) ;
260256
261257 // Test plain (no compression)
262- await testPlainHttp2 ( ) ;
258+ await testCompressedResponse ( http2Server , null , '/plain' ) ;
259+ session . removeAllListeners ( ) ;
260+ await testCompressedResponse ( http2SecureServer , null , '/plain' ) ;
261+ session . removeAllListeners ( ) ;
262+
263+ // Test invalid compressed data (triggers decompression error handler)
264+ await testInvalidCompressedResponse ( http2Server ) ;
263265 session . removeAllListeners ( ) ;
264- await testPlainHttp2Secure ( ) ;
266+ await testInvalidCompressedResponse ( http2SecureServer ) ;
265267 session . removeAllListeners ( ) ;
266268} ;
267269
0 commit comments