File: test-follow-all-303.js

package info (click to toggle)
node-request 2.88.1-6
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 960 kB
  • sloc: javascript: 9,687; sh: 46; makefile: 2
file content (45 lines) | stat: -rw-r--r-- 886 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
'use strict'

var http = require('http')
var request = require('../index')
var tape = require('tape')

var server = http.createServer(function (req, res) {
  if (req.method === 'POST') {
    res.setHeader('location', req.url)
    res.statusCode = 303
    res.end('try again')
  } else {
    res.end('ok')
  }
})

tape('setup', function (t) {
  server.listen(0, function () {
    server.url = 'http://localhost:' + this.address().port
    t.end()
  })
})

tape('followAllRedirects with 303', function (t) {
  var redirects = 0

  request.post({
    url: server.url + '/foo',
    followAllRedirects: true,
    form: { foo: 'bar' }
  }, function (err, res, body) {
    t.equal(err, null)
    t.equal(body, 'ok')
    t.equal(redirects, 1)
    t.end()
  }).on('redirect', function () {
    redirects++
  })
})

tape('cleanup', function (t) {
  server.close(function () {
    t.end()
  })
})