PageRenderTime 21ms CodeModel.GetById 16ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/node_modules/request/tests/test-follow-all.js

https://bitbucket.org/gagginaspinnata/todo-app-with-angularjs
JavaScript | 35 lines | 28 code | 6 blank | 1 comment | 5 complexity | 496d91366d1e0d8b8a4a42489c74f838 MD5 | raw file
Possible License(s): Apache-2.0, MIT
 1var request = require('../main');
 2var http = require('http');
 3var requests = 0;
 4var assert = require('assert');
 5
 6var server = http.createServer(function (req, res) {
 7  requests ++;
 8
 9  // redirect everything 3 times, no matter what.
10  var c = req.headers.cookie;
11
12  if (!c) c = 0;
13  else c = +c.split('=')[1] || 0;
14
15  if (c > 3) {
16    res.end('ok: '+requests);
17    return;
18  }
19
20  res.setHeader('set-cookie', 'c=' + (c + 1));
21  res.setHeader('location', req.url);
22  res.statusCode = 302;
23  res.end('try again, i guess\n');
24});
25server.listen(6767);
26
27request.post({ url: 'http://localhost:6767/foo',
28               followAllRedirects: true,
29               form: { foo: 'bar' } }, function (er, req, body) {
30  if (er) throw er;
31  assert.equal(body, 'ok: 5');
32  assert.equal(requests, 5);
33  console.error('ok - ' + process.version);
34  server.close();
35});