~cordova-ubuntu/cordova-cli/trunk

« back to all changes in this revision

Viewing changes to node_modules/cordova/_vendor/request/2.22.0/tests/test-follow-all-303.js

  • Committer: Robert Bruce Park
  • Date: 2014-02-26 21:27:56 UTC
  • mfrom: (44.1.5 3.4-release)
  • Revision ID: robert.park@canonical.com-20140226212756-6jmoiqugw0f1ebxb
Update to 3.4.0 stable release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
});