forked from request/request
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request request#290 from isaacs/master
A test for request#289
- Loading branch information
Showing
4 changed files
with
71 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
var request = require('request'); | ||
var http = require('http'); | ||
var requests = 0; | ||
var assert = require('assert'); | ||
|
||
var server = http.createServer(function (req, res) { | ||
console.error(req.method, req.url); | ||
requests ++; | ||
|
||
if (req.method === 'POST') { | ||
console.error('send 303'); | ||
res.setHeader('location', req.url); | ||
res.statusCode = 303; | ||
res.end('try again, i guess\n'); | ||
} else { | ||
console.error('send 200') | ||
res.end('ok: ' + requests); | ||
} | ||
}); | ||
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: 2'); | ||
assert.equal(requests, 2); | ||
console.error('ok - ' + process.version); | ||
server.close(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); |