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

Function processHeader

lib/internal/http2/util.js:777–829  ·  view source on GitHub ↗
(key, value)

Source from the content-addressed store, hash-verified

775 const neverIndex = sensitiveHeaders.map((v) => v.toLowerCase());
776
777 function processHeader(key, value) {
778 key = key.toLowerCase();
779 const isStrictSingleValueField = strictSingleValueFields &&
780 kSingleValueFields.has(key);
781 let isArray = ArrayIsArray(value);
782 if (isArray) {
783 switch (value.length) {
784 case 0:
785 return;
786 case 1:
787 value = String(value[0]);
788 isArray = false;
789 break;
790 default:
791 if (isStrictSingleValueField)
792 throw new ERR_HTTP2_HEADER_SINGLE_VALUE(key);
793 }
794 } else {
795 value = String(value);
796 }
797 if (isStrictSingleValueField) {
798 if (singles.has(key))
799 throw new ERR_HTTP2_HEADER_SINGLE_VALUE(key);
800 singles.add(key);
801 }
802 const flags = neverIndex.includes(key) ?
803 kNeverIndexFlag :
804 kNoHeaderFlags;
805 if (key[0] === ':') {
806 const err = validatePseudoHeaderValue(key);
807 if (err !== undefined)
808 throw err;
809 pseudoHeaders += `${key}\0${value}\0${flags}`;
810 count++;
811 return;
812 }
813 if (!checkIsHttpToken(key)) {
814 throw new ERR_INVALID_HTTP_TOKEN('Header name', key);
815 }
816 if (isIllegalConnectionSpecificHeader(key, value)) {
817 throw new ERR_HTTP2_INVALID_CONNECTION_HEADERS(key);
818 }
819 if (isArray) {
820 for (let j = 0; j < value.length; ++j) {
821 const val = String(value[j]);
822 headers += `${key}\0${val}\0${flags}`;
823 }
824 count += value.length;
825 return;
826 }
827 headers += `${key}\0${value}\0${flags}`;
828 count++;
829 }
830
831 if (ArrayIsArray(arrayOrMap)) {
832 for (let i = 0; i < arrayOrMap.length; i += 2) {

Callers 1

buildNgHeaderStringFunction · 0.70

Calls 6

StringClass · 0.85
checkIsHttpTokenFunction · 0.85
includesMethod · 0.80
hasMethod · 0.65
addMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…