Parse headers from headerLines.  Optional argument `only` is an array of regular expressions; only headers matching one of these expressions are parsed.  Returns a object with name/value pairs.
function parseHeaders(filename, headerLines, only = null) {
  const headers = Object.create(null);
  for (let line of headerLines) {
    if (line === '')
      continue;
    let [name, value] = line.match(/^(.*?)\:\s+(.*)$/).slice(1);
    if (only && !match(name, only))
      continue;

    const key  = (name || '').toLowerCase();
    value = (value || '').trim().replace(/^"(.*)"$/, '$1');
    if (Array.isArray(headers[key]))
      headers[key].push(value);
    else if (headers[key])
      headers[key] = [headers[key], value];
    else
      headers[key] = value;
  }
  return headers;
}