How to use the request.apply function in request

To help you get started, we’ve selected a few request examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nodejitsu / txn / test / txn.js View on Github external
function track_request(req, callback) {
      if(req.method != 'GET' || ! req.uri.match(/\/conc$/))
        return request.apply(this, arguments);

      gets += 1;
      if(gets > 3)
        return request.apply(this, arguments);

      // Return the same thing over and over to produce many conflicts in a row.
      return callback(null, {statusCode:200}, JSON.stringify({_id:'conc', _rev:bad_rev}));
    }
  })
github jhaynie / request-ssl / lib / index.js View on Github external
url = _.isObject(args[0]) ? opts.url || opts.uri : args[0],
		callback = arguments[arguments.length-1];
	if (!url) { throw new Error("missing url"); }
	var isSSL = urlib.parse(url).protocol === 'https:';
	// if passed in a URL string
	if (_.isString(args[0])) {
		opts = {
			url: url
		};
		args[0] = opts;
	}
	if (isSSL) {
		opts.agentOptions = _.merge(_.clone(opts.agentOptions||{}),{secureProtocol: secureProtocol});
	}
	debug('request-> %j (%d) [%s]',opts,isSSL,url);
	var req = request.apply(null, args);
	if (isSSL) {
		var hasCallback = !!callback && _.isFunction(callback);
		// wrap our callback to only allow once callback
		var originalCallback = hasCallback && callback;
		var wrappedCallback = function() {
			if (hasCallback && originalCallback) {
				originalCallback.apply(null,arguments);
				originalCallback = null;
			}
			else if (!hasCallback) {
				hasCallback = true; // so we don't call again
				req.emit('error',arguments[0]);
			}
		};
		callback = wrappedCallback;
		Request._lastURL = url; // useful for testing
github jhs / audit_couchdb / node_modules / probe_couchdb / emitter.js View on Github external
if(typeof opts == 'string')
    opts = {uri:opts};

  opts.proxy  = opts.proxy  || self.proxy || DEFS.http_proxy;
  opts.client = opts.client || self.client;
  opts.followRedirect = false;

  opts.headers = opts.headers || {};
  opts.headers.accept = opts.headers.accept || 'application/json';
  //opts.headers.Connection = opts.headers.Connection || 'keep-alive';

  if(opts.method && opts.method !== "GET" && opts.method !== "HEAD")
    opts.headers['content-type'] = 'application/json';

  return request.apply(self, [opts, json_body]);

  function json_body(er, resp, body) {
    if(!er) {
      try      { body = JSON.parse(body) }
      catch(e) { er = e }
    }

    // TODO: Maybe set self.client = resp.client?
    return callback && callback.apply(this, [er, resp, body]);
  }
}
github devongovett / reader / tests / shared.js View on Github external
exports.request = function() {
    return request.apply(this, arguments);
};
github jhs / audit_couchdb / probe_couchdb.js View on Github external
return callback && callback.apply(this, [er, resp, body]);
  }

  opts.proxy  = opts.proxy  || self.proxy;
  opts.client = opts.client || self.client;
  opts.followRedirect = false;

  opts.headers = opts.headers || {};
  opts.headers.accept = opts.headers.accept || 'application/json';
  //opts.headers.Connection = opts.headers.Connection || 'keep-alive';

  if(opts.method && opts.method !== "GET" && opts.method !== "HEAD")
    opts.headers['content-type'] = 'application/json';

  return request.apply(self, [opts, json_body]);
}
github luminati-io / luminati-proxy / lib / server.js View on Github external
E.prototype.request = function(){
    const args = [].slice.call(arguments);
    if (typeof args[0]=='string')
        args[0] = {url: args[0]};
    args[0].proxy = args[0].proxy||`http://127.0.0.1:${this.port}`;
    return request.apply(null, args);
};
github danielwippermann / resol-vbus / src / dlx-recorder.js View on Github external
_request() {
        return request.apply(undefined, arguments);
    },
github derek / node-yql / yql.js View on Github external
YQL.prototype._httpRequest = function () {
    request.apply(null, arguments)
};