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

Function writeHeaders

test/parallel/test-http-max-http-headers.js:45–77  ·  view source on GitHub ↗
(socket, headers)

Source from the content-addressed store, hash-verified

43}
44
45function writeHeaders(socket, headers) {
46 const array = [];
47 const chunkSize = 100;
48 let last = 0;
49
50 for (let i = 0; i < headers.length / chunkSize; i++) {
51 const current = (i + 1) * chunkSize;
52 array.push(headers.slice(last, current));
53 last = current;
54 }
55
56 // Safety check we are chunking correctly
57 assert.strictEqual(array.join(''), headers);
58
59 next();
60
61 function next() {
62 if (socket.destroyed) {
63 console.log('socket was destroyed early, data left to write:',
64 array.join('').length);
65 return;
66 }
67
68 const chunk = array.shift();
69
70 if (chunk) {
71 console.log('writing chunk of size', chunk.length);
72 socket.write(chunk, next);
73 } else {
74 socket.end();
75 }
76 }
77}
78
79function test1() {
80 console.log('test1');

Callers 2

test1Function · 0.85

Calls 4

nextFunction · 0.70
sliceMethod · 0.65
pushMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected