@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.
Files changed (108) hide show
  1. package/package.json +2 -2
  2. package/.github/ISSUE_TEMPLATE.md +0 -56
  3. package/.github/PULL_REQUEST_TEMPLATE.md +0 -13
  4. package/.github/stale.yml +0 -19
  5. package/.swcrc +0 -57
  6. package/.travis.yml +0 -21
  7. package/CONTRIBUTING.md +0 -81
  8. package/biome.json +0 -44
  9. package/codecov.yml +0 -2
  10. package/disabled.appveyor.yml +0 -36
  11. package/examples/README.md +0 -135
  12. package/gulpfile.js +0 -71
  13. package/release.sh +0 -45
  14. package/tests/browser/karma.conf.js +0 -57
  15. package/tests/browser/ssl/ca.crt +0 -14
  16. package/tests/browser/ssl/server.crt +0 -14
  17. package/tests/browser/ssl/server.key +0 -15
  18. package/tests/browser/start.js +0 -37
  19. package/tests/browser/test.js +0 -34
  20. package/tests/fixtures/har.json +0 -158
  21. package/tests/googledoodle.jpg +0 -0
  22. package/tests/server.js +0 -142
  23. package/tests/squid.conf +0 -76
  24. package/tests/ssl/ca/README.md +0 -8
  25. package/tests/ssl/ca/ca.cnf +0 -20
  26. package/tests/ssl/ca/ca.crl +0 -0
  27. package/tests/ssl/ca/ca.crt +0 -17
  28. package/tests/ssl/ca/ca.csr +0 -13
  29. package/tests/ssl/ca/ca.key +0 -18
  30. package/tests/ssl/ca/ca.srl +0 -1
  31. package/tests/ssl/ca/client-enc.key +0 -30
  32. package/tests/ssl/ca/client.cnf +0 -20
  33. package/tests/ssl/ca/client.crt +0 -20
  34. package/tests/ssl/ca/client.csr +0 -18
  35. package/tests/ssl/ca/client.key +0 -27
  36. package/tests/ssl/ca/gen-all-certs.sh +0 -6
  37. package/tests/ssl/ca/gen-client.sh +0 -25
  38. package/tests/ssl/ca/gen-localhost.sh +0 -22
  39. package/tests/ssl/ca/gen-server.sh +0 -18
  40. package/tests/ssl/ca/localhost.cnf +0 -20
  41. package/tests/ssl/ca/localhost.crt +0 -20
  42. package/tests/ssl/ca/localhost.csr +0 -18
  43. package/tests/ssl/ca/localhost.js +0 -33
  44. package/tests/ssl/ca/localhost.key +0 -27
  45. package/tests/ssl/ca/server.cnf +0 -19
  46. package/tests/ssl/ca/server.crt +0 -25
  47. package/tests/ssl/ca/server.csr +0 -29
  48. package/tests/ssl/ca/server.js +0 -34
  49. package/tests/ssl/ca/server.key +0 -51
  50. package/tests/ssl/npm-ca.crt +0 -16
  51. package/tests/ssl/test.crt +0 -15
  52. package/tests/ssl/test.key +0 -15
  53. package/tests/test-agent.js +0 -102
  54. package/tests/test-agentOptions.js +0 -51
  55. package/tests/test-api.js +0 -33
  56. package/tests/test-aws.js +0 -123
  57. package/tests/test-baseUrl.js +0 -133
  58. package/tests/test-basic-auth.js +0 -221
  59. package/tests/test-bearer-auth.js +0 -187
  60. package/tests/test-body.js +0 -154
  61. package/tests/test-cookies.js +0 -130
  62. package/tests/test-defaults.js +0 -340
  63. package/tests/test-digest-auth.js +0 -232
  64. package/tests/test-emptyBody.js +0 -56
  65. package/tests/test-errors.js +0 -108
  66. package/tests/test-event-forwarding.js +0 -39
  67. package/tests/test-follow-all-303.js +0 -45
  68. package/tests/test-follow-all.js +0 -57
  69. package/tests/test-form-data-error.js +0 -85
  70. package/tests/test-form-data.js +0 -133
  71. package/tests/test-form-urlencoded.js +0 -73
  72. package/tests/test-form.js +0 -101
  73. package/tests/test-gzip.js +0 -296
  74. package/tests/test-har.js +0 -175
  75. package/tests/test-hawk.js +0 -187
  76. package/tests/test-headers.js +0 -305
  77. package/tests/test-http-signature.js +0 -110
  78. package/tests/test-httpModule.js +0 -112
  79. package/tests/test-https.js +0 -116
  80. package/tests/test-isUrl.js +0 -120
  81. package/tests/test-json-request.js +0 -117
  82. package/tests/test-localAddress.js +0 -49
  83. package/tests/test-multipart-encoding.js +0 -147
  84. package/tests/test-multipart.js +0 -129
  85. package/tests/test-node-debug.js +0 -95
  86. package/tests/test-oauth.js +0 -721
  87. package/tests/test-onelineproxy.js +0 -61
  88. package/tests/test-option-reuse.js +0 -54
  89. package/tests/test-options-convenience-method.js +0 -52
  90. package/tests/test-params.js +0 -101
  91. package/tests/test-piped-redirect.js +0 -55
  92. package/tests/test-pipes.js +0 -383
  93. package/tests/test-pool.js +0 -148
  94. package/tests/test-promise.js +0 -53
  95. package/tests/test-proxy-connect.js +0 -80
  96. package/tests/test-proxy.js +0 -304
  97. package/tests/test-qs.js +0 -135
  98. package/tests/test-redirect-auth.js +0 -131
  99. package/tests/test-redirect-complex.js +0 -93
  100. package/tests/test-redirect.js +0 -449
  101. package/tests/test-rfc3986.js +0 -106
  102. package/tests/test-stream.js +0 -36
  103. package/tests/test-timeout.js +0 -260
  104. package/tests/test-timing.js +0 -147
  105. package/tests/test-toJSON.js +0 -45
  106. package/tests/test-tunnel.js +0 -466
  107. package/tests/test-unix.js +0 -74
  108. package/tests/unicycle.jpg +0 -0
