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

Function _storeHeader

lib/_http_outgoing.js:430–565  ·  view source on GitHub ↗
(firstLine, headers)

Source from the content-addressed store, hash-verified

428
429OutgoingMessage.prototype._storeHeader = _storeHeader;
430function _storeHeader(firstLine, headers) {
431 // firstLine in the case of request is: 'GET /index.html HTTP/1.1\r\n'
432 // in the case of response it is: 'HTTP/1.1 200 OK\r\n'
433 const state = {
434 connection: false,
435 contLen: false,
436 te: false,
437 date: false,
438 expect: false,
439 trailer: false,
440 header: firstLine,
441 };
442 const lenient = this._isLenientHeaderValidation();
443
444 if (headers) {
445 if (headers === this[kOutHeaders]) {
446 for (const key in headers) {
447 const entry = headers[key];
448 processHeader(this, state, entry[0], entry[1], false, lenient);
449 }
450 } else if (ArrayIsArray(headers)) {
451 if (headers.length && ArrayIsArray(headers[0])) {
452 for (let i = 0; i < headers.length; i++) {
453 const entry = headers[i];
454 processHeader(this, state, entry[0], entry[1], true, lenient);
455 }
456 } else {
457 if (headers.length % 2 !== 0) {
458 throw new ERR_INVALID_ARG_VALUE('headers', headers);
459 }
460
461 for (let n = 0; n < headers.length; n += 2) {
462 processHeader(this, state, headers[n + 0], headers[n + 1], true, lenient);
463 }
464 }
465 } else {
466 for (const key in headers) {
467 if (ObjectHasOwn(headers, key)) {
468 processHeader(this, state, key, headers[key], true, lenient);
469 }
470 }
471 }
472 }
473
474 let { header } = state;
475
476 // Date header
477 if (this.sendDate && !state.date) {
478 header += 'Date: ' + utcDate() + '\r\n';
479 }
480
481 // Force the connection to close when the response is a 204 No Content or
482 // a 304 Not Modified and the user has set a "Transfer-Encoding: chunked"
483 // header.
484 //
485 // RFC 2616 mandates that 204 and 304 responses MUST NOT have a body but
486 // node.js used to send out a zero chunk anyway to accommodate clients
487 // that don't have special handling for those responses.

Callers

nothing calls this directly

Calls 4

utcDateFunction · 0.85
_sendMethod · 0.80
processHeaderFunction · 0.70
debugFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…