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

Function prepareRequestHeadersArray

lib/internal/http2/util.js:621–704  ·  view source on GitHub ↗

* Takes a request headers array, validates it and sets defaults, and returns * the resulting headers in NgHeaders string list format. * @returns {object}

(headers, session)

Source from the content-addressed store, hash-verified

619 * @returns {object}
620 */
621function prepareRequestHeadersArray(headers, session) {
622 let method;
623 let scheme;
624 let authority;
625 let path;
626 let protocol;
627
628 // Extract the key pseudo header values from the headers array.
629 for (let i = 0; i < headers.length; i += 2) {
630 if (headers[i][0] !== ':') {
631 continue;
632 }
633
634 const header = headers[i].toLowerCase();
635 const value = headers[i + 1];
636
637 if (header === HTTP2_HEADER_METHOD) {
638 method = value;
639 } else if (header === HTTP2_HEADER_SCHEME) {
640 scheme = value;
641 } else if (header === HTTP2_HEADER_AUTHORITY) {
642 authority = value;
643 } else if (header === HTTP2_HEADER_PATH) {
644 path = value;
645 } else if (header === HTTP2_HEADER_PROTOCOL) {
646 protocol = value;
647 }
648 }
649
650 // We then build an array of any missing pseudo headers, to prepend
651 // default values to the given header array:
652 const additionalPseudoHeaders = [];
653
654 if (method === undefined) {
655 method = HTTP2_METHOD_GET;
656 additionalPseudoHeaders.push(HTTP2_HEADER_METHOD, method);
657 }
658
659 const connect = method === HTTP2_METHOD_CONNECT;
660
661 if (!connect || protocol !== undefined) {
662 if (authority === undefined && headers[HTTP2_HEADER_HOST] === undefined) {
663 authority = session[kAuthority];
664 additionalPseudoHeaders.push(HTTP2_HEADER_AUTHORITY, authority);
665 }
666 if (scheme === undefined) {
667 scheme = session[kProtocol].slice(0, -1);
668 additionalPseudoHeaders.push(HTTP2_HEADER_SCHEME, scheme);
669 }
670 if (path === undefined) {
671 additionalPseudoHeaders.push(HTTP2_HEADER_PATH, '/');
672 }
673 } else {
674 if (authority === undefined)
675 throw new ERR_HTTP2_CONNECT_AUTHORITY();
676 if (scheme !== undefined)
677 throw new ERR_HTTP2_CONNECT_SCHEME();
678 if (path !== undefined)

Callers 1

requestMethod · 0.85

Calls 4

buildNgHeaderStringFunction · 0.85
concatMethod · 0.80
sliceMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…