lib/resolver.js
function requestAsync(resource, opts = {}) {
  const settings = {
    followRedirect: true,
    encoding: null,
    rejectUnauthorized: false
  };

  if (opts.user && opts.pass) {
    settings.headers = {Authorization: 'Basic ' + token(opts.user, opts.pass)};
  }

  return new Bluebird((resolve, reject) => {
    // Handle protocol-relative urls
    resource = url.resolve('http://te.st', resource);
    request(resource, settings, (err, resp, body) => {
      let msg;
      if (err) {
        debug('Url failed:', err.message || err);
        return reject(err);
      }
      if (resp.statusCode !== 200) {
        msg = 'Wrong status code ' + resp.statusCode + ' for ' + resource;
        debug(msg);
        return reject(new Error(msg));
      }

      const mimeType =
        result(resp, 'headers.content-type') || mime.getType(resource);

      resolve({
        contents: body,
        path: resource,
        mime: mimeType
      });
    });
  });
}
function requestAsync(resource, opts = {}) {
  const settings = {
    followRedirect: true,
    encoding: null,
    rejectUnauthorized: false
  };

  if (opts.user && opts.pass) {
    settings.headers = {Authorization: 'Basic ' + token(opts.user, opts.pass)};
  }

  return new Bluebird((resolve, reject) => {
    // Handle protocol-relative urls
    resource = url.resolve('http://te.st', resource);
    request(resource, settings, (err, resp, body) => {
      let msg;
      if (err) {
        debug('Url failed:', err.message || err);
        return reject(err);
      }
      if (resp.statusCode !== 200) {
        msg = 'Wrong status code ' + resp.statusCode + ' for ' + resource;
        debug(msg);
        return reject(new Error(msg));
      }

      const mimeType =
        result(resp, 'headers.content-type') || mime.getType(resource);

      resolve({
        contents: body,
        path: resource,
        mime: mimeType
      });
    });
  });
}
function requestAsync ( resource , opts = { } ) { const settings = { followRedirect : true , encoding : null , rejectUnauthorized : false } ; if ( opts . user && opts . pass ) { settings . headers = { Authorization : 'Basic ' + token ( opts . user , opts . pass ) } ; } return new Bluebird ( ( resolve , reject ) => { // Handle protocol-relative urls resource = url . resolve ( 'http://te.st' , resource ) ; request ( resource , settings , ( err , resp , body ) => { let msg ; if ( err ) { debug ( 'Url failed:' , err . message || err ) ; return reject ( err ) ; } if ( resp . statusCode !== 200 ) { msg = 'Wrong status code ' + resp . statusCode + ' for ' + resource ; debug ( msg ) ; return reject ( new Error ( msg ) ) ; } const mimeType = result ( resp , 'headers.content-type' ) || mime . getType ( resource ) ; resolve ( { contents : body , path : resource , mime : mimeType } ) ; } ) ; } ) ; }
Get external resource
@param {string} resource Ressource to be fetched
@param {object} opts Option hash
@returns {Promise} Promise
Get external resource