mirror of https://github.com/lukechilds/node.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
791 B
30 lines
791 B
var request = require('../index');
|
|
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();
|
|
});
|
|
|