(payload, res, done)
| 701 | } |
| 702 | |
| 703 | function writeHttp2Payload (payload, res, done) { |
| 704 | const buffer = Buffer.isBuffer(payload) ? payload : Buffer.from(payload) |
| 705 | let offset = 0 |
| 706 | |
| 707 | function writeChunk () { |
| 708 | while (offset < buffer.length) { |
| 709 | /* c8 ignore next 3 - defensive guard for aborted responses */ |
| 710 | if (res.destroyed || res.writableEnded) { |
| 711 | return |
| 712 | } |
| 713 | |
| 714 | const end = Math.min(offset + HTTP2_WRITE_CHUNK_SIZE, buffer.length) |
| 715 | const shouldContinue = res.write(buffer.subarray(offset, end)) |
| 716 | offset = end |
| 717 | |
| 718 | if (shouldContinue === false) { |
| 719 | res.once('drain', writeChunk) |
| 720 | return |
| 721 | } |
| 722 | } |
| 723 | |
| 724 | done() |
| 725 | } |
| 726 | |
| 727 | writeChunk() |
| 728 | } |
| 729 | |
| 730 | function logStreamError (logger, err, res) { |
| 731 | if (err.code === 'ERR_STREAM_PREMATURE_CLOSE') { |
no test coverage detected