-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
test-form-urlencoded.js
59 lines (46 loc) 路 1.18 KB
/
test-form-urlencoded.js
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
'use strict'
var http = require('http')
, request = require('../index')
, tape = require('tape')
function runTest (t, options) {
var server = http.createServer(function(req, res) {
t.ok(req.headers['content-type'].match(/application\/x-www-form-urlencoded/))
t.equal(req.headers.accept, 'application/json')
var data = ''
req.setEncoding('utf8')
req.on('data', function(d) {
data += d
})
req.on('end', function() {
t.equal(data, 'some=url&encoded=data')
res.writeHead(200)
res.end('done')
})
})
server.listen(6767, function() {
request.post('http://localhost:6767', options, function(err, res, body) {
t.equal(err, null)
t.equal(res.statusCode, 200)
t.equal(body, 'done')
server.close(function() {
t.end()
})
})
})
}
var cases = [
{
form: {some: 'url', encoded: 'data'},
json: true
},
{
headers: {'content-type': 'application/x-www-form-urlencoded; charset=UTF-8'},
body: 'some=url&encoded=data',
json: true
}
]
cases.forEach(function (options, index) {
tape('application/x-www-form-urlencoded ' + index, function(t) {
runTest(t, options)
})
})