source: Dev/trunk/src/node_modules/request/tests/test-follow-all.js @ 484

Last change on this file since 484 was 484, checked in by hendrikvanantwerpen, 11 years ago

Commit node_modules, to make checkouts and builds more deterministic.

File size: 850 bytes
Line 
1var request = require('../index');
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});
Note: See TracBrowser for help on using the repository browser.