Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if ('0' === res.headers['content-length']) {
// We know that the body is empty (unfortunately, this check does not cover chunked encoding)
return false;
}
// console.log(res);
return /^\s*(?:deflate|gzip)\s*$/.test(res.headers['content-encoding']);
};
// generate HTTP verb methods
if (methods.indexOf('del') == -1) {
// create a copy so we don't cause conflicts with
// other packages using the methods package and
// npm 3.x
methods = methods.slice(0);
methods.push('del');
}
methods.forEach(method => {
const name = method;
method = 'del' == method ? 'delete' : method;
method = method.toUpperCase();
request[name] = (url, data, fn) => {
const req = request(method, url);
if ('function' == typeof data) (fn = data), (data = null);
if (data) {
if (method === 'GET' || method === 'HEAD') {
req.query(data);
} else {
req.send(data);
}
}
if ('0' === res.headers['content-length']) {
// We know that the body is empty (unfortunately, this check does not cover chunked encoding)
return false;
}
// console.log(res);
return /^\s*(?:deflate|gzip)\s*$/.test(res.headers['content-encoding']);
};
// generate HTTP verb methods
if (methods.indexOf('del') == -1) {
// create a copy so we don't cause conflicts with
// other packages using the methods package and
// npm 3.x
methods = methods.slice(0);
methods.push('del');
}
methods.forEach(method => {
const name = method;
method = 'del' == method ? 'delete' : method;
method = method.toUpperCase();
request[name] = (url, data, fn) => {
const req = request(method, url);
if ('function' == typeof data) (fn = data), (data = null);
if (data) {
if (method === 'GET' || method === 'HEAD') {
req.query(data);
} else {
req.send(data);
}
}
if ('0' === res.headers['content-length']) {
// We know that the body is empty (unfortunately, this check does not cover chunked encoding)
return false;
}
// console.log(res);
return /^\s*(?:deflate|gzip)\s*$/.test(res.headers['content-encoding']);
};
// generate HTTP verb methods
if (methods.indexOf('del') == -1) {
// create a copy so we don't cause conflicts with
// other packages using the methods package and
// npm 3.x
methods = methods.slice(0);
methods.push('del');
}
methods.forEach(method => {
const name = method;
method = 'del' == method ? 'delete' : method;
method = method.toUpperCase();
request[name] = (url, data, fn) => {
const req = request(method, url);
if ('function' == typeof data) (fn = data), (data = null);
if (data) {
if (method === 'GET' || method === 'HEAD') {
req.query(data);
} else {
req.send(data);
}
}
return /^\s*(?:deflate|gzip)\s*$/.test(res.headers['content-encoding']);
};
/**
* Expose `Request`.
*/
exports.Request = Request;
// generate HTTP verb methods
if (methods.indexOf('del') == -1) {
// create a copy so we don't cause conflicts with
// other packages using the methods package and
// npm 3.x
methods = methods.slice(0);
methods.push('del');
}
methods.forEach(function(method){
var name = method;
method = 'del' == method ? 'delete' : method;
method = method.toUpperCase();
request[name] = function(url, data, fn){
var req = request(method, url);
if ('function' == typeof data) fn = data, data = null;
if (data) req.send(data);
fn && req.end(fn);
return req;
};
});
/**
}
return this;
};
Request.prototype.trustLocalhost = function(toggle) {
this._trustLocalhost = toggle === undefined ? true : toggle;
return this;
};
// generate HTTP verb methods
if (methods.indexOf('del') == -1) {
// create a copy so we don't cause conflicts with
// other packages using the methods package and
// npm 3.x
methods = methods.slice(0);
methods.push('del');
}
methods.forEach(method => {
const name = method;
method = 'del' == method ? 'delete' : method;
method = method.toUpperCase();
request[name] = (url, data, fn) => {
const req = request(method, url);
if ('function' == typeof data) (fn = data), (data = null);
if (data) {
if (method === 'GET' || method === 'HEAD') {
req.query(data);
} else {
req.send(data);
}
}
if ((ret = this._nesteds[j].match(request))) {
return ret;
}
}
}
// route is not matched
return null;
};
/**
* Define supported HTTP methods for Route object
* and all failback method
*/
if (methods[methods.length - 1] !== 'all') {
methods.push('all');
}
methods.forEach(function (METHOD) {
Route.prototype[METHOD] = function () {
var cbs = Array.prototype.slice.apply(arguments),
that = this;
cbs.forEach(function (cb) {
util.isGenerator(cb, that);
});
this.handlers[METHOD.toUpperCase()] = cbs;
return this;
};
});
return this;
};
Request.prototype.trustLocalhost = function(toggle) {
this._trustLocalhost = toggle === undefined ? true : toggle;
return this;
};
// generate HTTP verb methods
if (!methods.includes('del')) {
// create a copy so we don't cause conflicts with
// other packages using the methods package and
// npm 3.x
methods = methods.slice(0);
methods.push('del');
}
methods.forEach(method => {
const name = method;
method = method === 'del' ? 'delete' : method;
method = method.toUpperCase();
request[name] = (url, data, fn) => {
const req = request(method, url);
if (typeof data === 'function') {
fn = data;
data = null;
}
if (data) {
if (method === 'GET' || method === 'HEAD') {
// url first
if (1 == arguments.length) {
return new Request('GET', method);
}
return new Request(method, url);
}
// generate HTTP verb methods
if (methods.indexOf('del') == -1) {
// create a copy so we don't cause conflicts with
// other packages using the methods package and
// npm 3.x
methods = methods.slice(0);
methods.push('del');
}
methods.forEach(function(method){
var name = method;
method = 'del' == method ? 'delete' : method;
method = method.toUpperCase();
request[name] = function(url, data, fn){
var req = request(method, url);
if ('function' == typeof data) fn = data, data = null;
if (data) req.send(data);
fn && req.end(fn);
return req;
};
});
/**
it('should wrap/unwrap express on start/stop', function() {
var express = require('./plugins/fixtures/express4');
var patchedMethods = require('methods');
patchedMethods.push('use', 'route', 'param', 'all');
patchedMethods.forEach(function(method) {
wrapTest(express.application, method);
});
});
var _superagent = require('superagent');
var methods = require('methods');
var assign = require('object-assign');
var uses = [];
var superagent = assign({}, _superagent);
superagent.use = function(fn) {
uses.push(fn);
return this;
};
methods.indexOf('del') == -1 && methods.push('del');
methods.forEach(function(method) {
superagent[method] = function() {
var request = _superagent[method].apply(superagent, arguments);
uses.forEach(function(use) {
request = request.use(use);
});
return request;
};
});
module.exports = superagent;