@@ -1,147 +0,0 @@
1
- 'use strict'
2
-
3
- var http = require('http')
4
- var path = require('path')
5
- var request = require('../index')
6
- var fs = require('fs')
7
- var tape = require('tape')
8
-
9
- var localFile = path.join(__dirname, 'unicycle.jpg')
10
- var cases = {
11
- // based on body type
12
- '+array -stream': {
13
- options: {
14
- multipart: [{name: 'field', body: 'value'}]
15
- },
16
- expected: {chunked: false}
17
- },
18
- '+array +stream': {
19
- options: {
20
- multipart: [{name: 'file', body: null}]
21
- },
22
- expected: {chunked: true}
23
- },
24
- // encoding overrides body value
25
- '+array +encoding': {
26
- options: {
27
- headers: {'transfer-encoding': 'chunked'},
28
- multipart: [{name: 'field', body: 'value'}]
29
- },
30
- expected: {chunked: true}
31
- },
32
-
33
- // based on body type
34
- '+object -stream': {
35
- options: {
36
- multipart: {data: [{name: 'field', body: 'value'}]}
37
- },
38
- expected: {chunked: false}
39
- },
40
- '+object +stream': {
41
- options: {
42
- multipart: {data: [{name: 'file', body: null}]}
43
- },
44
- expected: {chunked: true}
45
- },
46
- // encoding overrides body value
47
- '+object +encoding': {
48
- options: {
49
- headers: {'transfer-encoding': 'chunked'},
50
- multipart: {data: [{name: 'field', body: 'value'}]}
51
- },
52
- expected: {chunked: true}
53
- },
54
-
55
- // based on body type
56
- '+object -chunked -stream': {
57
- options: {
58
- multipart: {chunked: false, data: [{name: 'field', body: 'value'}]}
59
- },
60
- expected: {chunked: false}
61
- },
62
- '+object -chunked +stream': {
63
- options: {
64
- multipart: {chunked: false, data: [{name: 'file', body: null}]}
65
- },
66
- expected: {chunked: true}
67
- },
68
- // chunked overrides body value
69
- '+object +chunked -stream': {
70
- options: {
71
- multipart: {chunked: true, data: [{name: 'field', body: 'value'}]}
72
- },
73
- expected: {chunked: true}
74
- },
75
- // encoding overrides chunked
76
- '+object +encoding -chunked': {
77
- options: {
78
- headers: {'transfer-encoding': 'chunked'},
79
- multipart: {chunked: false, data: [{name: 'field', body: 'value'}]}
80
- },
81
- expected: {chunked: true}
82
- }
83
- }
84
-
85
- function runTest (t, test) {
86
- var server = http.createServer(function (req, res) {
87
- t.ok(req.headers['content-type'].match(/^multipart\/related; boundary=[^\s;]+$/))
88
-
89
- if (test.expected.chunked) {
90
- t.ok(req.headers['transfer-encoding'] === 'chunked')
91
- t.notOk(req.headers['content-length'])
92
- } else {
93
- t.ok(req.headers['content-length'])
94
- t.notOk(req.headers['transfer-encoding'])
95
- }
96
-
97
- // temp workaround
98
- var data = ''
99
- req.setEncoding('utf8')
100
-
101
- req.on('data', function (d) {
102
- data += d
103
- })
104
-
105
- req.on('end', function () {
106
- // check for the fields traces
107
- if (test.expected.chunked && data.indexOf('name: file') !== -1) {
108
- // file
109
- t.ok(data.indexOf('name: file') !== -1)
110
- // check for unicycle.jpg traces
111
- t.ok(data.indexOf('2005:06:21 01:44:12') !== -1)
112
- } else {
113
- // field
114
- t.ok(data.indexOf('name: field') !== -1)
115
- var parts = test.options.multipart.data || test.options.multipart
116
- t.ok(data.indexOf(parts[0].body) !== -1)
117
- }
118
-
119
- res.writeHead(200)
120
- res.end()
121
- })
122
- })
123
-
124
- server.listen(0, function () {
125
- var url = 'http://localhost:' + this.address().port
126
- // @NOTE: multipartData properties must be set here
127
- // so that file read stream does not leak in node v0.8
128
- var parts = test.options.multipart.data || test.options.multipart
129
- if (parts[0].name === 'file') {
130
- parts[0].body = fs.createReadStream(localFile)
131
- }
132
-
133
- request.post(url, test.options, function (err, res, body) {
134
- t.equal(err, null)
135
- t.equal(res.statusCode, 200)
136
- server.close(function () {
137
- t.end()
138
- })
139
- })
140
- })
141
- }
142
-
143
- Object.keys(cases).forEach(function (name) {
144
- tape('multipart-encoding ' + name, function (t) {
145
- runTest(t, cases[name])
146
- })
147
- })
@@ -1,129 +0,0 @@
1
- 'use strict'
2
-
3
- var http = require('http')
4
- var path = require('path')
5
- var request = require('../index')
6
- var fs = require('fs')
7
- var tape = require('tape')
8
-
9
- function runTest (t, a) {
10
- var remoteFile = path.join(__dirname, 'googledoodle.jpg')
11
- var localFile = path.join(__dirname, 'unicycle.jpg')
12
- var multipartData = []
13
-
14
- var server = http.createServer(function (req, res) {
15
- if (req.url === '/file') {
16
- res.writeHead(200, {'content-type': 'image/jpg'})
17
- res.end(fs.readFileSync(remoteFile), 'binary')
18
- return
19
- }
20
-
21
- if (a.header) {
22
- if (a.header.indexOf('mixed') !== -1) {
23
- t.ok(req.headers['content-type'].match(/^multipart\/mixed; boundary=[^\s;]+$/))
24
- } else {
25
- t.ok(req.headers['content-type']
26
- .match(/^multipart\/related; boundary=XXX; type=text\/xml; start="<root>"$/))
27
- }
28
- } else {
29
- t.ok(req.headers['content-type'].match(/^multipart\/related; boundary=[^\s;]+$/))
30
- }
31
-
32
- // temp workaround
33
- var data = ''
34
- req.setEncoding('utf8')
35
-
36
- req.on('data', function (d) {
37
- data += d
38
- })
39
-
40
- req.on('end', function () {
41
- // check for the fields traces
42
-
43
- // my_field
44
- t.ok(data.indexOf('name: my_field') !== -1)
45
- t.ok(data.indexOf(multipartData[0].body) !== -1)
46
-
47
- // my_number
48
- t.ok(data.indexOf('name: my_number') !== -1)
49
- t.ok(data.indexOf(multipartData[1].body) !== -1)
50
-
51
- // my_buffer
52
- t.ok(data.indexOf('name: my_buffer') !== -1)
53
- t.ok(data.indexOf(multipartData[2].body) !== -1)
54
-
55
- // my_file
56
- t.ok(data.indexOf('name: my_file') !== -1)
57
- // check for unicycle.jpg traces
58
- t.ok(data.indexOf('2005:06:21 01:44:12') !== -1)
59
-
60
- // remote_file
61
- t.ok(data.indexOf('name: remote_file') !== -1)
62
- // check for http://localhost:nnnn/file traces
63
- t.ok(data.indexOf('Photoshop ICC') !== -1)
64
-
65
- if (a.header && a.header.indexOf('boundary=XXX') !== -1) {
66
- t.ok(data.indexOf('--XXX') !== -1)
67
- }
68
-
69
- res.writeHead(200)
70
- res.end(a.json ? JSON.stringify({status: 'done'}) : 'done')
71
- })
72
- })
73
-
74
- server.listen(0, function () {
75
- var url = 'http://localhost:' + this.address().port
76
- // @NOTE: multipartData properties must be set here so that my_file read stream does not leak in node v0.8
77
- multipartData = [
78
- {name: 'my_field', body: 'my_value'},
79
- {name: 'my_number', body: 1000},
80
- {name: 'my_buffer', body: Buffer.from([1, 2, 3])},
81
- {name: 'my_file', body: fs.createReadStream(localFile)},
82
- {name: 'remote_file', body: request(url + '/file')}
83
- ]
84
-
85
- var reqOptions = {
86
- url: url + '/upload',
87
- multipart: multipartData
88
- }
89
- if (a.header) {
90
- reqOptions.headers = {
91
- 'content-type': a.header
92
- }
93
- }
94
- if (a.json) {
95
- reqOptions.json = true
96
- }
97
- request[a.method](reqOptions, function (err, res, body) {
98
- t.equal(err, null)
99
- t.equal(res.statusCode, 200)
100
- t.deepEqual(body, a.json ? {status: 'done'} : 'done')
101
- server.close(function () {
102
- t.end()
103
- })
104
- })
105
- })
106
- }
107
-
108
- var testHeaders = [
109
- null,
110
- 'multipart/mixed',
111
- 'multipart/related; boundary=XXX; type=text/xml; start="<root>"'
112
- ]
113
-
114
- var methods = ['post', 'get']
115
- methods.forEach(function (method) {
116
- testHeaders.forEach(function (header) {
117
- [true, false].forEach(function (json) {
118
- var name = [
119
- 'multipart-related', method.toUpperCase(),
120
- (header || 'default'),
121
- (json ? '+' : '-') + 'json'
122
- ].join(' ')
123
-
124
- tape(name, function (t) {
125
- runTest(t, {method: method, header: header, json: json})
126
- })
127
- })
128
- })
129
- })
@@ -1,95 +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, res) {
8
- res.statusCode = 200
9
- res.end('')
10
- })
11
-
12
- var stderr = []
13
- var prevStderrLen = 0
14
-
15
- tape('setup', function (t) {
16
- process.stderr._oldWrite = process.stderr.write
17
- process.stderr.write = function (string, encoding, fd) {
18
- stderr.push(string)
19
- }
20
-
21
- s.listen(0, function () {
22
- s.url = 'http://localhost:' + this.address().port
23
- t.end()
24
- })
25
- })
26
-
27
- tape('a simple request should not fail with debugging enabled', function (t) {
28
- request.debug = true
29
- t.equal(request.Request.debug, true, 'request.debug sets request.Request.debug')
30
- t.equal(request.debug, true, 'request.debug gets request.Request.debug')
31
- stderr = []
32
-
33
- request(s.url, function (err, res, body) {
34
- t.ifError(err, 'the request did not fail')
35
- t.ok(res, 'the request did not fail')
36
-
37
- t.ok(stderr.length, 'stderr has some messages')
38
- var url = s.url.replace(/\//g, '\\/')
39
- var patterns = [
40
- /^REQUEST { uri: /,
41
- new RegExp('^REQUEST make request ' + url + '/\n$'),
42
- /^REQUEST onRequestResponse /,
43
- /^REQUEST finish init /,
44
- /^REQUEST response end /,
45
- /^REQUEST end event /,
46
- /^REQUEST emitting complete /
47
- ]
48
- patterns.forEach(function (pattern) {
49
- var found = false
50
- stderr.forEach(function (msg) {
51
- if (pattern.test(msg)) {
52
- found = true
53
- }
54
- })
55
- t.ok(found, 'a log message matches ' + pattern)
56
- })
57
- prevStderrLen = stderr.length
58
- t.end()
59
- })
60
- })
61
-
62
- tape('there should be no further lookups on process.env', function (t) {
63
- process.env.NODE_DEBUG = ''
64
- stderr = []
65
-
66
- request(s.url, function (err, res, body) {
67
- t.ifError(err, 'the request did not fail')
68
- t.ok(res, 'the request did not fail')
69
- t.equal(stderr.length, prevStderrLen, 'env.NODE_DEBUG is not retested')
70
- t.end()
71
- })
72
- })
73
-
74
- tape('it should be possible to disable debugging at runtime', function (t) {
75
- request.debug = false
76
- t.equal(request.Request.debug, false, 'request.debug sets request.Request.debug')
77
- t.equal(request.debug, false, 'request.debug gets request.Request.debug')
78
- stderr = []
79
-
80
- request(s.url, function (err, res, body) {
81
- t.ifError(err, 'the request did not fail')
82
- t.ok(res, 'the request did not fail')
83
- t.equal(stderr.length, 0, 'debugging can be disabled')
84
- t.end()
85
- })
86
- })
87
-
88
- tape('cleanup', function (t) {
89
- process.stderr.write = process.stderr._oldWrite
90
- delete process.stderr._oldWrite
91
-
92
- s.close(function () {
93
- t.end()
94
- })
95
- })