@@ -130,6 +130,27 @@ function verifyLoadingFailed({ method, params }) { |
130 | 130 | assert.strictEqual(typeof params.errorText, 'string'); |
131 | 131 | } |
132 | 132 |
|
| 133 | +function verifyHttpResponse(response) { |
| 134 | + assert.strictEqual(response.statusCode, 200); |
| 135 | + const chunks = []; |
| 136 | + |
| 137 | + // Verifies that the inspector does not put the response into flowing mode. |
| 138 | + assert.strictEqual(response.readableFlowing, null); |
| 139 | + // Verifies that the data listener may be added at a later time, and it can |
| 140 | + // still observe the data in full. |
| 141 | + queueMicrotask(() => { |
| 142 | + response.on('data', (chunk) => { |
| 143 | + chunks.push(chunk); |
| 144 | + }); |
| 145 | + assert.strictEqual(response.readableFlowing, true); |
| 146 | + }); |
| 147 | + |
| 148 | + response.on('end', common.mustCall(() => { |
| 149 | + const body = Buffer.concat(chunks).toString(); |
| 150 | + assert.strictEqual(body, '\nhello world\n'); |
| 151 | + })); |
| 152 | +} |
| 153 | + |
133 | 154 | async function testHttpGet() { |
134 | 155 | const url = `http://127.0.0.1:${httpServer.address().port}/hello-world`; |
135 | 156 | const requestWillBeSentFuture = once(session, 'Network.requestWillBeSent') |
@@ -146,18 +167,20 @@ async function testHttpGet() { |
146 | 167 | port: httpServer.address().port, |
147 | 168 | path: '/hello-world', |
148 | 169 | headers: requestHeaders |
149 | | - }, common.mustCall((res) => { |
150 | | - // Dump the response. |
151 | | - res.on('data', () => {}); |
152 | | - res.on('end', () => {}); |
153 | | - })); |
| 170 | + }, common.mustCall(verifyHttpResponse)); |
154 | 171 |
|
155 | 172 | await requestWillBeSentFuture; |
156 | 173 | const responseReceived = await responseReceivedFuture; |
157 | 174 | const loadingFinished = await loadingFinishedFuture; |
158 | 175 |
|
159 | 176 | const delta = (loadingFinished.timestamp - responseReceived.timestamp) * 1000; |
160 | 177 | assert.ok(delta > kDelta); |
| 178 | + |
| 179 | + const responseBody = await session.post('Network.getResponseBody', { |
| 180 | + requestId: responseReceived.requestId, |
| 181 | + }); |
| 182 | + assert.strictEqual(responseBody.base64Encoded, false); |
| 183 | + assert.strictEqual(responseBody.body, '\nhello world\n'); |
161 | 184 | } |
162 | 185 |
|
163 | 186 | async function testHttpsGet() { |
@@ -177,18 +200,20 @@ async function testHttpsGet() { |
177 | 200 | path: '/hello-world', |
178 | 201 | rejectUnauthorized: false, |
179 | 202 | headers: requestHeaders, |
180 | | - }, common.mustCall((res) => { |
181 | | - // Dump the response. |
182 | | - res.on('data', () => {}); |
183 | | - res.on('end', () => {}); |
184 | | - })); |
| 203 | + }, common.mustCall(verifyHttpResponse)); |
185 | 204 |
|
186 | 205 | await requestWillBeSentFuture; |
187 | 206 | const responseReceived = await responseReceivedFuture; |
188 | 207 | const loadingFinished = await loadingFinishedFuture; |
189 | 208 |
|
190 | 209 | const delta = (loadingFinished.timestamp - responseReceived.timestamp) * 1000; |
191 | 210 | assert.ok(delta > kDelta); |
| 211 | + |
| 212 | + const responseBody = await session.post('Network.getResponseBody', { |
| 213 | + requestId: responseReceived.requestId, |
| 214 | + }); |
| 215 | + assert.strictEqual(responseBody.base64Encoded, false); |
| 216 | + assert.strictEqual(responseBody.body, '\nhello world\n'); |
192 | 217 | } |
193 | 218 |
|
194 | 219 | async function testHttpError() { |
|