(request: Http.IncomingMessage, response: Http.ServerResponse)
| 1190 | // destroys a closing socket as soon as the response is flushed, which resets the |
| 1191 | // connection while body bytes are queued and can lose the response. |
| 1192 | const teardownBody = (request: Http.IncomingMessage, response: Http.ServerResponse): void => { |
| 1193 | if (request.complete || request.destroyed) { |
| 1194 | return |
| 1195 | } |
| 1196 | const socket = request.socket |
| 1197 | if ((response as unknown as ServerResponseInternals)._last) { |
| 1198 | // Skips Node's `_dump`. Unlike `_dumped`, it keeps the parser applying backpressure. |
| 1199 | ;(request as unknown as IncomingMessageInternals)._consuming = true |
| 1200 | ;(response as unknown as ServerResponseInternals)._last = false |
| 1201 | return closeSocket(socket) |
| 1202 | } |
| 1203 | let bytes = 0 |
| 1204 | request.on("data", (chunk: Buffer) => { |
| 1205 | bytes += chunk.length |
| 1206 | if (bytes > maxDrainBytes) { |
| 1207 | // Pausing stops further `data` events, so this runs once. |
| 1208 | request.pause() |
| 1209 | closeSocket(socket) |
| 1210 | } |
| 1211 | }) |
| 1212 | request.resume() |
| 1213 | } |
| 1214 | |
| 1215 | const closeSocket = (socket: Net.Socket): void => { |
| 1216 | if (socket.destroyed) { |
no test coverage detected