Skip to content

Commit

Permalink
Test for #289
Browse files Browse the repository at this point in the history
Seems to work as expected
  • Loading branch information
isaacs committed Jul 31, 2012
1 parent 6297612 commit d38e57b
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions tests/test-follow-all.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
var request = require('request');
var http = require('http');
var requests = 0;
var assert = require('assert');

var server = http.createServer(function (req, res) {
requests ++;

// redirect everything 3 times, no matter what.
var c = req.headers.cookie;

if (!c) c = 0;
else c = +c.split('=')[1] || 0;

if (c > 3) {
res.end('ok: '+requests);
return;
}

res.setHeader('set-cookie', 'c=' + (c + 1));
res.setHeader('location', req.url);
res.statusCode = 302;
res.end('try again, i guess\n');
});
server.listen(6767);

request.post({ url: 'http://localhost:6767/foo',
followAllRedirects: true,
form: { foo: 'bar' } }, function (er, req, body) {
if (er) throw er;
assert.equal(body, 'ok: 5');
assert.equal(requests, 5);
console.error('ok - ' + process.version);
server.close();
});

0 comments on commit d38e57b

Please sign in to comment.