langchain.js
    Preparing search index...

    Function normalizeHeaders

    • Normalizes various header formats into a consistent Record format.

      This function accepts headers in multiple formats and converts them to a Record<string, HeaderValue | readonly HeaderValue[]> for consistent handling.

      Parameters

      • headers: HeadersLike

        The headers to normalize. Can be:

        • A Headers instance
        • An array of [key, value] pairs
        • A plain object with string keys
        • A NullableHeaders-like object with a 'values' property containing Headers
        • null or undefined

      Returns Record<string, HeaderValue | readonly HeaderValue[]>

      A normalized Record containing the header key-value pairs

      // With Headers instance
      const headers1 = new Headers([['content-type', 'application/json']]);
      const normalized1 = normalizeHeaders(headers1);

      // With plain object
      const headers2 = { 'content-type': 'application/json' };
      const normalized2 = normalizeHeaders(headers2);

      // With array of pairs
      const headers3 = [['content-type', 'application/json']];
      const normalized3 = normalizeHeaders(headers3);