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:
791 bytes
|
Line | |
---|
1 | var request = require('../index'); |
---|
2 | var http = require('http'); |
---|
3 | var requests = 0; |
---|
4 | var assert = require('assert'); |
---|
5 | |
---|
6 | var server = http.createServer(function (req, res) { |
---|
7 | console.error(req.method, req.url); |
---|
8 | requests ++; |
---|
9 | |
---|
10 | if (req.method === 'POST') { |
---|
11 | console.error('send 303'); |
---|
12 | res.setHeader('location', req.url); |
---|
13 | res.statusCode = 303; |
---|
14 | res.end('try again, i guess\n'); |
---|
15 | } else { |
---|
16 | console.error('send 200') |
---|
17 | res.end('ok: ' + requests); |
---|
18 | } |
---|
19 | }); |
---|
20 | server.listen(6767); |
---|
21 | |
---|
22 | request.post({ url: 'http://localhost:6767/foo', |
---|
23 | followAllRedirects: true, |
---|
24 | form: { foo: 'bar' } }, function (er, req, body) { |
---|
25 | if (er) throw er; |
---|
26 | assert.equal(body, 'ok: 2'); |
---|
27 | assert.equal(requests, 2); |
---|
28 | console.error('ok - ' + process.version); |
---|
29 | server.close(); |
---|
30 | }); |
---|
Note: See
TracBrowser
for help on using the repository browser.