Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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}));
}
})
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
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]);
}
}
exports.request = function() {
return request.apply(this, arguments);
};
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]);
}
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);
};
_request() {
return request.apply(undefined, arguments);
},
YQL.prototype._httpRequest = function () {
request.apply(null, arguments)
};