Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var server = createServer(router)
router.all('/foo', saw)
request(server)
.get('/foo')
.expect(200, 'saw GET /foo', cb)
request(server)
.get('/foo/')
.expect(404, cb)
})
})
})
methods.slice().sort().forEach(function (method) {
if (method === 'connect') {
// CONNECT is tricky and supertest doesn't support it
return
}
var body = method !== 'head'
? 'hello, world'
: ''
describe('.' + method + '(path, ...fn)', function () {
it('should be chainable', function () {
var router = new Router()
assert.equal(router[method]('/', helloWorld), router)
})
it('should respond to a ' + method.toUpperCase() + ' request', function (done) {
var router = new Router()
var route = router.route('/foo')
var server = createServer(router)
route.all([[createHitHandle(1), createHitHandle(2)], createHitHandle(3)], helloWorld)
request(server)
.get('/foo')
.expect('x-fn-1', 'hit')
.expect('x-fn-2', 'hit')
.expect('x-fn-3', 'hit')
.expect(200, 'hello, world', done)
})
})
methods.slice().sort().forEach(function (method) {
if (method === 'connect') {
// CONNECT is tricky and supertest doesn't support it
return
}
var body = method !== 'head'
? 'hello, world'
: ''
describe('.' + method + '(...fn)', function () {
it('should respond to a ' + method.toUpperCase() + ' request', function (done) {
var router = new Router()
var route = router.route('/')
var server = createServer(router)
route[method](helloWorld)
res.statusCode = 500
res.end(err.message)
return
}
res.statusCode = req.headers['x-expect-method'] === req.method
? req.body.user === 'tobi'
? 201
: 400
: 405
res.end()
})
})
})
methods.slice().sort().forEach(function (method) {
if (method === 'connect') {
// except CONNECT
return
}
it('should support ' + method.toUpperCase() + ' requests', function (done) {
request(this.server)[method]('/')
.set('Content-Type', 'application/json')
.set('Content-Length', '15')
.set('X-Expect-Method', method.toUpperCase())
.send('{"user":"tobi"}')
.expect(201, done)
})
})
})
// header content is a string, and distinction between 0 and no information is crucial
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);
}
// header content is a string, and distinction between 0 and no information is crucial
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);
}
// header content is a string, and distinction between 0 and no information is crucial
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);
}
// console.log(res);
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;
};
});
}
// 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;
};
});
}
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) {
* @api private
*/
Agent.prototype._attachCookies = function(req){
var url = parse(req.url);
var access = CookieAccess(url.hostname, url.pathname, 'https:' == url.protocol);
var cookies = this.jar.getCookies(access).toValueString();
req.cookies = cookies;
};
// 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();
Agent.prototype[name] = function(url, fn){
var req = new request.Request(method, url);
req.ca(this._ca);
req.key(this._key);
req.pfx(this._pfx);
req.cert(this._cert);
req.on('response', this._saveCookies.bind(this));
req.on('redirect', this._saveCookies.bind(this));