@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.
Files changed (117) hide show
  1. package/.github/ISSUE_TEMPLATE.md +56 -0
  2. package/.github/PULL_REQUEST_TEMPLATE.md +13 -0
  3. package/.github/stale.yml +19 -0
  4. package/.swcrc +57 -0
  5. package/.travis.yml +21 -0
  6. package/CHANGELOG.md +717 -0
  7. package/CONTRIBUTING.md +81 -0
  8. package/biome.json +44 -0
  9. package/codecov.yml +2 -0
  10. package/disabled.appveyor.yml +36 -0
  11. package/dist/request.cjs +1476 -0
  12. package/dist/request.mjs +1474 -0
  13. package/examples/README.md +135 -0
  14. package/gulpfile.js +71 -0
  15. package/package.json +1 -2
  16. package/release.sh +45 -0
  17. package/tests/browser/karma.conf.js +57 -0
  18. package/tests/browser/ssl/ca.crt +14 -0
  19. package/tests/browser/ssl/server.crt +14 -0
  20. package/tests/browser/ssl/server.key +15 -0
  21. package/tests/browser/start.js +37 -0
  22. package/tests/browser/test.js +34 -0
  23. package/tests/fixtures/har.json +158 -0
  24. package/tests/googledoodle.jpg +0 -0
  25. package/tests/server.js +142 -0
  26. package/tests/squid.conf +76 -0
  27. package/tests/ssl/ca/README.md +8 -0
  28. package/tests/ssl/ca/ca.cnf +20 -0
  29. package/tests/ssl/ca/ca.crl +0 -0
  30. package/tests/ssl/ca/ca.crt +17 -0
  31. package/tests/ssl/ca/ca.csr +13 -0
  32. package/tests/ssl/ca/ca.key +18 -0
  33. package/tests/ssl/ca/ca.srl +1 -0
  34. package/tests/ssl/ca/client-enc.key +30 -0
  35. package/tests/ssl/ca/client.cnf +20 -0
  36. package/tests/ssl/ca/client.crt +20 -0
  37. package/tests/ssl/ca/client.csr +18 -0
  38. package/tests/ssl/ca/client.key +27 -0
  39. package/tests/ssl/ca/gen-all-certs.sh +6 -0
  40. package/tests/ssl/ca/gen-client.sh +25 -0
  41. package/tests/ssl/ca/gen-localhost.sh +22 -0
  42. package/tests/ssl/ca/gen-server.sh +18 -0
  43. package/tests/ssl/ca/localhost.cnf +20 -0
  44. package/tests/ssl/ca/localhost.crt +20 -0
  45. package/tests/ssl/ca/localhost.csr +18 -0
  46. package/tests/ssl/ca/localhost.js +33 -0
  47. package/tests/ssl/ca/localhost.key +27 -0
  48. package/tests/ssl/ca/server.cnf +19 -0
  49. package/tests/ssl/ca/server.crt +25 -0
  50. package/tests/ssl/ca/server.csr +29 -0
  51. package/tests/ssl/ca/server.js +34 -0
  52. package/tests/ssl/ca/server.key +51 -0
  53. package/tests/ssl/npm-ca.crt +16 -0
  54. package/tests/ssl/test.crt +15 -0
  55. package/tests/ssl/test.key +15 -0
  56. package/tests/test-agent.js +102 -0
  57. package/tests/test-agentOptions.js +51 -0
  58. package/tests/test-api.js +33 -0
  59. package/tests/test-aws.js +123 -0
  60. package/tests/test-baseUrl.js +133 -0
  61. package/tests/test-basic-auth.js +221 -0
  62. package/tests/test-bearer-auth.js +187 -0
  63. package/tests/test-body.js +154 -0
  64. package/tests/test-cookies.js +130 -0
  65. package/tests/test-defaults.js +340 -0
  66. package/tests/test-digest-auth.js +232 -0
  67. package/tests/test-emptyBody.js +56 -0
  68. package/tests/test-errors.js +108 -0
  69. package/tests/test-event-forwarding.js +39 -0
  70. package/tests/test-follow-all-303.js +45 -0
  71. package/tests/test-follow-all.js +57 -0
  72. package/tests/test-form-data-error.js +85 -0
  73. package/tests/test-form-data.js +133 -0
  74. package/tests/test-form-urlencoded.js +73 -0
  75. package/tests/test-form.js +101 -0
  76. package/tests/test-gzip.js +296 -0
  77. package/tests/test-har.js +175 -0
  78. package/tests/test-hawk.js +187 -0
  79. package/tests/test-headers.js +305 -0
  80. package/tests/test-http-signature.js +110 -0
  81. package/tests/test-httpModule.js +112 -0
  82. package/tests/test-https.js +116 -0
  83. package/tests/test-isUrl.js +120 -0
  84. package/tests/test-json-request.js +117 -0
  85. package/tests/test-localAddress.js +49 -0
  86. package/tests/test-multipart-encoding.js +147 -0
  87. package/tests/test-multipart.js +129 -0
  88. package/tests/test-node-debug.js +95 -0
  89. package/tests/test-oauth.js +721 -0
  90. package/tests/test-onelineproxy.js +61 -0
  91. package/tests/test-option-reuse.js +54 -0
  92. package/tests/test-options-convenience-method.js +52 -0
  93. package/tests/test-params.js +101 -0
  94. package/tests/test-piped-redirect.js +55 -0
  95. package/tests/test-pipes.js +383 -0
  96. package/tests/test-pool.js +148 -0
  97. package/tests/test-promise.js +53 -0
  98. package/tests/test-proxy-connect.js +80 -0
  99. package/tests/test-proxy.js +304 -0
  100. package/tests/test-qs.js +135 -0
  101. package/tests/test-redirect-auth.js +131 -0
  102. package/tests/test-redirect-complex.js +93 -0
  103. package/tests/test-redirect.js +449 -0
  104. package/tests/test-rfc3986.js +106 -0
  105. package/tests/test-stream.js +36 -0
  106. package/tests/test-timeout.js +260 -0
  107. package/tests/test-timing.js +147 -0
  108. package/tests/test-toJSON.js +45 -0
  109. package/tests/test-tunnel.js +466 -0
  110. package/tests/test-unix.js +74 -0
  111. package/tests/unicycle.jpg +0 -0
  112. package/request.js +0 -1553
  113. package/src/ZlibTransform.js +0 -27
  114. package/src/caseless.js +0 -118
  115. package/src/index.js +0 -122
  116. package/src/request.js +0 -967
  117. package/src/utils.js +0 -274
