How to use the methods.slice function in methods

To help you get started, we’ve selected a few methods 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 pillarjs / router / test / router.js View on Github external
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) {
github pillarjs / router / test / route.js View on Github external
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)
github expressjs / body-parser / test / body-parser.js View on Github external
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)
      })
    })
  })
github mendersoftware / gui / node_modules / superagent / lib / node / index.js View on Github external
// 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);
      }
github concur / skipper / node_modules / superagent / lib / node / index.js View on Github external
// 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);
      }
github AntSwordProject / antSword / node_modules / superagent / lib / node / index.js View on Github external
// 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);
      }
github MindFreakers / cdn / node_modules / superagent / lib / node / index.js View on Github external
// 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;
  };
});
github hsiW / WishBot / node_modules / discord.js / node_modules / superagent / lib / node / index.js View on Github external
}

  // 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;
  };
});
github visionmedia / superagent / src / node / index.js View on Github external
}

  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) {
github MindFreakers / cdn / node_modules / superagent / lib / node / agent.js View on Github external
* @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));