@wiajs/request 3.0.0 → 3.0.1
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/.github/ISSUE_TEMPLATE.md +56 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +13 -0
- package/.github/stale.yml +19 -0
- package/.swcrc +57 -0
- package/.travis.yml +21 -0
- package/CHANGELOG.md +717 -0
- package/CONTRIBUTING.md +81 -0
- package/biome.json +44 -0
- package/codecov.yml +2 -0
- package/disabled.appveyor.yml +36 -0
- package/dist/request.cjs +1476 -0
- package/dist/request.mjs +1474 -0
- package/examples/README.md +135 -0
- package/gulpfile.js +71 -0
- package/package.json +1 -2
- package/release.sh +45 -0
- package/tests/browser/karma.conf.js +57 -0
- package/tests/browser/ssl/ca.crt +14 -0
- package/tests/browser/ssl/server.crt +14 -0
- package/tests/browser/ssl/server.key +15 -0
- package/tests/browser/start.js +37 -0
- package/tests/browser/test.js +34 -0
- package/tests/fixtures/har.json +158 -0
- package/tests/googledoodle.jpg +0 -0
- package/tests/server.js +142 -0
- package/tests/squid.conf +76 -0
- package/tests/ssl/ca/README.md +8 -0
- package/tests/ssl/ca/ca.cnf +20 -0
- package/tests/ssl/ca/ca.crl +0 -0
- package/tests/ssl/ca/ca.crt +17 -0
- package/tests/ssl/ca/ca.csr +13 -0
- package/tests/ssl/ca/ca.key +18 -0
- package/tests/ssl/ca/ca.srl +1 -0
- package/tests/ssl/ca/client-enc.key +30 -0
- package/tests/ssl/ca/client.cnf +20 -0
- package/tests/ssl/ca/client.crt +20 -0
- package/tests/ssl/ca/client.csr +18 -0
- package/tests/ssl/ca/client.key +27 -0
- package/tests/ssl/ca/gen-all-certs.sh +6 -0
- package/tests/ssl/ca/gen-client.sh +25 -0
- package/tests/ssl/ca/gen-localhost.sh +22 -0
- package/tests/ssl/ca/gen-server.sh +18 -0
- package/tests/ssl/ca/localhost.cnf +20 -0
- package/tests/ssl/ca/localhost.crt +20 -0
- package/tests/ssl/ca/localhost.csr +18 -0
- package/tests/ssl/ca/localhost.js +33 -0
- package/tests/ssl/ca/localhost.key +27 -0
- package/tests/ssl/ca/server.cnf +19 -0
- package/tests/ssl/ca/server.crt +25 -0
- package/tests/ssl/ca/server.csr +29 -0
- package/tests/ssl/ca/server.js +34 -0
- package/tests/ssl/ca/server.key +51 -0
- package/tests/ssl/npm-ca.crt +16 -0
- package/tests/ssl/test.crt +15 -0
- package/tests/ssl/test.key +15 -0
- package/tests/test-agent.js +102 -0
- package/tests/test-agentOptions.js +51 -0
- package/tests/test-api.js +33 -0
- package/tests/test-aws.js +123 -0
- package/tests/test-baseUrl.js +133 -0
- package/tests/test-basic-auth.js +221 -0
- package/tests/test-bearer-auth.js +187 -0
- package/tests/test-body.js +154 -0
- package/tests/test-cookies.js +130 -0
- package/tests/test-defaults.js +340 -0
- package/tests/test-digest-auth.js +232 -0
- package/tests/test-emptyBody.js +56 -0
- package/tests/test-errors.js +108 -0
- package/tests/test-event-forwarding.js +39 -0
- package/tests/test-follow-all-303.js +45 -0
- package/tests/test-follow-all.js +57 -0
- package/tests/test-form-data-error.js +85 -0
- package/tests/test-form-data.js +133 -0
- package/tests/test-form-urlencoded.js +73 -0
- package/tests/test-form.js +101 -0
- package/tests/test-gzip.js +296 -0
- package/tests/test-har.js +175 -0
- package/tests/test-hawk.js +187 -0
- package/tests/test-headers.js +305 -0
- package/tests/test-http-signature.js +110 -0
- package/tests/test-httpModule.js +112 -0
- package/tests/test-https.js +116 -0
- package/tests/test-isUrl.js +120 -0
- package/tests/test-json-request.js +117 -0
- package/tests/test-localAddress.js +49 -0
- package/tests/test-multipart-encoding.js +147 -0
- package/tests/test-multipart.js +129 -0
- package/tests/test-node-debug.js +95 -0
- package/tests/test-oauth.js +721 -0
- package/tests/test-onelineproxy.js +61 -0
- package/tests/test-option-reuse.js +54 -0
- package/tests/test-options-convenience-method.js +52 -0
- package/tests/test-params.js +101 -0
- package/tests/test-piped-redirect.js +55 -0
- package/tests/test-pipes.js +383 -0
- package/tests/test-pool.js +148 -0
- package/tests/test-promise.js +53 -0
- package/tests/test-proxy-connect.js +80 -0
- package/tests/test-proxy.js +304 -0
- package/tests/test-qs.js +135 -0
- package/tests/test-redirect-auth.js +131 -0
- package/tests/test-redirect-complex.js +93 -0
- package/tests/test-redirect.js +449 -0
- package/tests/test-rfc3986.js +106 -0
- package/tests/test-stream.js +36 -0
- package/tests/test-timeout.js +260 -0
- package/tests/test-timing.js +147 -0
- package/tests/test-toJSON.js +45 -0
- package/tests/test-tunnel.js +466 -0
- package/tests/test-unix.js +74 -0
- package/tests/unicycle.jpg +0 -0
- package/request.js +0 -1553
- package/src/ZlibTransform.js +0 -27
- package/src/caseless.js +0 -118
- package/src/index.js +0 -122
- package/src/request.js +0 -967
- package/src/utils.js +0 -274
|
@@ -0,0 +1,466 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
var server = require('./server')
|
|
4
|
+
var tape = require('tape')
|
|
5
|
+
var request = require('../index')
|
|
6
|
+
var https = require('https')
|
|
7
|
+
var net = require('net')
|
|
8
|
+
var fs = require('fs')
|
|
9
|
+
var path = require('path')
|
|
10
|
+
var util = require('util')
|
|
11
|
+
var url = require('url')
|
|
12
|
+
var destroyable = require('server-destroy')
|
|
13
|
+
|
|
14
|
+
var events = []
|
|
15
|
+
var caFile = path.resolve(__dirname, 'ssl/ca/ca.crt')
|
|
16
|
+
var ca = fs.readFileSync(caFile)
|
|
17
|
+
var clientCert = fs.readFileSync(path.resolve(__dirname, 'ssl/ca/client.crt'))
|
|
18
|
+
var clientKey = fs.readFileSync(path.resolve(__dirname, 'ssl/ca/client-enc.key'))
|
|
19
|
+
var clientPassword = 'password'
|
|
20
|
+
var sslOpts = {
|
|
21
|
+
key: path.resolve(__dirname, 'ssl/ca/localhost.key'),
|
|
22
|
+
cert: path.resolve(__dirname, 'ssl/ca/localhost.crt')
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
var mutualSSLOpts = {
|
|
26
|
+
key: path.resolve(__dirname, 'ssl/ca/localhost.key'),
|
|
27
|
+
cert: path.resolve(__dirname, 'ssl/ca/localhost.crt'),
|
|
28
|
+
ca: caFile,
|
|
29
|
+
requestCert: true,
|
|
30
|
+
rejectUnauthorized: true
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// this is needed for 'https over http, tunnel=false' test
|
|
34
|
+
// from https://github.com/coolaj86/node-ssl-root-cas/blob/v1.1.9-beta/ssl-root-cas.js#L4267-L4281
|
|
35
|
+
var httpsOpts = https.globalAgent.options
|
|
36
|
+
httpsOpts.ca = httpsOpts.ca || []
|
|
37
|
+
httpsOpts.ca.push(ca)
|
|
38
|
+
|
|
39
|
+
var s = server.createServer()
|
|
40
|
+
var ss = server.createSSLServer(sslOpts)
|
|
41
|
+
var ss2 = server.createSSLServer(mutualSSLOpts)
|
|
42
|
+
|
|
43
|
+
// XXX when tunneling https over https, connections get left open so the server
|
|
44
|
+
// doesn't want to close normally (and same issue with http server on v0.8.x)
|
|
45
|
+
destroyable(s)
|
|
46
|
+
destroyable(ss)
|
|
47
|
+
destroyable(ss2)
|
|
48
|
+
|
|
49
|
+
function event () {
|
|
50
|
+
events.push(util.format.apply(null, arguments))
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function setListeners (server, type) {
|
|
54
|
+
server.on('/', function (req, res) {
|
|
55
|
+
event('%s response', type)
|
|
56
|
+
res.end(type + ' ok')
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
server.on('request', function (req, res) {
|
|
60
|
+
if (/^https?:/.test(req.url)) {
|
|
61
|
+
// This is a proxy request
|
|
62
|
+
var dest = req.url.split(':')[0]
|
|
63
|
+
// Is it a redirect?
|
|
64
|
+
var match = req.url.match(/\/redirect\/(https?)$/)
|
|
65
|
+
if (match) {
|
|
66
|
+
dest += '->' + match[1]
|
|
67
|
+
}
|
|
68
|
+
event('%s proxy to %s', type, dest)
|
|
69
|
+
request(req.url, { followRedirect: false }).pipe(res)
|
|
70
|
+
}
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
server.on('/redirect/http', function (req, res) {
|
|
74
|
+
event('%s redirect to http', type)
|
|
75
|
+
res.writeHead(301, {
|
|
76
|
+
location: s.url
|
|
77
|
+
})
|
|
78
|
+
res.end()
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
server.on('/redirect/https', function (req, res) {
|
|
82
|
+
event('%s redirect to https', type)
|
|
83
|
+
res.writeHead(301, {
|
|
84
|
+
location: ss.url
|
|
85
|
+
})
|
|
86
|
+
res.end()
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
server.on('connect', function (req, client, head) {
|
|
90
|
+
var u = url.parse(req.url)
|
|
91
|
+
var server = net.connect(u.host, u.port, function () {
|
|
92
|
+
event('%s connect to %s', type, req.url)
|
|
93
|
+
client.write('HTTP/1.1 200 Connection established\r\n\r\n')
|
|
94
|
+
client.pipe(server)
|
|
95
|
+
server.write(head)
|
|
96
|
+
server.pipe(client)
|
|
97
|
+
})
|
|
98
|
+
})
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
setListeners(s, 'http')
|
|
102
|
+
setListeners(ss, 'https')
|
|
103
|
+
setListeners(ss2, 'https')
|
|
104
|
+
|
|
105
|
+
// monkey-patch since you can't set a custom certificate authority for the
|
|
106
|
+
// proxy in tunnel-agent (this is necessary for "* over https" tests)
|
|
107
|
+
var customCaCount = 0
|
|
108
|
+
var httpsRequestOld = https.request
|
|
109
|
+
https.request = function (options) {
|
|
110
|
+
if (customCaCount) {
|
|
111
|
+
options.ca = ca
|
|
112
|
+
customCaCount--
|
|
113
|
+
}
|
|
114
|
+
return httpsRequestOld.apply(this, arguments)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function runTest (name, opts, expected) {
|
|
118
|
+
tape(name, function (t) {
|
|
119
|
+
opts.ca = ca
|
|
120
|
+
if (opts.proxy === ss.url) {
|
|
121
|
+
customCaCount = (opts.url === ss.url ? 2 : 1)
|
|
122
|
+
}
|
|
123
|
+
request(opts, function (err, res, body) {
|
|
124
|
+
event(err ? 'err ' + err.message : res.statusCode + ' ' + body)
|
|
125
|
+
t.deepEqual(events, expected)
|
|
126
|
+
events = []
|
|
127
|
+
t.end()
|
|
128
|
+
})
|
|
129
|
+
})
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function addTests () {
|
|
133
|
+
// HTTP OVER HTTP
|
|
134
|
+
|
|
135
|
+
runTest('http over http, tunnel=true', {
|
|
136
|
+
url: s.url,
|
|
137
|
+
proxy: s.url,
|
|
138
|
+
tunnel: true
|
|
139
|
+
}, [
|
|
140
|
+
'http connect to localhost:' + s.port,
|
|
141
|
+
'http response',
|
|
142
|
+
'200 http ok'
|
|
143
|
+
])
|
|
144
|
+
|
|
145
|
+
runTest('http over http, tunnel=false', {
|
|
146
|
+
url: s.url,
|
|
147
|
+
proxy: s.url,
|
|
148
|
+
tunnel: false
|
|
149
|
+
}, [
|
|
150
|
+
'http proxy to http',
|
|
151
|
+
'http response',
|
|
152
|
+
'200 http ok'
|
|
153
|
+
])
|
|
154
|
+
|
|
155
|
+
runTest('http over http, tunnel=default', {
|
|
156
|
+
url: s.url,
|
|
157
|
+
proxy: s.url
|
|
158
|
+
}, [
|
|
159
|
+
'http proxy to http',
|
|
160
|
+
'http response',
|
|
161
|
+
'200 http ok'
|
|
162
|
+
])
|
|
163
|
+
|
|
164
|
+
// HTTP OVER HTTPS
|
|
165
|
+
|
|
166
|
+
runTest('http over https, tunnel=true', {
|
|
167
|
+
url: s.url,
|
|
168
|
+
proxy: ss.url,
|
|
169
|
+
tunnel: true
|
|
170
|
+
}, [
|
|
171
|
+
'https connect to localhost:' + s.port,
|
|
172
|
+
'http response',
|
|
173
|
+
'200 http ok'
|
|
174
|
+
])
|
|
175
|
+
|
|
176
|
+
runTest('http over https, tunnel=false', {
|
|
177
|
+
url: s.url,
|
|
178
|
+
proxy: ss.url,
|
|
179
|
+
tunnel: false
|
|
180
|
+
}, [
|
|
181
|
+
'https proxy to http',
|
|
182
|
+
'http response',
|
|
183
|
+
'200 http ok'
|
|
184
|
+
])
|
|
185
|
+
|
|
186
|
+
runTest('http over https, tunnel=default', {
|
|
187
|
+
url: s.url,
|
|
188
|
+
proxy: ss.url
|
|
189
|
+
}, [
|
|
190
|
+
'https proxy to http',
|
|
191
|
+
'http response',
|
|
192
|
+
'200 http ok'
|
|
193
|
+
])
|
|
194
|
+
|
|
195
|
+
// HTTPS OVER HTTP
|
|
196
|
+
|
|
197
|
+
runTest('https over http, tunnel=true', {
|
|
198
|
+
url: ss.url,
|
|
199
|
+
proxy: s.url,
|
|
200
|
+
tunnel: true
|
|
201
|
+
}, [
|
|
202
|
+
'http connect to localhost:' + ss.port,
|
|
203
|
+
'https response',
|
|
204
|
+
'200 https ok'
|
|
205
|
+
])
|
|
206
|
+
|
|
207
|
+
runTest('https over http, tunnel=false', {
|
|
208
|
+
url: ss.url,
|
|
209
|
+
proxy: s.url,
|
|
210
|
+
tunnel: false
|
|
211
|
+
}, [
|
|
212
|
+
'http proxy to https',
|
|
213
|
+
'https response',
|
|
214
|
+
'200 https ok'
|
|
215
|
+
])
|
|
216
|
+
|
|
217
|
+
runTest('https over http, tunnel=default', {
|
|
218
|
+
url: ss.url,
|
|
219
|
+
proxy: s.url
|
|
220
|
+
}, [
|
|
221
|
+
'http connect to localhost:' + ss.port,
|
|
222
|
+
'https response',
|
|
223
|
+
'200 https ok'
|
|
224
|
+
])
|
|
225
|
+
|
|
226
|
+
// HTTPS OVER HTTPS
|
|
227
|
+
|
|
228
|
+
runTest('https over https, tunnel=true', {
|
|
229
|
+
url: ss.url,
|
|
230
|
+
proxy: ss.url,
|
|
231
|
+
tunnel: true
|
|
232
|
+
}, [
|
|
233
|
+
'https connect to localhost:' + ss.port,
|
|
234
|
+
'https response',
|
|
235
|
+
'200 https ok'
|
|
236
|
+
])
|
|
237
|
+
|
|
238
|
+
runTest('https over https, tunnel=false', {
|
|
239
|
+
url: ss.url,
|
|
240
|
+
proxy: ss.url,
|
|
241
|
+
tunnel: false,
|
|
242
|
+
pool: false // must disable pooling here or Node.js hangs
|
|
243
|
+
}, [
|
|
244
|
+
'https proxy to https',
|
|
245
|
+
'https response',
|
|
246
|
+
'200 https ok'
|
|
247
|
+
])
|
|
248
|
+
|
|
249
|
+
runTest('https over https, tunnel=default', {
|
|
250
|
+
url: ss.url,
|
|
251
|
+
proxy: ss.url
|
|
252
|
+
}, [
|
|
253
|
+
'https connect to localhost:' + ss.port,
|
|
254
|
+
'https response',
|
|
255
|
+
'200 https ok'
|
|
256
|
+
])
|
|
257
|
+
|
|
258
|
+
// HTTP->HTTP OVER HTTP
|
|
259
|
+
|
|
260
|
+
runTest('http->http over http, tunnel=true', {
|
|
261
|
+
url: s.url + '/redirect/http',
|
|
262
|
+
proxy: s.url,
|
|
263
|
+
tunnel: true
|
|
264
|
+
}, [
|
|
265
|
+
'http connect to localhost:' + s.port,
|
|
266
|
+
'http redirect to http',
|
|
267
|
+
'http connect to localhost:' + s.port,
|
|
268
|
+
'http response',
|
|
269
|
+
'200 http ok'
|
|
270
|
+
])
|
|
271
|
+
|
|
272
|
+
runTest('http->http over http, tunnel=false', {
|
|
273
|
+
url: s.url + '/redirect/http',
|
|
274
|
+
proxy: s.url,
|
|
275
|
+
tunnel: false
|
|
276
|
+
}, [
|
|
277
|
+
'http proxy to http->http',
|
|
278
|
+
'http redirect to http',
|
|
279
|
+
'http proxy to http',
|
|
280
|
+
'http response',
|
|
281
|
+
'200 http ok'
|
|
282
|
+
])
|
|
283
|
+
|
|
284
|
+
runTest('http->http over http, tunnel=default', {
|
|
285
|
+
url: s.url + '/redirect/http',
|
|
286
|
+
proxy: s.url
|
|
287
|
+
}, [
|
|
288
|
+
'http proxy to http->http',
|
|
289
|
+
'http redirect to http',
|
|
290
|
+
'http proxy to http',
|
|
291
|
+
'http response',
|
|
292
|
+
'200 http ok'
|
|
293
|
+
])
|
|
294
|
+
|
|
295
|
+
// HTTP->HTTPS OVER HTTP
|
|
296
|
+
|
|
297
|
+
runTest('http->https over http, tunnel=true', {
|
|
298
|
+
url: s.url + '/redirect/https',
|
|
299
|
+
proxy: s.url,
|
|
300
|
+
tunnel: true
|
|
301
|
+
}, [
|
|
302
|
+
'http connect to localhost:' + s.port,
|
|
303
|
+
'http redirect to https',
|
|
304
|
+
'http connect to localhost:' + ss.port,
|
|
305
|
+
'https response',
|
|
306
|
+
'200 https ok'
|
|
307
|
+
])
|
|
308
|
+
|
|
309
|
+
runTest('http->https over http, tunnel=false', {
|
|
310
|
+
url: s.url + '/redirect/https',
|
|
311
|
+
proxy: s.url,
|
|
312
|
+
tunnel: false
|
|
313
|
+
}, [
|
|
314
|
+
'http proxy to http->https',
|
|
315
|
+
'http redirect to https',
|
|
316
|
+
'http proxy to https',
|
|
317
|
+
'https response',
|
|
318
|
+
'200 https ok'
|
|
319
|
+
])
|
|
320
|
+
|
|
321
|
+
runTest('http->https over http, tunnel=default', {
|
|
322
|
+
url: s.url + '/redirect/https',
|
|
323
|
+
proxy: s.url
|
|
324
|
+
}, [
|
|
325
|
+
'http proxy to http->https',
|
|
326
|
+
'http redirect to https',
|
|
327
|
+
'http connect to localhost:' + ss.port,
|
|
328
|
+
'https response',
|
|
329
|
+
'200 https ok'
|
|
330
|
+
])
|
|
331
|
+
|
|
332
|
+
// HTTPS->HTTP OVER HTTP
|
|
333
|
+
|
|
334
|
+
runTest('https->http over http, tunnel=true', {
|
|
335
|
+
url: ss.url + '/redirect/http',
|
|
336
|
+
proxy: s.url,
|
|
337
|
+
tunnel: true
|
|
338
|
+
}, [
|
|
339
|
+
'http connect to localhost:' + ss.port,
|
|
340
|
+
'https redirect to http',
|
|
341
|
+
'http connect to localhost:' + s.port,
|
|
342
|
+
'http response',
|
|
343
|
+
'200 http ok'
|
|
344
|
+
])
|
|
345
|
+
|
|
346
|
+
runTest('https->http over http, tunnel=false', {
|
|
347
|
+
url: ss.url + '/redirect/http',
|
|
348
|
+
proxy: s.url,
|
|
349
|
+
tunnel: false
|
|
350
|
+
}, [
|
|
351
|
+
'http proxy to https->http',
|
|
352
|
+
'https redirect to http',
|
|
353
|
+
'http proxy to http',
|
|
354
|
+
'http response',
|
|
355
|
+
'200 http ok'
|
|
356
|
+
])
|
|
357
|
+
|
|
358
|
+
runTest('https->http over http, tunnel=default', {
|
|
359
|
+
url: ss.url + '/redirect/http',
|
|
360
|
+
proxy: s.url
|
|
361
|
+
}, [
|
|
362
|
+
'http connect to localhost:' + ss.port,
|
|
363
|
+
'https redirect to http',
|
|
364
|
+
'http proxy to http',
|
|
365
|
+
'http response',
|
|
366
|
+
'200 http ok'
|
|
367
|
+
])
|
|
368
|
+
|
|
369
|
+
// HTTPS->HTTPS OVER HTTP
|
|
370
|
+
|
|
371
|
+
runTest('https->https over http, tunnel=true', {
|
|
372
|
+
url: ss.url + '/redirect/https',
|
|
373
|
+
proxy: s.url,
|
|
374
|
+
tunnel: true
|
|
375
|
+
}, [
|
|
376
|
+
'http connect to localhost:' + ss.port,
|
|
377
|
+
'https redirect to https',
|
|
378
|
+
'http connect to localhost:' + ss.port,
|
|
379
|
+
'https response',
|
|
380
|
+
'200 https ok'
|
|
381
|
+
])
|
|
382
|
+
|
|
383
|
+
runTest('https->https over http, tunnel=false', {
|
|
384
|
+
url: ss.url + '/redirect/https',
|
|
385
|
+
proxy: s.url,
|
|
386
|
+
tunnel: false
|
|
387
|
+
}, [
|
|
388
|
+
'http proxy to https->https',
|
|
389
|
+
'https redirect to https',
|
|
390
|
+
'http proxy to https',
|
|
391
|
+
'https response',
|
|
392
|
+
'200 https ok'
|
|
393
|
+
])
|
|
394
|
+
|
|
395
|
+
runTest('https->https over http, tunnel=default', {
|
|
396
|
+
url: ss.url + '/redirect/https',
|
|
397
|
+
proxy: s.url
|
|
398
|
+
}, [
|
|
399
|
+
'http connect to localhost:' + ss.port,
|
|
400
|
+
'https redirect to https',
|
|
401
|
+
'http connect to localhost:' + ss.port,
|
|
402
|
+
'https response',
|
|
403
|
+
'200 https ok'
|
|
404
|
+
])
|
|
405
|
+
|
|
406
|
+
// MUTUAL HTTPS OVER HTTP
|
|
407
|
+
|
|
408
|
+
runTest('mutual https over http, tunnel=true', {
|
|
409
|
+
url: ss2.url,
|
|
410
|
+
proxy: s.url,
|
|
411
|
+
tunnel: true,
|
|
412
|
+
cert: clientCert,
|
|
413
|
+
key: clientKey,
|
|
414
|
+
passphrase: clientPassword
|
|
415
|
+
}, [
|
|
416
|
+
'http connect to localhost:' + ss2.port,
|
|
417
|
+
'https response',
|
|
418
|
+
'200 https ok'
|
|
419
|
+
])
|
|
420
|
+
|
|
421
|
+
// XXX causes 'Error: socket hang up'
|
|
422
|
+
// runTest('mutual https over http, tunnel=false', {
|
|
423
|
+
// url : ss2.url,
|
|
424
|
+
// proxy : s.url,
|
|
425
|
+
// tunnel : false,
|
|
426
|
+
// cert : clientCert,
|
|
427
|
+
// key : clientKey,
|
|
428
|
+
// passphrase : clientPassword
|
|
429
|
+
// }, [
|
|
430
|
+
// 'http connect to localhost:' + ss2.port,
|
|
431
|
+
// 'https response',
|
|
432
|
+
// '200 https ok'
|
|
433
|
+
// ])
|
|
434
|
+
|
|
435
|
+
runTest('mutual https over http, tunnel=default', {
|
|
436
|
+
url: ss2.url,
|
|
437
|
+
proxy: s.url,
|
|
438
|
+
cert: clientCert,
|
|
439
|
+
key: clientKey,
|
|
440
|
+
passphrase: clientPassword
|
|
441
|
+
}, [
|
|
442
|
+
'http connect to localhost:' + ss2.port,
|
|
443
|
+
'https response',
|
|
444
|
+
'200 https ok'
|
|
445
|
+
])
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
tape('setup', function (t) {
|
|
449
|
+
s.listen(0, function () {
|
|
450
|
+
ss.listen(0, function () {
|
|
451
|
+
ss2.listen(0, 'localhost', function () {
|
|
452
|
+
addTests()
|
|
453
|
+
tape('cleanup', function (t) {
|
|
454
|
+
s.destroy(function () {
|
|
455
|
+
ss.destroy(function () {
|
|
456
|
+
ss2.destroy(function () {
|
|
457
|
+
t.end()
|
|
458
|
+
})
|
|
459
|
+
})
|
|
460
|
+
})
|
|
461
|
+
})
|
|
462
|
+
t.end()
|
|
463
|
+
})
|
|
464
|
+
})
|
|
465
|
+
})
|
|
466
|
+
})
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
var request = require('../index')
|
|
4
|
+
var http = require('http')
|
|
5
|
+
var fs = require('fs')
|
|
6
|
+
var rimraf = require('rimraf')
|
|
7
|
+
var assert = require('assert')
|
|
8
|
+
var tape = require('tape')
|
|
9
|
+
var url = require('url')
|
|
10
|
+
|
|
11
|
+
var rawPath = [null, 'raw', 'path'].join('/')
|
|
12
|
+
var queryPath = [null, 'query', 'path'].join('/')
|
|
13
|
+
var searchString = '?foo=bar'
|
|
14
|
+
var socket = [__dirname, 'tmp-socket'].join('/')
|
|
15
|
+
var expectedBody = 'connected'
|
|
16
|
+
var statusCode = 200
|
|
17
|
+
|
|
18
|
+
rimraf.sync(socket)
|
|
19
|
+
|
|
20
|
+
var s = http.createServer(function (req, res) {
|
|
21
|
+
var incomingUrl = url.parse(req.url)
|
|
22
|
+
switch (incomingUrl.pathname) {
|
|
23
|
+
case rawPath:
|
|
24
|
+
assert.equal(incomingUrl.pathname, rawPath, 'requested path is sent to server')
|
|
25
|
+
break
|
|
26
|
+
|
|
27
|
+
case queryPath:
|
|
28
|
+
assert.equal(incomingUrl.pathname, queryPath, 'requested path is sent to server')
|
|
29
|
+
assert.equal(incomingUrl.search, searchString, 'query string is sent to server')
|
|
30
|
+
break
|
|
31
|
+
|
|
32
|
+
default:
|
|
33
|
+
assert(false, 'A valid path was requested')
|
|
34
|
+
}
|
|
35
|
+
res.statusCode = statusCode
|
|
36
|
+
res.end(expectedBody)
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
tape('setup', function (t) {
|
|
40
|
+
s.listen(socket, function () {
|
|
41
|
+
t.end()
|
|
42
|
+
})
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
tape('unix socket connection', function (t) {
|
|
46
|
+
request('http://unix:' + socket + ':' + rawPath, function (err, res, body) {
|
|
47
|
+
t.equal(err, null, 'no error in connection')
|
|
48
|
+
t.equal(res.statusCode, statusCode, 'got HTTP 200 OK response')
|
|
49
|
+
t.equal(body, expectedBody, 'expected response body is received')
|
|
50
|
+
t.end()
|
|
51
|
+
})
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
tape('unix socket connection with qs', function (t) {
|
|
55
|
+
request({
|
|
56
|
+
uri: 'http://unix:' + socket + ':' + queryPath,
|
|
57
|
+
qs: {
|
|
58
|
+
foo: 'bar'
|
|
59
|
+
}
|
|
60
|
+
}, function (err, res, body) {
|
|
61
|
+
t.equal(err, null, 'no error in connection')
|
|
62
|
+
t.equal(res.statusCode, statusCode, 'got HTTP 200 OK response')
|
|
63
|
+
t.equal(body, expectedBody, 'expected response body is received')
|
|
64
|
+
t.end()
|
|
65
|
+
})
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
tape('cleanup', function (t) {
|
|
69
|
+
s.close(function () {
|
|
70
|
+
fs.unlink(socket, function () {
|
|
71
|
+
t.end()
|
|
72
|
+
})
|
|
73
|
+
})
|
|
74
|
+
})
|
|
Binary file
|