index.js
function performRequest (options, isFirstRequest) {
  // This should be the default export of either request or request-promise.
  const requester = options.requester;

  // Note that request is always an instanceof ReadableStream, EventEmitter
  // If the requester is request-promise, it is also thenable.
  const request = requester(options);

  // We must define the host header ourselves to preserve case and order.
  if (request.getHeader('host') === HOST) {
    request.setHeader('host', request.uri.host);
  }

  // If the requester is not request-promise, ensure we get a callback.
  if (typeof request.callback !== 'function') {
    throw new TypeError('Expected a callback function, got ' +
        typeof (request.callback) + ' instead.');
  }

  // We only need the callback from the first request.
  // The other callbacks can be safely ignored.
  if (isFirstRequest) {
    // This should be a user supplied callback or request-promise's callback.
    // The callback is always wrapped/bound to the request instance.
    options.callback = request.callback;
  }

  request.removeAllListeners('error')
    .once('error', function (error) {
      onRequestResponse(options, error);
    });

  request.removeAllListeners('complete')
    .once('complete', function (response, body) {
      onRequestResponse(options, null, response, body);
    });

  // Indicate that this is a cloudscraper request
  request.cloudscraper = true;
  return request;
}
function performRequest (options, isFirstRequest) {
  // This should be the default export of either request or request-promise.
  const requester = options.requester;

  // Note that request is always an instanceof ReadableStream, EventEmitter
  // If the requester is request-promise, it is also thenable.
  const request = requester(options);

  // We must define the host header ourselves to preserve case and order.
  if (request.getHeader('host') === HOST) {
    request.setHeader('host', request.uri.host);
  }

  // If the requester is not request-promise, ensure we get a callback.
  if (typeof request.callback !== 'function') {
    throw new TypeError('Expected a callback function, got ' +
        typeof (request.callback) + ' instead.');
  }

  // We only need the callback from the first request.
  // The other callbacks can be safely ignored.
  if (isFirstRequest) {
    // This should be a user supplied callback or request-promise's callback.
    // The callback is always wrapped/bound to the request instance.
    options.callback = request.callback;
  }

  request.removeAllListeners('error')
    .once('error', function (error) {
      onRequestResponse(options, error);
    });

  request.removeAllListeners('complete')
    .once('complete', function (response, body) {
      onRequestResponse(options, null, response, body);
    });

  // Indicate that this is a cloudscraper request
  request.cloudscraper = true;
  return request;
}
function performRequest ( options , isFirstRequest ) { // This should be the default export of either request or request-promise. const requester = options . requester ; // Note that request is always an instanceof ReadableStream, EventEmitter // If the requester is request-promise, it is also thenable. const request = requester ( options ) ; // We must define the host header ourselves to preserve case and order. if ( request . getHeader ( 'host' ) === HOST ) { request . setHeader ( 'host' , request . uri . host ) ; } // If the requester is not request-promise, ensure we get a callback. if ( typeof request . callback !== 'function' ) { throw new TypeError ( 'Expected a callback function, got ' + typeof ( request . callback ) + ' instead.' ) ; } // We only need the callback from the first request. // The other callbacks can be safely ignored. if ( isFirstRequest ) { // This should be a user supplied callback or request-promise's callback. // The callback is always wrapped/bound to the request instance. options . callback = request . callback ; } request . removeAllListeners ( 'error' ) . once ( 'error' , function ( error ) { onRequestResponse ( options , error ) ; } ) ; request . removeAllListeners ( 'complete' ) . once ( 'complete' , function ( response , body ) { onRequestResponse ( options , null , response , body ) ; } ) ; // Indicate that this is a cloudscraper request request . cloudscraper = true ; return request ; }
This function is wrapped to ensure that we get new options on first call. The options object is reused in subsequent calls when calling it directly.
This function is wrapped to ensure that we get new options on first call . The options object is reused in subsequent calls when calling it directly .