@wiajs/request 3.0.1 → 3.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/.github/ISSUE_TEMPLATE.md +0 -56
- package/.github/PULL_REQUEST_TEMPLATE.md +0 -13
- package/.github/stale.yml +0 -19
- package/.swcrc +0 -57
- package/.travis.yml +0 -21
- package/CONTRIBUTING.md +0 -81
- package/biome.json +0 -44
- package/codecov.yml +0 -2
- package/disabled.appveyor.yml +0 -36
- package/examples/README.md +0 -135
- package/gulpfile.js +0 -71
- package/release.sh +0 -45
- package/tests/browser/karma.conf.js +0 -57
- package/tests/browser/ssl/ca.crt +0 -14
- package/tests/browser/ssl/server.crt +0 -14
- package/tests/browser/ssl/server.key +0 -15
- package/tests/browser/start.js +0 -37
- package/tests/browser/test.js +0 -34
- package/tests/fixtures/har.json +0 -158
- package/tests/googledoodle.jpg +0 -0
- package/tests/server.js +0 -142
- package/tests/squid.conf +0 -76
- package/tests/ssl/ca/README.md +0 -8
- package/tests/ssl/ca/ca.cnf +0 -20
- package/tests/ssl/ca/ca.crl +0 -0
- package/tests/ssl/ca/ca.crt +0 -17
- package/tests/ssl/ca/ca.csr +0 -13
- package/tests/ssl/ca/ca.key +0 -18
- package/tests/ssl/ca/ca.srl +0 -1
- package/tests/ssl/ca/client-enc.key +0 -30
- package/tests/ssl/ca/client.cnf +0 -20
- package/tests/ssl/ca/client.crt +0 -20
- package/tests/ssl/ca/client.csr +0 -18
- package/tests/ssl/ca/client.key +0 -27
- package/tests/ssl/ca/gen-all-certs.sh +0 -6
- package/tests/ssl/ca/gen-client.sh +0 -25
- package/tests/ssl/ca/gen-localhost.sh +0 -22
- package/tests/ssl/ca/gen-server.sh +0 -18
- package/tests/ssl/ca/localhost.cnf +0 -20
- package/tests/ssl/ca/localhost.crt +0 -20
- package/tests/ssl/ca/localhost.csr +0 -18
- package/tests/ssl/ca/localhost.js +0 -33
- package/tests/ssl/ca/localhost.key +0 -27
- package/tests/ssl/ca/server.cnf +0 -19
- package/tests/ssl/ca/server.crt +0 -25
- package/tests/ssl/ca/server.csr +0 -29
- package/tests/ssl/ca/server.js +0 -34
- package/tests/ssl/ca/server.key +0 -51
- package/tests/ssl/npm-ca.crt +0 -16
- package/tests/ssl/test.crt +0 -15
- package/tests/ssl/test.key +0 -15
- package/tests/test-agent.js +0 -102
- package/tests/test-agentOptions.js +0 -51
- package/tests/test-api.js +0 -33
- package/tests/test-aws.js +0 -123
- package/tests/test-baseUrl.js +0 -133
- package/tests/test-basic-auth.js +0 -221
- package/tests/test-bearer-auth.js +0 -187
- package/tests/test-body.js +0 -154
- package/tests/test-cookies.js +0 -130
- package/tests/test-defaults.js +0 -340
- package/tests/test-digest-auth.js +0 -232
- package/tests/test-emptyBody.js +0 -56
- package/tests/test-errors.js +0 -108
- package/tests/test-event-forwarding.js +0 -39
- package/tests/test-follow-all-303.js +0 -45
- package/tests/test-follow-all.js +0 -57
- package/tests/test-form-data-error.js +0 -85
- package/tests/test-form-data.js +0 -133
- package/tests/test-form-urlencoded.js +0 -73
- package/tests/test-form.js +0 -101
- package/tests/test-gzip.js +0 -296
- package/tests/test-har.js +0 -175
- package/tests/test-hawk.js +0 -187
- package/tests/test-headers.js +0 -305
- package/tests/test-http-signature.js +0 -110
- package/tests/test-httpModule.js +0 -112
- package/tests/test-https.js +0 -116
- package/tests/test-isUrl.js +0 -120
- package/tests/test-json-request.js +0 -117
- package/tests/test-localAddress.js +0 -49
- package/tests/test-multipart-encoding.js +0 -147
- package/tests/test-multipart.js +0 -129
- package/tests/test-node-debug.js +0 -95
- package/tests/test-oauth.js +0 -721
- package/tests/test-onelineproxy.js +0 -61
- package/tests/test-option-reuse.js +0 -54
- package/tests/test-options-convenience-method.js +0 -52
- package/tests/test-params.js +0 -101
- package/tests/test-piped-redirect.js +0 -55
- package/tests/test-pipes.js +0 -383
- package/tests/test-pool.js +0 -148
- package/tests/test-promise.js +0 -53
- package/tests/test-proxy-connect.js +0 -80
- package/tests/test-proxy.js +0 -304
- package/tests/test-qs.js +0 -135
- package/tests/test-redirect-auth.js +0 -131
- package/tests/test-redirect-complex.js +0 -93
- package/tests/test-redirect.js +0 -449
- package/tests/test-rfc3986.js +0 -106
- package/tests/test-stream.js +0 -36
- package/tests/test-timeout.js +0 -260
- package/tests/test-timing.js +0 -147
- package/tests/test-toJSON.js +0 -45
- package/tests/test-tunnel.js +0 -466
- package/tests/test-unix.js +0 -74
- package/tests/unicycle.jpg +0 -0
|
@@ -1,232 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
var http = require('http')
|
|
4
|
-
var request = require('../index')
|
|
5
|
-
var tape = require('tape')
|
|
6
|
-
var crypto = require('crypto')
|
|
7
|
-
|
|
8
|
-
function makeHeader () {
|
|
9
|
-
return [].join.call(arguments, ', ')
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
function makeHeaderRegex () {
|
|
13
|
-
return new RegExp('^' + makeHeader.apply(null, arguments) + '$')
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function md5 (str) {
|
|
17
|
-
return crypto.createHash('md5').update(str).digest('hex')
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
var digestServer = http.createServer(function (req, res) {
|
|
21
|
-
var ok,
|
|
22
|
-
testHeader
|
|
23
|
-
|
|
24
|
-
if (req.url === '/test/') {
|
|
25
|
-
if (req.headers.authorization) {
|
|
26
|
-
testHeader = makeHeaderRegex(
|
|
27
|
-
'Digest username="test"',
|
|
28
|
-
'realm="Private"',
|
|
29
|
-
'nonce="WpcHS2/TBAA=dffcc0dbd5f96d49a5477166649b7c0ae3866a93"',
|
|
30
|
-
'uri="/test/"',
|
|
31
|
-
'qop=auth',
|
|
32
|
-
'response="[a-f0-9]{32}"',
|
|
33
|
-
'nc=00000001',
|
|
34
|
-
'cnonce="[a-f0-9]{32}"',
|
|
35
|
-
'algorithm=MD5',
|
|
36
|
-
'opaque="5ccc069c403ebaf9f0171e9517f40e41"'
|
|
37
|
-
)
|
|
38
|
-
if (testHeader.test(req.headers.authorization)) {
|
|
39
|
-
ok = true
|
|
40
|
-
} else {
|
|
41
|
-
// Bad auth header, don't send back WWW-Authenticate header
|
|
42
|
-
ok = false
|
|
43
|
-
}
|
|
44
|
-
} else {
|
|
45
|
-
// No auth header, send back WWW-Authenticate header
|
|
46
|
-
ok = false
|
|
47
|
-
res.setHeader('www-authenticate', makeHeader(
|
|
48
|
-
'Digest realm="Private"',
|
|
49
|
-
'nonce="WpcHS2/TBAA=dffcc0dbd5f96d49a5477166649b7c0ae3866a93"',
|
|
50
|
-
'algorithm=MD5',
|
|
51
|
-
'qop="auth"',
|
|
52
|
-
'opaque="5ccc069c403ebaf9f0171e9517f40e41"'
|
|
53
|
-
))
|
|
54
|
-
}
|
|
55
|
-
} else if (req.url === '/test/md5-sess') { // RFC 2716 MD5-sess w/ qop=auth
|
|
56
|
-
var user = 'test'
|
|
57
|
-
var realm = 'Private'
|
|
58
|
-
var pass = 'testing'
|
|
59
|
-
var nonce = 'WpcHS2/TBAA=dffcc0dbd5f96d49a5477166649b7c0ae3866a93'
|
|
60
|
-
var nonceCount = '00000001'
|
|
61
|
-
var qop = 'auth'
|
|
62
|
-
var algorithm = 'MD5-sess'
|
|
63
|
-
if (req.headers.authorization) {
|
|
64
|
-
// HA1=MD5(MD5(username:realm:password):nonce:cnonce)
|
|
65
|
-
// HA2=MD5(method:digestURI)
|
|
66
|
-
// response=MD5(HA1:nonce:nonceCount:clientNonce:qop:HA2)
|
|
67
|
-
|
|
68
|
-
var cnonce = /cnonce="(.*)"/.exec(req.headers.authorization)[1]
|
|
69
|
-
var ha1 = md5(md5(user + ':' + realm + ':' + pass) + ':' + nonce + ':' + cnonce)
|
|
70
|
-
var ha2 = md5('GET:/test/md5-sess')
|
|
71
|
-
var response = md5(ha1 + ':' + nonce + ':' + nonceCount + ':' + cnonce + ':' + qop + ':' + ha2)
|
|
72
|
-
|
|
73
|
-
testHeader = makeHeaderRegex(
|
|
74
|
-
'Digest username="' + user + '"',
|
|
75
|
-
'realm="' + realm + '"',
|
|
76
|
-
'nonce="' + nonce + '"',
|
|
77
|
-
'uri="/test/md5-sess"',
|
|
78
|
-
'qop=' + qop,
|
|
79
|
-
'response="' + response + '"',
|
|
80
|
-
'nc=' + nonceCount,
|
|
81
|
-
'cnonce="' + cnonce + '"',
|
|
82
|
-
'algorithm=' + algorithm
|
|
83
|
-
)
|
|
84
|
-
|
|
85
|
-
ok = testHeader.test(req.headers.authorization)
|
|
86
|
-
} else {
|
|
87
|
-
// No auth header, send back WWW-Authenticate header
|
|
88
|
-
ok = false
|
|
89
|
-
res.setHeader('www-authenticate', makeHeader(
|
|
90
|
-
'Digest realm="' + realm + '"',
|
|
91
|
-
'nonce="' + nonce + '"',
|
|
92
|
-
'algorithm=' + algorithm,
|
|
93
|
-
'qop="' + qop + '"'
|
|
94
|
-
))
|
|
95
|
-
}
|
|
96
|
-
} else if (req.url === '/dir/index.html') {
|
|
97
|
-
// RFC2069-compatible mode
|
|
98
|
-
// check: http://www.rfc-editor.org/errata_search.php?rfc=2069
|
|
99
|
-
if (req.headers.authorization) {
|
|
100
|
-
testHeader = makeHeaderRegex(
|
|
101
|
-
'Digest username="Mufasa"',
|
|
102
|
-
'realm="testrealm@host.com"',
|
|
103
|
-
'nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093"',
|
|
104
|
-
'uri="/dir/index.html"',
|
|
105
|
-
'response="[a-f0-9]{32}"',
|
|
106
|
-
'opaque="5ccc069c403ebaf9f0171e9517f40e41"'
|
|
107
|
-
)
|
|
108
|
-
if (testHeader.test(req.headers.authorization)) {
|
|
109
|
-
ok = true
|
|
110
|
-
} else {
|
|
111
|
-
// Bad auth header, don't send back WWW-Authenticate header
|
|
112
|
-
ok = false
|
|
113
|
-
}
|
|
114
|
-
} else {
|
|
115
|
-
// No auth header, send back WWW-Authenticate header
|
|
116
|
-
ok = false
|
|
117
|
-
res.setHeader('www-authenticate', makeHeader(
|
|
118
|
-
'Digest realm="testrealm@host.com"',
|
|
119
|
-
'nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093"',
|
|
120
|
-
'opaque="5ccc069c403ebaf9f0171e9517f40e41"'
|
|
121
|
-
))
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
if (ok) {
|
|
126
|
-
res.end('ok')
|
|
127
|
-
} else {
|
|
128
|
-
res.statusCode = 401
|
|
129
|
-
res.end('401')
|
|
130
|
-
}
|
|
131
|
-
})
|
|
132
|
-
|
|
133
|
-
tape('setup', function (t) {
|
|
134
|
-
digestServer.listen(0, function () {
|
|
135
|
-
digestServer.url = 'http://localhost:' + this.address().port
|
|
136
|
-
t.end()
|
|
137
|
-
})
|
|
138
|
-
})
|
|
139
|
-
|
|
140
|
-
tape('with sendImmediately = false', function (t) {
|
|
141
|
-
var numRedirects = 0
|
|
142
|
-
|
|
143
|
-
request({
|
|
144
|
-
method: 'GET',
|
|
145
|
-
uri: digestServer.url + '/test/',
|
|
146
|
-
auth: {
|
|
147
|
-
user: 'test',
|
|
148
|
-
pass: 'testing',
|
|
149
|
-
sendImmediately: false
|
|
150
|
-
}
|
|
151
|
-
}, function (error, response, body) {
|
|
152
|
-
t.equal(error, null)
|
|
153
|
-
t.equal(response.statusCode, 200)
|
|
154
|
-
t.equal(numRedirects, 1)
|
|
155
|
-
t.end()
|
|
156
|
-
}).on('redirect', function () {
|
|
157
|
-
t.equal(this.response.statusCode, 401)
|
|
158
|
-
numRedirects++
|
|
159
|
-
})
|
|
160
|
-
})
|
|
161
|
-
|
|
162
|
-
tape('with MD5-sess algorithm', function (t) {
|
|
163
|
-
var numRedirects = 0
|
|
164
|
-
|
|
165
|
-
request({
|
|
166
|
-
method: 'GET',
|
|
167
|
-
uri: digestServer.url + '/test/md5-sess',
|
|
168
|
-
auth: {
|
|
169
|
-
user: 'test',
|
|
170
|
-
pass: 'testing',
|
|
171
|
-
sendImmediately: false
|
|
172
|
-
}
|
|
173
|
-
}, function (error, response, body) {
|
|
174
|
-
t.equal(error, null)
|
|
175
|
-
t.equal(response.statusCode, 200)
|
|
176
|
-
t.equal(numRedirects, 1)
|
|
177
|
-
t.end()
|
|
178
|
-
}).on('redirect', function () {
|
|
179
|
-
t.equal(this.response.statusCode, 401)
|
|
180
|
-
numRedirects++
|
|
181
|
-
})
|
|
182
|
-
})
|
|
183
|
-
|
|
184
|
-
tape('without sendImmediately = false', function (t) {
|
|
185
|
-
var numRedirects = 0
|
|
186
|
-
|
|
187
|
-
// If we don't set sendImmediately = false, request will send basic auth
|
|
188
|
-
request({
|
|
189
|
-
method: 'GET',
|
|
190
|
-
uri: digestServer.url + '/test/',
|
|
191
|
-
auth: {
|
|
192
|
-
user: 'test',
|
|
193
|
-
pass: 'testing'
|
|
194
|
-
}
|
|
195
|
-
}, function (error, response, body) {
|
|
196
|
-
t.equal(error, null)
|
|
197
|
-
t.equal(response.statusCode, 401)
|
|
198
|
-
t.equal(numRedirects, 0)
|
|
199
|
-
t.end()
|
|
200
|
-
}).on('redirect', function () {
|
|
201
|
-
t.equal(this.response.statusCode, 401)
|
|
202
|
-
numRedirects++
|
|
203
|
-
})
|
|
204
|
-
})
|
|
205
|
-
|
|
206
|
-
tape('with different credentials', function (t) {
|
|
207
|
-
var numRedirects = 0
|
|
208
|
-
|
|
209
|
-
request({
|
|
210
|
-
method: 'GET',
|
|
211
|
-
uri: digestServer.url + '/dir/index.html',
|
|
212
|
-
auth: {
|
|
213
|
-
user: 'Mufasa',
|
|
214
|
-
pass: 'CircleOfLife',
|
|
215
|
-
sendImmediately: false
|
|
216
|
-
}
|
|
217
|
-
}, function (error, response, body) {
|
|
218
|
-
t.equal(error, null)
|
|
219
|
-
t.equal(response.statusCode, 200)
|
|
220
|
-
t.equal(numRedirects, 1)
|
|
221
|
-
t.end()
|
|
222
|
-
}).on('redirect', function () {
|
|
223
|
-
t.equal(this.response.statusCode, 401)
|
|
224
|
-
numRedirects++
|
|
225
|
-
})
|
|
226
|
-
})
|
|
227
|
-
|
|
228
|
-
tape('cleanup', function (t) {
|
|
229
|
-
digestServer.close(function () {
|
|
230
|
-
t.end()
|
|
231
|
-
})
|
|
232
|
-
})
|
package/tests/test-emptyBody.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
var request = require('../index')
|
|
4
|
-
var http = require('http')
|
|
5
|
-
var tape = require('tape')
|
|
6
|
-
|
|
7
|
-
var s = http.createServer(function (req, resp) {
|
|
8
|
-
resp.statusCode = 200
|
|
9
|
-
resp.end('')
|
|
10
|
-
})
|
|
11
|
-
|
|
12
|
-
tape('setup', function (t) {
|
|
13
|
-
s.listen(0, function () {
|
|
14
|
-
s.url = 'http://localhost:' + this.address().port
|
|
15
|
-
t.end()
|
|
16
|
-
})
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
tape('empty body with encoding', function (t) {
|
|
20
|
-
request(s.url, function (err, res, body) {
|
|
21
|
-
t.equal(err, null)
|
|
22
|
-
t.equal(res.statusCode, 200)
|
|
23
|
-
t.equal(body, '')
|
|
24
|
-
t.end()
|
|
25
|
-
})
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
tape('empty body without encoding', function (t) {
|
|
29
|
-
request({
|
|
30
|
-
url: s.url,
|
|
31
|
-
encoding: null
|
|
32
|
-
}, function (err, res, body) {
|
|
33
|
-
t.equal(err, null)
|
|
34
|
-
t.equal(res.statusCode, 200)
|
|
35
|
-
t.same(body, Buffer.alloc(0))
|
|
36
|
-
t.end()
|
|
37
|
-
})
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
tape('empty JSON body', function (t) {
|
|
41
|
-
request({
|
|
42
|
-
url: s.url,
|
|
43
|
-
json: {}
|
|
44
|
-
}, function (err, res, body) {
|
|
45
|
-
t.equal(err, null)
|
|
46
|
-
t.equal(res.statusCode, 200)
|
|
47
|
-
t.equal(body, undefined)
|
|
48
|
-
t.end()
|
|
49
|
-
})
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
tape('cleanup', function (t) {
|
|
53
|
-
s.close(function () {
|
|
54
|
-
t.end()
|
|
55
|
-
})
|
|
56
|
-
})
|
package/tests/test-errors.js
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
var request = require('../index')
|
|
4
|
-
var tape = require('tape')
|
|
5
|
-
|
|
6
|
-
var local = 'http://localhost:0/asdf'
|
|
7
|
-
|
|
8
|
-
tape('without uri', function (t) {
|
|
9
|
-
t.throws(function () {
|
|
10
|
-
request({})
|
|
11
|
-
}, /^Error: options\.uri is a required argument$/)
|
|
12
|
-
t.end()
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
tape('invalid uri 1', function (t) {
|
|
16
|
-
t.throws(function () {
|
|
17
|
-
request({
|
|
18
|
-
uri: 'this-is-not-a-valid-uri'
|
|
19
|
-
})
|
|
20
|
-
}, /^Error: Invalid URI/)
|
|
21
|
-
t.end()
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
tape('invalid uri 2', function (t) {
|
|
25
|
-
t.throws(function () {
|
|
26
|
-
request({
|
|
27
|
-
uri: 'github.com/uri-is-not-valid-without-protocol'
|
|
28
|
-
})
|
|
29
|
-
}, /^Error: Invalid URI/)
|
|
30
|
-
t.end()
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
tape('invalid uri + NO_PROXY', function (t) {
|
|
34
|
-
process.env.NO_PROXY = 'google.com'
|
|
35
|
-
t.throws(function () {
|
|
36
|
-
request({
|
|
37
|
-
uri: 'invalid'
|
|
38
|
-
})
|
|
39
|
-
}, /^Error: Invalid URI/)
|
|
40
|
-
delete process.env.NO_PROXY
|
|
41
|
-
t.end()
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
tape('deprecated unix URL', function (t) {
|
|
45
|
-
t.throws(function () {
|
|
46
|
-
request({
|
|
47
|
-
uri: 'unix://path/to/socket/and/then/request/path'
|
|
48
|
-
})
|
|
49
|
-
}, /^Error: `unix:\/\/` URL scheme is no longer supported/)
|
|
50
|
-
t.end()
|
|
51
|
-
})
|
|
52
|
-
|
|
53
|
-
tape('invalid body', function (t) {
|
|
54
|
-
t.throws(function () {
|
|
55
|
-
request({
|
|
56
|
-
uri: local, body: {}
|
|
57
|
-
})
|
|
58
|
-
}, /^Error: Argument error, options\.body\.$/)
|
|
59
|
-
t.end()
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
tape('invalid multipart', function (t) {
|
|
63
|
-
t.throws(function () {
|
|
64
|
-
request({
|
|
65
|
-
uri: local,
|
|
66
|
-
multipart: 'foo'
|
|
67
|
-
})
|
|
68
|
-
}, /^Error: Argument error, options\.multipart\.$/)
|
|
69
|
-
t.end()
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
tape('multipart without body 1', function (t) {
|
|
73
|
-
t.throws(function () {
|
|
74
|
-
request({
|
|
75
|
-
uri: local,
|
|
76
|
-
multipart: [ {} ]
|
|
77
|
-
})
|
|
78
|
-
}, /^Error: Body attribute missing in multipart\.$/)
|
|
79
|
-
t.end()
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
tape('multipart without body 2', function (t) {
|
|
83
|
-
t.throws(function () {
|
|
84
|
-
request(local, {
|
|
85
|
-
multipart: [ {} ]
|
|
86
|
-
})
|
|
87
|
-
}, /^Error: Body attribute missing in multipart\.$/)
|
|
88
|
-
t.end()
|
|
89
|
-
})
|
|
90
|
-
|
|
91
|
-
tape('head method with a body', function (t) {
|
|
92
|
-
t.throws(function () {
|
|
93
|
-
request(local, {
|
|
94
|
-
method: 'HEAD',
|
|
95
|
-
body: 'foo'
|
|
96
|
-
})
|
|
97
|
-
}, /HTTP HEAD requests MUST NOT include a request body/)
|
|
98
|
-
t.end()
|
|
99
|
-
})
|
|
100
|
-
|
|
101
|
-
tape('head method with a body 2', function (t) {
|
|
102
|
-
t.throws(function () {
|
|
103
|
-
request.head(local, {
|
|
104
|
-
body: 'foo'
|
|
105
|
-
})
|
|
106
|
-
}, /HTTP HEAD requests MUST NOT include a request body/)
|
|
107
|
-
t.end()
|
|
108
|
-
})
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
var server = require('./server')
|
|
4
|
-
var request = require('../index')
|
|
5
|
-
var tape = require('tape')
|
|
6
|
-
|
|
7
|
-
var s = server.createServer()
|
|
8
|
-
|
|
9
|
-
tape('setup', function (t) {
|
|
10
|
-
s.listen(0, function () {
|
|
11
|
-
s.on('/', function (req, res) {
|
|
12
|
-
res.writeHead(200, { 'content-type': 'text/plain' })
|
|
13
|
-
res.write('waited')
|
|
14
|
-
res.end()
|
|
15
|
-
})
|
|
16
|
-
t.end()
|
|
17
|
-
})
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
tape('should emit socket event', function (t) {
|
|
21
|
-
t.plan(4)
|
|
22
|
-
|
|
23
|
-
var req = request(s.url, function (err, res, body) {
|
|
24
|
-
t.equal(err, null)
|
|
25
|
-
t.equal(res.statusCode, 200)
|
|
26
|
-
t.equal(body, 'waited')
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
req.on('socket', function (socket) {
|
|
30
|
-
var requestSocket = req.req.socket
|
|
31
|
-
t.equal(requestSocket, socket)
|
|
32
|
-
})
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
tape('cleanup', function (t) {
|
|
36
|
-
s.close(function () {
|
|
37
|
-
t.end()
|
|
38
|
-
})
|
|
39
|
-
})
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
var http = require('http')
|
|
4
|
-
var request = require('../index')
|
|
5
|
-
var tape = require('tape')
|
|
6
|
-
|
|
7
|
-
var server = http.createServer(function (req, res) {
|
|
8
|
-
if (req.method === 'POST') {
|
|
9
|
-
res.setHeader('location', req.url)
|
|
10
|
-
res.statusCode = 303
|
|
11
|
-
res.end('try again')
|
|
12
|
-
} else {
|
|
13
|
-
res.end('ok')
|
|
14
|
-
}
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
tape('setup', function (t) {
|
|
18
|
-
server.listen(0, function () {
|
|
19
|
-
server.url = 'http://localhost:' + this.address().port
|
|
20
|
-
t.end()
|
|
21
|
-
})
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
tape('followAllRedirects with 303', function (t) {
|
|
25
|
-
var redirects = 0
|
|
26
|
-
|
|
27
|
-
request.post({
|
|
28
|
-
url: server.url + '/foo',
|
|
29
|
-
followAllRedirects: true,
|
|
30
|
-
form: { foo: 'bar' }
|
|
31
|
-
}, function (err, res, body) {
|
|
32
|
-
t.equal(err, null)
|
|
33
|
-
t.equal(body, 'ok')
|
|
34
|
-
t.equal(redirects, 1)
|
|
35
|
-
t.end()
|
|
36
|
-
}).on('redirect', function () {
|
|
37
|
-
redirects++
|
|
38
|
-
})
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
tape('cleanup', function (t) {
|
|
42
|
-
server.close(function () {
|
|
43
|
-
t.end()
|
|
44
|
-
})
|
|
45
|
-
})
|
package/tests/test-follow-all.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
var http = require('http')
|
|
4
|
-
var request = require('../index')
|
|
5
|
-
var tape = require('tape')
|
|
6
|
-
|
|
7
|
-
var server = http.createServer(function (req, res) {
|
|
8
|
-
// redirect everything 3 times, no matter what.
|
|
9
|
-
var c = req.headers.cookie
|
|
10
|
-
|
|
11
|
-
if (!c) {
|
|
12
|
-
c = 0
|
|
13
|
-
} else {
|
|
14
|
-
c = +c.split('=')[1] || 0
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
if (c > 3) {
|
|
18
|
-
res.end('ok')
|
|
19
|
-
return
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
res.setHeader('set-cookie', 'c=' + (c + 1))
|
|
23
|
-
res.setHeader('location', req.url)
|
|
24
|
-
res.statusCode = 302
|
|
25
|
-
res.end('try again')
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
tape('setup', function (t) {
|
|
29
|
-
server.listen(0, function () {
|
|
30
|
-
server.url = 'http://localhost:' + this.address().port
|
|
31
|
-
t.end()
|
|
32
|
-
})
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
tape('followAllRedirects', function (t) {
|
|
36
|
-
var redirects = 0
|
|
37
|
-
|
|
38
|
-
request.post({
|
|
39
|
-
url: server.url + '/foo',
|
|
40
|
-
followAllRedirects: true,
|
|
41
|
-
jar: true,
|
|
42
|
-
form: { foo: 'bar' }
|
|
43
|
-
}, function (err, res, body) {
|
|
44
|
-
t.equal(err, null)
|
|
45
|
-
t.equal(body, 'ok')
|
|
46
|
-
t.equal(redirects, 4)
|
|
47
|
-
t.end()
|
|
48
|
-
}).on('redirect', function () {
|
|
49
|
-
redirects++
|
|
50
|
-
})
|
|
51
|
-
})
|
|
52
|
-
|
|
53
|
-
tape('cleanup', function (t) {
|
|
54
|
-
server.close(function () {
|
|
55
|
-
t.end()
|
|
56
|
-
})
|
|
57
|
-
})
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
var request = require('../index')
|
|
4
|
-
var server = require('./server')
|
|
5
|
-
var tape = require('tape')
|
|
6
|
-
|
|
7
|
-
var s = server.createServer()
|
|
8
|
-
|
|
9
|
-
tape('setup', function (t) {
|
|
10
|
-
s.listen(0, function () {
|
|
11
|
-
t.end()
|
|
12
|
-
})
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
tape('re-emit formData errors', function (t) {
|
|
16
|
-
s.on('/', function (req, res) {
|
|
17
|
-
res.writeHead(400)
|
|
18
|
-
res.end()
|
|
19
|
-
t.fail('The form-data error did not abort the request.')
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
request.post(s.url, function (err, res, body) {
|
|
23
|
-
t.equal(err.message, 'form-data: Arrays are not supported.')
|
|
24
|
-
setTimeout(function () {
|
|
25
|
-
t.end()
|
|
26
|
-
}, 10)
|
|
27
|
-
}).form().append('field', ['value1', 'value2'])
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
tape('omit content-length header if the value is set to NaN', function (t) {
|
|
31
|
-
// returns chunked HTTP response which is streamed to the 2nd HTTP request in the form data
|
|
32
|
-
s.on('/chunky', server.createChunkResponse(
|
|
33
|
-
['some string',
|
|
34
|
-
'some other string'
|
|
35
|
-
]))
|
|
36
|
-
|
|
37
|
-
// accepts form data request
|
|
38
|
-
s.on('/stream', function (req, resp) {
|
|
39
|
-
req.on('data', function (chunk) {
|
|
40
|
-
// consume the request body
|
|
41
|
-
})
|
|
42
|
-
req.on('end', function () {
|
|
43
|
-
resp.writeHead(200)
|
|
44
|
-
resp.end()
|
|
45
|
-
})
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
var sendStreamRequest = function (stream) {
|
|
49
|
-
request.post({
|
|
50
|
-
uri: s.url + '/stream',
|
|
51
|
-
formData: {
|
|
52
|
-
param: stream
|
|
53
|
-
}
|
|
54
|
-
}, function (err, res) {
|
|
55
|
-
t.error(err, 'request failed')
|
|
56
|
-
t.end()
|
|
57
|
-
})
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
request.get({
|
|
61
|
-
uri: s.url + '/chunky'
|
|
62
|
-
}).on('response', function (res) {
|
|
63
|
-
sendStreamRequest(res)
|
|
64
|
-
})
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
// TODO: remove this test after form-data@2.0 starts stringifying null values
|
|
68
|
-
tape('form-data should throw on null value', function (t) {
|
|
69
|
-
t.throws(function () {
|
|
70
|
-
request({
|
|
71
|
-
method: 'POST',
|
|
72
|
-
url: s.url,
|
|
73
|
-
formData: {
|
|
74
|
-
key: null
|
|
75
|
-
}
|
|
76
|
-
})
|
|
77
|
-
}, TypeError)
|
|
78
|
-
t.end()
|
|
79
|
-
})
|
|
80
|
-
|
|
81
|
-
tape('cleanup', function (t) {
|
|
82
|
-
s.close(function () {
|
|
83
|
-
t.end()
|
|
84
|
-
})
|
|
85
|
-
})
|