MCPcopy
hub / github.com/fastify/fastify / writeHttp2Payload

Function writeHttp2Payload

lib/reply.js:703–728  ·  view source on GitHub ↗
(payload, res, done)

Source from the content-addressed store, hash-verified

701}
702
703function 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
730function logStreamError (logger, err, res) {
731 if (err.code === 'ERR_STREAM_PREMATURE_CLOSE') {

Callers 1

writePayloadFunction · 0.85

Calls 1

writeChunkFunction · 0.85

Tested by

no test coverage detected