package/src/utils.js DELETED
@@ -1,274 +0,0 @@
1
- /**
2
- * utils for request
3
- */
4
- import url from 'node:url'
5
- import assert from 'node:assert'
6
-
7
- const {URL} = url
8
-
9
- // Whether to use the native URL object or the legacy url module
10
- let useNativeURL = false
11
- try {
12
- assert(new URL(''))
13
- } catch (error) {
14
- useNativeURL = error.code === 'ERR_INVALID_URL'
15
- }
16
-
17
- // URL fields to preserve in copy operations
18
- const preservedUrlFields = [
19
- 'auth',
20
- 'host',
21
- 'hostname',
22
- 'href',
23
- 'path',
24
- 'pathname',
25
- 'port',
26
- 'protocol',
27
- 'query',
28
- 'search',
29
- 'hash',
30
- ]
31
-
32
- /**
33
- *
34
- * @param {*} code
35
- * @param {*} message
36
- * @param {*} baseClass
37
- * @returns
38
- */
39
- function createErrorType(code, message, baseClass) {
40
- // Create constructor
41
- function CustomError(properties) {
42
- // istanbul ignore else
43
- if (isFunction(Error.captureStackTrace)) {
44
- Error.captureStackTrace(this, this.constructor)
45
- }
46
- Object.assign(this, properties || {})
47
- this.code = code
48
- this.message = this.cause ? `${message}: ${this.cause.message}` : message
49
- }
50
-
51
- // Attach constructor and set default properties
52
- CustomError.prototype = new (baseClass || Error)()
53
- Object.defineProperties(CustomError.prototype, {
54
- constructor: {
55
- value: CustomError,
56
- enumerable: false,
57
- },
58
- name: {
59
- value: `Error [${code}]`,
60
- enumerable: false,
61
- },
62
- })
63
- return CustomError
64
- }
65
-
66
- const InvalidUrlError = createErrorType('ERR_INVALID_URL', 'Invalid URL', TypeError)
67
-
68
- // @ts-ignore
69
- const typeOfTest = type => thing => typeof thing === type
70
-
71
- /**
72
- * Determine if a value is a String
73
- *
74
- * @param {*} val The value to test
75
- *
76
- * @returns {boolean} True if value is a String, otherwise false
77
- */
78
- const isString = typeOfTest('string')
79
-
80
- /**
81
- * Determine if a value is an Array
82
- *
83
- * @param {Object} val The value to test
84
- *
85
- * @returns {boolean} True if value is an Array, otherwise false
86
- */
87
- const {isArray} = Array
88
-
89
- /**
90
- * Determine if a value is undefined
91
- *
92
- * @param {*} val The value to test
93
- *
94
- * @returns {boolean} True if the value is undefined, otherwise false
95
- */
96
- const isUndefined = typeOfTest('undefined')
97
-
98
- /**
99
- * Determine if a value is a Buffer
100
- *
101
- * @param {*} val The value to test
102
- *
103
- * @returns {boolean} True if value is a Buffer, otherwise false
104
- */
105
- function isBuffer(val) {
106
- return (
107
- val !== null &&
108
- !isUndefined(val) &&
109
- val.constructor !== null &&
110
- !isUndefined(val.constructor) &&
111
- isFunction(val.constructor.isBuffer) &&
112
- val.constructor.isBuffer(val)
113
- )
114
- }
115
-
116
- /**
117
- * Determine if a value is a Function
118
- *
119
- * @param {*} val The value to test
120
- * @returns {boolean} True if value is a Function, otherwise false
121
- */
122
- const isFunction = typeOfTest('function')
123
-
124
- /**
125
- * Determine if a value is a Number
126
- *
127
- * @param {*} val The value to test
128
- *
129
- * @returns {boolean} True if value is a Number, otherwise false
130
- */
131
- const isNumber = typeOfTest('number')
132
-
133
- /**
134
- * Determine if a value is an Object
135
- *
136
- * @param {*} thing The value to test
137
- *
138
- * @returns {boolean} True if value is an Object, otherwise false
139
- */
140
- const isObject = thing => thing !== null && typeof thing === 'object'
141
-
142
- /**
143
- * Determine if a value is a Boolean
144
- *
145
- * @param {*} thing The value to test
146
- * @returns {boolean} True if value is a Boolean, otherwise false
147
- */
148
- const isBoolean = thing => thing === true || thing === false
149
-
150
- const noop = () => {}
151
-
152
- /**
153
- *
154
- * @param {*} value
155
- * @returns
156
- */
157
- function isURL(value) {
158
- return URL && value instanceof URL
159
- }
160
-
161
- function isReadStream(rs) {
162
- return rs.readable && rs.path && rs.mode
163
- }
164
-
165
- /**
166
- *
167
- * @param {*} urlObject
168
- * @param {*} target
169
- * @returns
170
- */
171
- function spreadUrlObject(urlObject, target) {
172
- const spread = target || {}
173
- for (const key of preservedUrlFields) {
174
- spread[key] = urlObject[key]
175
- }
176
-
177
- // Fix IPv6 hostname
178
- if (spread.hostname.startsWith('[')) {
179
- spread.hostname = spread.hostname.slice(1, -1)
180
- }
181
- // Ensure port is a number
182
- if (spread.port !== '') {
183
- spread.port = Number(spread.port)
184
- }
185
- // Concatenate path
186
- spread.path = spread.search ? spread.pathname + spread.search : spread.pathname
187
-
188
- return spread
189
- }
190
-
191
- /**
192
- *
193
- * @param {*} input
194
- * @returns
195
- */
196
- function parseUrl(input) {
197
- let parsed
198
- // istanbul ignore else
199
- if (useNativeURL) {
200
- parsed = new URL(input)
201
- } else {
202
- // Ensure the URL is valid and absolute
203
- parsed = validateUrl(url.parse(input))
204
- if (!isString(parsed.protocol)) {
205
- throw new InvalidUrlError({input})
206
- }
207
- }
208
- return parsed
209
- }
210
-
211
- /**
212
- *
213
- * @param {*} input
214
- * @returns
215
- */
216
- function validateUrl(input) {
217
- if (/^\[/.test(input.hostname) && !/^\[[:0-9a-f]+\]$/i.test(input.hostname)) {
218
- throw new InvalidUrlError({input: input.href || input})
219
- }
220
- if (/^\[/.test(input.host) && !/^\[[:0-9a-f]+\](:\d+)?$/i.test(input.host)) {
221
- throw new InvalidUrlError({input: input.href || input})
222
- }
223
- return input
224
- }
225
-
226
- /**
227
- *
228
- * @param {*} relative
229
- * @param {*} base
230
- * @returns
231
- */
232
- function resolveUrl(relative, base) {
233
- // istanbul ignore next
234
- return useNativeURL ? new URL(relative, base) : parseUrl(url.resolve(base, relative))
235
- }
236
-
237
- /**
238
- *
239
- * @param {string} method
240
- * @param {number} code
241
- * @returns
242
- */
243
- function noBody(method, code) {
244
- return (
245
- method === 'HEAD' ||
246
- // Informational
247
- (code >= 100 && code < 200) ||
248
- // No Content
249
- code === 204 ||
250
- // Not Modified
251
- code === 304
252
- )
253
- }
254
-
255
- export default {
256
- createErrorType,
257
- InvalidUrlError,
258
- isString,
259
- isArray,
260
- isBuffer,
261
- isUndefined,
262
- isNumber,
263
- isBoolean,
264
- isFunction,
265
- isObject,
266
- isURL,
267
- isReadStream,
268
- noop,
269
- parseUrl,
270
- spreadUrlObject,
271
- validateUrl,
272
- resolveUrl,
273
- noBody,
274
- }