Write headers to the File object.  Optional argument `only` is an array of regular expressions; only headers matching one of these expressions are written.
function writeHeaders(file, headers, only = null) {
  for (let name in headers) {
    let value = headers[name];
    if (only && !match(name, only))
      continue;
    if (Array.isArray(value))
      for (let item of value)
        file.write(`${name}: ${item}\n`);
    else
      file.write(`${name}: ${value}\n`);
  }
}