CoolFace
Datasetpublic

basant307/AI_Governance_Project

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
0likes48downloads
parseHeaders.js70 linesDownload Raw Back to helpers
1'use strict';2 3import utils from '../utils.js';4 5// RawAxiosHeaders whose duplicates are ignored by node6// c.f. https://nodejs.org/api/http.html#http_message_headers7const ignoreDuplicateOf = utils.toObjectSet([8  'age',9  'authorization',10  'content-length',11  'content-type',12  'etag',13  'expires',14  'from',15  'host',16  'if-modified-since',17  'if-unmodified-since',18  'last-modified',19  'location',20  'max-forwards',21  'proxy-authorization',22  'referer',23  'retry-after',24  'user-agent',25]);26 27/**28 * Parse headers into an object29 *30 * ```31 * Date: Wed, 27 Aug 2014 08:58:49 GMT32 * Content-Type: application/json33 * Connection: keep-alive34 * Transfer-Encoding: chunked35 * ```36 *37 * @param {String} rawHeaders Headers needing to be parsed38 *39 * @returns {Object} Headers parsed into an object40 */41export default (rawHeaders) => {42  const parsed = {};43  let key;44  let val;45  let i;46 47  rawHeaders &&48    rawHeaders.split('\n').forEach(function parser(line) {49      i = line.indexOf(':');50      key = line.substring(0, i).trim().toLowerCase();51      val = line.substring(i + 1).trim();52 53      if (!key || (parsed[key] && ignoreDuplicateOf[key])) {54        return;55      }56 57      if (key === 'set-cookie') {58        if (parsed[key]) {59          parsed[key].push(val);60        } else {61          parsed[key] = [val];62        }63      } else {64        parsed[key] = parsed[key] ? parsed[key] + ', ' + val : val;65      }66    });67 68  return parsed;69};70 
basant307/AI_Governance_Project · CoolFace