MCPcopy Index your code
hub / github.com/nodejs/node / end

Method end

lib/internal/http2/compat.js:819–861  ·  view source on GitHub ↗
(chunk, encoding, cb)

Source from the content-addressed store, hash-verified

817 }
818
819 end(chunk, encoding, cb) {
820 const stream = this[kStream];
821 const state = this[kState];
822
823 if (typeof chunk === 'function') {
824 cb = chunk;
825 chunk = null;
826 } else if (typeof encoding === 'function') {
827 cb = encoding;
828 encoding = 'utf8';
829 }
830
831 if ((state.closed || state.ending) &&
832 state.headRequest === stream.headRequest) {
833 if (typeof cb === 'function') {
834 process.nextTick(cb);
835 }
836 return this;
837 }
838
839 if (chunk !== null && chunk !== undefined)
840 this.write(chunk, encoding);
841
842 state.headRequest = stream.headRequest;
843 state.ending = true;
844
845 if (typeof cb === 'function') {
846 if (stream.writableEnded)
847 this.once('finish', cb);
848 else
849 stream.once('finish', cb);
850 }
851
852 if (!stream.headersSent)
853 this.writeHead(this[kState].statusCode);
854
855 if (this[kState].closed || stream.destroyed)
856 onStreamCloseResponse.call(stream);
857 else
858 stream.end();
859
860 return this;
861 }
862
863 destroy(err) {
864 if (this[kState].destroyed)

Callers 10

onServerStreamFunction · 0.45
onSessionHeadersFunction · 0.45
finishSessionCloseFunction · 0.45
requestMethod · 0.45
closeStreamFunction · 0.45
processRespondWithFDFunction · 0.45
pushStreamMethod · 0.45
respondMethod · 0.45
connectionListenerFunction · 0.45
core.jsFile · 0.45

Calls 4

writeMethod · 0.95
writeHeadMethod · 0.95
onceMethod · 0.45
callMethod · 0.45

Tested by

no test coverage detected