MCPcopy Create free account
hub / github.com/fastify/fastify / writeHttp2Payload

Function writeHttp2Payload

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

Source from the content-addressed store, hash-verified

715}
716
717function writeHttp2Payload (payload, res, done) {
718 const buffer = Buffer.isBuffer(payload) ? payload : Buffer.from(payload)
719 let offset = 0
720
721 function writeChunk () {
722 while (offset < buffer.length) {
723 /* c8 ignore next 3 - defensive guard for aborted responses */
724 if (res.destroyed || res.writableEnded) {
725 return
726 }
727
728 const end = Math.min(offset + HTTP2_WRITE_CHUNK_SIZE, buffer.length)
729 const shouldContinue = res.write(buffer.subarray(offset, end))
730 offset = end
731
732 if (shouldContinue === false) {
733 res.once('drain', writeChunk)
734 return
735 }
736 }
737
738 done()
739 }
740
741 writeChunk()
742}
743
744function logStreamError (err, reply, res) {
745 reply.server[kLogController].streamError(err, reply.request, reply)

Callers 1

writePayloadFunction · 0.85

Calls 2

writeChunkFunction · 0.85
fromMethod · 0.80

Tested by

no test coverage detected