function generateCorsResHeaders(rule, origin, method, headers,
isPreflight) {
    const resHeaders = {
        'access-control-max-age': rule.maxAgeSeconds,
        'access-control-allow-methods': rule.allowedMethods.join(', '),
        'vary':
        'Origin, Access-Control-Request-Headers, Access-Control-Request-Method',
    };
    // send back '*' if any origin allowed; otherwise send back
    // request Origin value
    if (rule.allowedOrigins.indexOf('*') > -1) {
        resHeaders['access-control-allow-origin'] = '*';
    } else {
        resHeaders['access-control-allow-origin'] = origin;
        // can only set allow credentials to true if not returning wildcard
        // for 'access-control-allow-origin'
        resHeaders['access-control-allow-credentials'] = true;
    }
    if (headers) {
        resHeaders['access-control-allow-headers'] = headers.join(', ');
    }
    if (rule.exposeHeaders) {
        resHeaders['access-control-expose-headers'] =
            rule.exposeHeaders.join(', ');
    }
    if (isPreflight) {
        resHeaders['content-length'] = '0';
        resHeaders.date = new Date().toUTCString();
    }
    return resHeaders;
}
_gatherResHeaders - Collect headers to return in response
@param {object} rule - array of rules
@param {string} [rule.id] - optional id to identify rule
@param {string[]} rule[].allowedMethods - methods allowed for CORS
@param {string[]} rule[].allowedOrigins - origins allowed for CORS
@param {string[]} [rule[].allowedHeaders] - headers allowed in an
  OPTIONS request via the Access-Control-Request-Headers header
@param {number} [rule[].maxAgeSeconds] - seconds browsers should cache
  OPTIONS response
@param {string[]} [rule[].exposeHeaders] - headers to expose to external
  applications
@param {string} origin - origin of CORS request
@param {string} method - Access-Control-Request-Method header value in
  an OPTIONS request and the actual method in any other request
@param {string[]} [headers] - Access-Control-Request-Headers header value
  in a preflight CORS request
@param {boolean} [isPreflight] - indicates if cors headers are being gathered
  for a CORS preflight request
@return {object} resHeaders - headers to include in response