async function fetch(uri, options = {}, secure = true) {
  const {user, pass, userAgent, request: requestOptions = {}} = options;
  const {headers = {}, method = 'get', https} = requestOptions;
  let resourceUrl = uri;
  let protocolRelative = false;

  // Consider protocol-relative urls
  if (/^\/\//.test(uri)) {
    protocolRelative = true;
    resourceUrl = urlResolve(`http${secure ? 's' : ''}://te.st`, uri);
  }

  requestOptions.https = {rejectUnauthorized: true, ...https};
  if (user && pass) {
    headers.Authorization = `Basic ${token(user, pass)}`;
  }

  if (userAgent) {
    headers['User-Agent'] = userAgent;
  }

  debug(`Fetching resource: ${resourceUrl}`, {...requestOptions, headers});

  try {
    const response = await got(resourceUrl, {...requestOptions, headers});
    if (method === 'head') {
      return response;
    }

    return Buffer.from(response.body || '');
  } catch (error) {
    // Try again with http
    if (secure && protocolRelative) {
      debug(`${error.message} - trying again over http`);
      return fetch(uri, options, false);
    }

    debug(`${resourceUrl} failed: ${error.message}`);

    if (method === 'head') {
      return error.response;
    }

    if (error.response) {
      return Buffer.from(error.response.body || '');
    }

    throw error;
  }
}
Get external resource. Try https and falls back to http
@param {string} uri Source uri
@param {object} options Options passed to critical
@param {boolean} secure Use https?
@returns {Promise<Buffer|response>} Resolves to fetched content or response object for HEAD request