rollup-packages-polyfill-core 0.12.3 → 0.13.0
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/LICENSE.md +26 -0
- package/browser-test/index.js +20 -0
- package/browser-test/main.js +44 -0
- package/package.json +1 -1
- package/polyfills/LICENSE-browserify-fs.txt +472 -0
- package/polyfills/LICENSE-buffer-es6.txt +69 -0
- package/polyfills/LICENSE-crypto-browserify.txt +355 -0
- package/polyfills/LICENSE-process-es6.txt +32 -0
- package/polyfills/__http-lib/capability.js +52 -0
- package/polyfills/__http-lib/request.js +278 -0
- package/polyfills/__http-lib/response.js +185 -0
- package/polyfills/__http-lib/to-arraybuffer.js +30 -0
- package/polyfills/__readable-stream/buffer-list.js +59 -0
- package/polyfills/__readable-stream/duplex.js +45 -0
- package/polyfills/__readable-stream/passthrough.js +15 -0
- package/polyfills/__readable-stream/readable.js +896 -0
- package/polyfills/__readable-stream/transform.js +174 -0
- package/polyfills/__readable-stream/writable.js +483 -0
- package/polyfills/__zlib-lib/LICENSE +21 -0
- package/polyfills/__zlib-lib/adler32.js +31 -0
- package/polyfills/__zlib-lib/binding.js +290 -0
- package/polyfills/__zlib-lib/crc32.js +40 -0
- package/polyfills/__zlib-lib/deflate.js +1862 -0
- package/polyfills/__zlib-lib/inffast.js +325 -0
- package/polyfills/__zlib-lib/inflate.js +1650 -0
- package/polyfills/__zlib-lib/inftrees.js +329 -0
- package/polyfills/__zlib-lib/messages.js +11 -0
- package/polyfills/__zlib-lib/trees.js +1220 -0
- package/polyfills/__zlib-lib/utils.js +73 -0
- package/polyfills/__zlib-lib/zstream.js +28 -0
- package/polyfills/assert.js +488 -0
- package/polyfills/buffer-es6.js +1985 -0
- package/polyfills/console.js +13 -0
- package/polyfills/constants.js +498 -0
- package/polyfills/domain.js +100 -0
- package/polyfills/empty.js +1 -0
- package/polyfills/events.js +481 -0
- package/polyfills/global.js +3 -0
- package/polyfills/http.js +167 -0
- package/polyfills/inherits.js +25 -0
- package/polyfills/os.js +126 -0
- package/polyfills/path.js +234 -0
- package/polyfills/process-es6.js +223 -0
- package/polyfills/punycode.js +475 -0
- package/polyfills/querystring.js +147 -0
- package/polyfills/setimmediate.js +185 -0
- package/polyfills/stream.js +110 -0
- package/polyfills/string-decoder.js +220 -0
- package/polyfills/timers.js +76 -0
- package/polyfills/tty.js +20 -0
- package/polyfills/url.js +785 -0
- package/polyfills/util.js +716 -0
- package/polyfills/vm.js +202 -0
- package/polyfills/zlib.js +635 -0
- package/rollup.config.mjs +18 -0
- package/scripts/build-constants.js +18 -0
- package/scripts/build-polyfills.js +52 -0
- package/scripts/collect-polyfills.js +17 -0
- package/src/index.ts +92 -0
- package/src/modules.ts +61 -0
- package/src/polyfills.ts +1 -0
- package/test/examples/assert.js +12 -0
- package/test/examples/constants.js +7 -0
- package/test/examples/crypto-broken.js +2 -0
- package/test/examples/crypto.js +7 -0
- package/test/examples/domain.js +33 -0
- package/test/examples/events.js +7 -0
- package/test/examples/os.js +7 -0
- package/test/examples/path.js +11 -0
- package/test/examples/stream.js +31 -0
- package/test/examples/string-decoder.js +19 -0
- package/test/examples/url-file-url-to-path.js +11 -0
- package/test/examples/url-format.js +13 -0
- package/test/examples/url-parse.js +14 -0
- package/test/examples/zlib.js +24 -0
- package/test/index.js +77 -0
- package/tsconfig.json +14 -0
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
Name: crypto-browserify
|
|
2
|
+
Version: 3.12.0
|
|
3
|
+
License: MIT
|
|
4
|
+
Private: false
|
|
5
|
+
Description: implementation of crypto for the browser
|
|
6
|
+
Repository: git://github.com/crypto-browserify/crypto-browserify.git
|
|
7
|
+
Homepage: https://github.com/crypto-browserify/crypto-browserify
|
|
8
|
+
Author: Dominic Tarr <dominic.tarr@gmail.com> (dominictarr.com)
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
Name: browserify-sign
|
|
13
|
+
Version: 4.0.4
|
|
14
|
+
License: ISC
|
|
15
|
+
Private: false
|
|
16
|
+
Description: adds node crypto signing for browsers
|
|
17
|
+
Repository: https://github.com/crypto-browserify/browserify-sign.git
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
Name: randombytes
|
|
22
|
+
Version: 2.1.0
|
|
23
|
+
License: MIT
|
|
24
|
+
Private: false
|
|
25
|
+
Description: random bytes from browserify stand alone
|
|
26
|
+
Repository: git@github.com:crypto-browserify/randombytes.git
|
|
27
|
+
Homepage: https://github.com/crypto-browserify/randombytes
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
Name: create-hash
|
|
32
|
+
Version: 1.2.0
|
|
33
|
+
License: MIT
|
|
34
|
+
Private: false
|
|
35
|
+
Description: create hashes for browserify
|
|
36
|
+
Repository: git@github.com:crypto-browserify/createHash.git
|
|
37
|
+
Homepage: https://github.com/crypto-browserify/createHash
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
Name: browserify-cipher
|
|
42
|
+
Version: 1.0.1
|
|
43
|
+
License: MIT
|
|
44
|
+
Private: false
|
|
45
|
+
Description: ciphers for the browser
|
|
46
|
+
Repository: git@github.com:crypto-browserify/browserify-cipher.git
|
|
47
|
+
Author: Calvin Metcalf <calvin.metcalf@gmail.com>
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
Name: pbkdf2
|
|
52
|
+
Version: 3.0.17
|
|
53
|
+
License: MIT
|
|
54
|
+
Private: false
|
|
55
|
+
Description: This library provides the functionality of PBKDF2 with the ability to use any supported hashing algorithm returned from crypto.getHashes()
|
|
56
|
+
Repository: https://github.com/crypto-browserify/pbkdf2.git
|
|
57
|
+
Homepage: https://github.com/crypto-browserify/pbkdf2
|
|
58
|
+
Author: Daniel Cousens
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
Name: diffie-hellman
|
|
63
|
+
Version: 5.0.3
|
|
64
|
+
License: MIT
|
|
65
|
+
Private: false
|
|
66
|
+
Description: pure js diffie-hellman
|
|
67
|
+
Repository: https://github.com/crypto-browserify/diffie-hellman.git
|
|
68
|
+
Homepage: https://github.com/crypto-browserify/diffie-hellman
|
|
69
|
+
Author: Calvin Metcalf
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
Name: create-hmac
|
|
74
|
+
Version: 1.1.7
|
|
75
|
+
License: MIT
|
|
76
|
+
Private: false
|
|
77
|
+
Description: node style hmacs in the browser
|
|
78
|
+
Repository: https://github.com/crypto-browserify/createHmac.git
|
|
79
|
+
Homepage: https://github.com/crypto-browserify/createHmac
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
Name: create-ecdh
|
|
84
|
+
Version: 4.0.3
|
|
85
|
+
License: MIT
|
|
86
|
+
Private: false
|
|
87
|
+
Description: createECDH but browserifiable
|
|
88
|
+
Repository: https://github.com/crypto-browserify/createECDH.git
|
|
89
|
+
Homepage: https://github.com/crypto-browserify/createECDH
|
|
90
|
+
Author: Calvin Metcalf
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
Name: public-encrypt
|
|
95
|
+
Version: 4.0.3
|
|
96
|
+
License: MIT
|
|
97
|
+
Private: false
|
|
98
|
+
Description: browserify version of publicEncrypt & privateDecrypt
|
|
99
|
+
Repository: https://github.com/crypto-browserify/publicEncrypt.git
|
|
100
|
+
Homepage: https://github.com/crypto-browserify/publicEncrypt
|
|
101
|
+
Author: Calvin Metcalf
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
Name: randomfill
|
|
106
|
+
Version: 1.0.4
|
|
107
|
+
License: MIT
|
|
108
|
+
Private: false
|
|
109
|
+
Description: random fill from browserify stand alone
|
|
110
|
+
Repository: https://github.com/crypto-browserify/randomfill.git
|
|
111
|
+
Homepage: https://github.com/crypto-browserify/randomfill
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
Name: browserify-des
|
|
116
|
+
Version: 1.0.2
|
|
117
|
+
License: MIT
|
|
118
|
+
Private: false
|
|
119
|
+
Repository: git+https://github.com/crypto-browserify/browserify-des.git
|
|
120
|
+
Homepage: https://github.com/crypto-browserify/browserify-des#readme
|
|
121
|
+
Author: Calvin Metcalf <calvin.metcalf@gmail.com>
|
|
122
|
+
|
|
123
|
+
---
|
|
124
|
+
|
|
125
|
+
Name: browserify-aes
|
|
126
|
+
Version: 1.2.0
|
|
127
|
+
License: MIT
|
|
128
|
+
Private: false
|
|
129
|
+
Description: aes, for browserify
|
|
130
|
+
Repository: git://github.com/crypto-browserify/browserify-aes.git
|
|
131
|
+
Homepage: https://github.com/crypto-browserify/browserify-aes
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
Name: safe-buffer
|
|
136
|
+
Version: 5.1.2
|
|
137
|
+
License: MIT
|
|
138
|
+
Private: false
|
|
139
|
+
Description: Safer Node.js Buffer API
|
|
140
|
+
Repository: git://github.com/feross/safe-buffer.git
|
|
141
|
+
Homepage: https://github.com/feross/safe-buffer
|
|
142
|
+
Author: Feross Aboukhadijeh <feross@feross.org> (http://feross.org)
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
Name: md5.js
|
|
147
|
+
Version: 1.3.5
|
|
148
|
+
License: MIT
|
|
149
|
+
Private: false
|
|
150
|
+
Description: node style md5 on pure JavaScript
|
|
151
|
+
Repository: https://github.com/crypto-browserify/md5.js.git
|
|
152
|
+
Homepage: https://github.com/crypto-browserify/md5.js
|
|
153
|
+
Author: Kirill Fomichev <fanatid@ya.ru> (https://github.com/fanatid)
|
|
154
|
+
|
|
155
|
+
---
|
|
156
|
+
|
|
157
|
+
Name: inherits
|
|
158
|
+
Version: 2.0.3
|
|
159
|
+
License: ISC
|
|
160
|
+
Private: false
|
|
161
|
+
Description: Browser-friendly inheritance fully compatible with standard node.js inherits()
|
|
162
|
+
Repository: undefined
|
|
163
|
+
|
|
164
|
+
---
|
|
165
|
+
|
|
166
|
+
Name: cipher-base
|
|
167
|
+
Version: 1.0.4
|
|
168
|
+
License: MIT
|
|
169
|
+
Private: false
|
|
170
|
+
Description: abstract base class for crypto-streams
|
|
171
|
+
Repository: git+https://github.com/crypto-browserify/cipher-base.git
|
|
172
|
+
Homepage: https://github.com/crypto-browserify/cipher-base#readme
|
|
173
|
+
Author: Calvin Metcalf <calvin.metcalf@gmail.com>
|
|
174
|
+
|
|
175
|
+
---
|
|
176
|
+
|
|
177
|
+
Name: evp_bytestokey
|
|
178
|
+
Version: 1.0.3
|
|
179
|
+
License: MIT
|
|
180
|
+
Private: false
|
|
181
|
+
Description: The insecure key derivation algorithm from OpenSSL
|
|
182
|
+
Repository: https://github.com/crypto-browserify/EVP_BytesToKey.git
|
|
183
|
+
Homepage: https://github.com/crypto-browserify/EVP_BytesToKey
|
|
184
|
+
Author: Calvin Metcalf <calvin.metcalf@gmail.com>
|
|
185
|
+
Contributors:
|
|
186
|
+
Kirill Fomichev <fanatid@ya.ru>
|
|
187
|
+
|
|
188
|
+
---
|
|
189
|
+
|
|
190
|
+
Name: elliptic
|
|
191
|
+
Version: 6.4.1
|
|
192
|
+
License: MIT
|
|
193
|
+
Private: false
|
|
194
|
+
Description: EC cryptography
|
|
195
|
+
Repository: git@github.com:indutny/elliptic
|
|
196
|
+
Homepage: https://github.com/indutny/elliptic
|
|
197
|
+
Author: Fedor Indutny <fedor@indutny.com>
|
|
198
|
+
|
|
199
|
+
---
|
|
200
|
+
|
|
201
|
+
Name: bn.js
|
|
202
|
+
Version: 4.11.8
|
|
203
|
+
License: MIT
|
|
204
|
+
Private: false
|
|
205
|
+
Description: Big number implementation in pure javascript
|
|
206
|
+
Repository: git@github.com:indutny/bn.js
|
|
207
|
+
Homepage: https://github.com/indutny/bn.js
|
|
208
|
+
Author: Fedor Indutny <fedor@indutny.com>
|
|
209
|
+
|
|
210
|
+
---
|
|
211
|
+
|
|
212
|
+
Name: browserify-rsa
|
|
213
|
+
Version: 4.0.1
|
|
214
|
+
License: MIT
|
|
215
|
+
Private: false
|
|
216
|
+
Description: RSA for browserify
|
|
217
|
+
Repository: git@github.com:crypto-browserify/browserify-rsa.git
|
|
218
|
+
|
|
219
|
+
---
|
|
220
|
+
|
|
221
|
+
Name: parse-asn1
|
|
222
|
+
Version: 5.1.4
|
|
223
|
+
License: ISC
|
|
224
|
+
Private: false
|
|
225
|
+
Description: utility library for parsing asn1 files for use with browserify-sign.
|
|
226
|
+
Repository: git://github.com/crypto-browserify/parse-asn1.git
|
|
227
|
+
|
|
228
|
+
---
|
|
229
|
+
|
|
230
|
+
Name: ripemd160
|
|
231
|
+
Version: 2.0.2
|
|
232
|
+
License: MIT
|
|
233
|
+
Private: false
|
|
234
|
+
Description: Compute ripemd160 of bytes or strings.
|
|
235
|
+
Repository: https://github.com/crypto-browserify/ripemd160
|
|
236
|
+
|
|
237
|
+
---
|
|
238
|
+
|
|
239
|
+
Name: sha.js
|
|
240
|
+
Version: 2.4.11
|
|
241
|
+
License: (MIT AND BSD-3-Clause)
|
|
242
|
+
Private: false
|
|
243
|
+
Description: Streamable SHA hashes in pure javascript
|
|
244
|
+
Repository: git://github.com/crypto-browserify/sha.js.git
|
|
245
|
+
Homepage: https://github.com/crypto-browserify/sha.js
|
|
246
|
+
Author: Dominic Tarr <dominic.tarr@gmail.com> (dominictarr.com)
|
|
247
|
+
|
|
248
|
+
---
|
|
249
|
+
|
|
250
|
+
Name: miller-rabin
|
|
251
|
+
Version: 4.0.1
|
|
252
|
+
License: MIT
|
|
253
|
+
Private: false
|
|
254
|
+
Description: Miller Rabin algorithm for primality test
|
|
255
|
+
Repository: git@github.com:indutny/miller-rabin
|
|
256
|
+
Homepage: https://github.com/indutny/miller-rabin
|
|
257
|
+
Author: Fedor Indutny <fedor@indutny.com>
|
|
258
|
+
|
|
259
|
+
---
|
|
260
|
+
|
|
261
|
+
Name: des.js
|
|
262
|
+
Version: 1.0.0
|
|
263
|
+
License: MIT
|
|
264
|
+
Private: false
|
|
265
|
+
Description: DES implementation
|
|
266
|
+
Repository: git+ssh://git@github.com/indutny/des.js.git
|
|
267
|
+
Homepage: https://github.com/indutny/des.js#readme
|
|
268
|
+
Author: Fedor Indutny <fedor@indutny.com>
|
|
269
|
+
|
|
270
|
+
---
|
|
271
|
+
|
|
272
|
+
Name: hash-base
|
|
273
|
+
Version: 3.0.4
|
|
274
|
+
License: MIT
|
|
275
|
+
Private: false
|
|
276
|
+
Description: abstract base class for hash-streams
|
|
277
|
+
Repository: https://github.com/crypto-browserify/hash-base.git
|
|
278
|
+
Homepage: https://github.com/crypto-browserify/hash-base
|
|
279
|
+
Author: Kirill Fomichev <fanatid@ya.ru> (https://github.com/fanatid)
|
|
280
|
+
|
|
281
|
+
---
|
|
282
|
+
|
|
283
|
+
Name: brorand
|
|
284
|
+
Version: 1.1.0
|
|
285
|
+
License: MIT
|
|
286
|
+
Private: false
|
|
287
|
+
Description: Random number generator for browsers and node.js
|
|
288
|
+
Repository: git@github.com:indutny/brorand
|
|
289
|
+
Homepage: https://github.com/indutny/brorand
|
|
290
|
+
Author: Fedor Indutny <fedor@indutny.com>
|
|
291
|
+
|
|
292
|
+
---
|
|
293
|
+
|
|
294
|
+
Name: buffer-xor
|
|
295
|
+
Version: 1.0.3
|
|
296
|
+
License: MIT
|
|
297
|
+
Private: false
|
|
298
|
+
Description: A simple module for bitwise-xor on buffers
|
|
299
|
+
Repository: https://github.com/crypto-browserify/buffer-xor.git
|
|
300
|
+
Homepage: https://github.com/crypto-browserify/buffer-xor
|
|
301
|
+
Author: Daniel Cousens
|
|
302
|
+
|
|
303
|
+
---
|
|
304
|
+
|
|
305
|
+
Name: asn1.js
|
|
306
|
+
Version: 4.10.1
|
|
307
|
+
License: MIT
|
|
308
|
+
Private: false
|
|
309
|
+
Description: ASN.1 encoder and decoder
|
|
310
|
+
Repository: git@github.com:indutny/asn1.js
|
|
311
|
+
Homepage: https://github.com/indutny/asn1.js
|
|
312
|
+
Author: Fedor Indutny
|
|
313
|
+
|
|
314
|
+
---
|
|
315
|
+
|
|
316
|
+
Name: minimalistic-assert
|
|
317
|
+
Version: 1.0.1
|
|
318
|
+
License: ISC
|
|
319
|
+
Private: false
|
|
320
|
+
Description: minimalistic-assert ===
|
|
321
|
+
Repository: https://github.com/calvinmetcalf/minimalistic-assert.git
|
|
322
|
+
Homepage: https://github.com/calvinmetcalf/minimalistic-assert
|
|
323
|
+
|
|
324
|
+
---
|
|
325
|
+
|
|
326
|
+
Name: hash.js
|
|
327
|
+
Version: 1.1.7
|
|
328
|
+
License: MIT
|
|
329
|
+
Private: false
|
|
330
|
+
Description: Various hash functions that could be run by both browser and node
|
|
331
|
+
Repository: git@github.com:indutny/hash.js
|
|
332
|
+
Homepage: https://github.com/indutny/hash.js
|
|
333
|
+
Author: Fedor Indutny <fedor@indutny.com>
|
|
334
|
+
|
|
335
|
+
---
|
|
336
|
+
|
|
337
|
+
Name: minimalistic-crypto-utils
|
|
338
|
+
Version: 1.0.1
|
|
339
|
+
License: MIT
|
|
340
|
+
Private: false
|
|
341
|
+
Description: Minimalistic tools for JS crypto modules
|
|
342
|
+
Repository: git+ssh://git@github.com/indutny/minimalistic-crypto-utils.git
|
|
343
|
+
Homepage: https://github.com/indutny/minimalistic-crypto-utils#readme
|
|
344
|
+
Author: Fedor Indutny <fedor@indutny.com>
|
|
345
|
+
|
|
346
|
+
---
|
|
347
|
+
|
|
348
|
+
Name: hmac-drbg
|
|
349
|
+
Version: 1.0.1
|
|
350
|
+
License: MIT
|
|
351
|
+
Private: false
|
|
352
|
+
Description: Deterministic random bit generator (hmac)
|
|
353
|
+
Repository: git+ssh://git@github.com/indutny/hmac-drbg.git
|
|
354
|
+
Homepage: https://github.com/indutny/hmac-drbg#readme
|
|
355
|
+
Author: Fedor Indutny <fedor@indutny.com>
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
Name: process-es6
|
|
2
|
+
Version: 0.11.6
|
|
3
|
+
License: MIT
|
|
4
|
+
Private: false
|
|
5
|
+
Description: process information for node.js and browsers, but in es6
|
|
6
|
+
Repository: git://github.com/calvinmetcalf/node-process-es6.git
|
|
7
|
+
Author: Roman Shtylman <shtylman@gmail.com>
|
|
8
|
+
License Copyright:
|
|
9
|
+
===
|
|
10
|
+
|
|
11
|
+
(The MIT License)
|
|
12
|
+
|
|
13
|
+
Copyright (c) 2013 Roman Shtylman <shtylman@gmail.com>
|
|
14
|
+
|
|
15
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
16
|
+
a copy of this software and associated documentation files (the
|
|
17
|
+
'Software'), to deal in the Software without restriction, including
|
|
18
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
19
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
20
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
21
|
+
the following conditions:
|
|
22
|
+
|
|
23
|
+
The above copyright notice and this permission notice shall be
|
|
24
|
+
included in all copies or substantial portions of the Software.
|
|
25
|
+
|
|
26
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
27
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
28
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
29
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
30
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
31
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
32
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export var hasFetch = isFunction(global.fetch) && isFunction(global.ReadableStream)
|
|
2
|
+
|
|
3
|
+
var _blobConstructor;
|
|
4
|
+
export function blobConstructor() {
|
|
5
|
+
if (typeof _blobConstructor !== 'undefined') {
|
|
6
|
+
return _blobConstructor;
|
|
7
|
+
}
|
|
8
|
+
try {
|
|
9
|
+
new global.Blob([new ArrayBuffer(1)])
|
|
10
|
+
_blobConstructor = true
|
|
11
|
+
} catch (e) {
|
|
12
|
+
_blobConstructor = false
|
|
13
|
+
}
|
|
14
|
+
return _blobConstructor
|
|
15
|
+
}
|
|
16
|
+
var xhr;
|
|
17
|
+
|
|
18
|
+
function checkTypeSupport(type) {
|
|
19
|
+
if (!xhr) {
|
|
20
|
+
xhr = new global.XMLHttpRequest()
|
|
21
|
+
// If location.host is empty, e.g. if this page/worker was loaded
|
|
22
|
+
// from a Blob, then use example.com to avoid an error
|
|
23
|
+
xhr.open('GET', global.location.host ? '/' : 'https://example.com')
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
xhr.responseType = type
|
|
27
|
+
return xhr.responseType === type
|
|
28
|
+
} catch (e) {
|
|
29
|
+
return false
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// For some strange reason, Safari 7.0 reports typeof global.ArrayBuffer === 'object'.
|
|
35
|
+
// Safari 7.1 appears to have fixed this bug.
|
|
36
|
+
var haveArrayBuffer = typeof global.ArrayBuffer !== 'undefined'
|
|
37
|
+
var haveSlice = haveArrayBuffer && isFunction(global.ArrayBuffer.prototype.slice)
|
|
38
|
+
|
|
39
|
+
export var arraybuffer = haveArrayBuffer && checkTypeSupport('arraybuffer')
|
|
40
|
+
// These next two tests unavoidably show warnings in Chrome. Since fetch will always
|
|
41
|
+
// be used if it's available, just return false for these to avoid the warnings.
|
|
42
|
+
export var msstream = !hasFetch && haveSlice && checkTypeSupport('ms-stream')
|
|
43
|
+
export var mozchunkedarraybuffer = !hasFetch && haveArrayBuffer &&
|
|
44
|
+
checkTypeSupport('moz-chunked-arraybuffer')
|
|
45
|
+
export var overrideMimeType = isFunction(xhr.overrideMimeType)
|
|
46
|
+
export var vbArray = isFunction(global.VBArray)
|
|
47
|
+
|
|
48
|
+
function isFunction(value) {
|
|
49
|
+
return typeof value === 'function'
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
xhr = null // Help gc
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import * as capability from './capability';
|
|
2
|
+
import {inherits} from 'util';
|
|
3
|
+
import {IncomingMessage, readyStates as rStates} from './response';
|
|
4
|
+
import {Writable} from 'stream';
|
|
5
|
+
import toArrayBuffer from './to-arraybuffer';
|
|
6
|
+
|
|
7
|
+
function decideMode(preferBinary, useFetch) {
|
|
8
|
+
if (capability.hasFetch && useFetch) {
|
|
9
|
+
return 'fetch'
|
|
10
|
+
} else if (capability.mozchunkedarraybuffer) {
|
|
11
|
+
return 'moz-chunked-arraybuffer'
|
|
12
|
+
} else if (capability.msstream) {
|
|
13
|
+
return 'ms-stream'
|
|
14
|
+
} else if (capability.arraybuffer && preferBinary) {
|
|
15
|
+
return 'arraybuffer'
|
|
16
|
+
} else if (capability.vbArray && preferBinary) {
|
|
17
|
+
return 'text:vbarray'
|
|
18
|
+
} else {
|
|
19
|
+
return 'text'
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export default ClientRequest;
|
|
23
|
+
|
|
24
|
+
function ClientRequest(opts) {
|
|
25
|
+
var self = this
|
|
26
|
+
Writable.call(self)
|
|
27
|
+
|
|
28
|
+
self._opts = opts
|
|
29
|
+
self._body = []
|
|
30
|
+
self._headers = {}
|
|
31
|
+
if (opts.auth)
|
|
32
|
+
self.setHeader('Authorization', 'Basic ' + new Buffer(opts.auth).toString('base64'))
|
|
33
|
+
Object.keys(opts.headers).forEach(function(name) {
|
|
34
|
+
self.setHeader(name, opts.headers[name])
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
var preferBinary
|
|
38
|
+
var useFetch = true
|
|
39
|
+
if (opts.mode === 'disable-fetch') {
|
|
40
|
+
// If the use of XHR should be preferred and includes preserving the 'content-type' header
|
|
41
|
+
useFetch = false
|
|
42
|
+
preferBinary = true
|
|
43
|
+
} else if (opts.mode === 'prefer-streaming') {
|
|
44
|
+
// If streaming is a high priority but binary compatibility and
|
|
45
|
+
// the accuracy of the 'content-type' header aren't
|
|
46
|
+
preferBinary = false
|
|
47
|
+
} else if (opts.mode === 'allow-wrong-content-type') {
|
|
48
|
+
// If streaming is more important than preserving the 'content-type' header
|
|
49
|
+
preferBinary = !capability.overrideMimeType
|
|
50
|
+
} else if (!opts.mode || opts.mode === 'default' || opts.mode === 'prefer-fast') {
|
|
51
|
+
// Use binary if text streaming may corrupt data or the content-type header, or for speed
|
|
52
|
+
preferBinary = true
|
|
53
|
+
} else {
|
|
54
|
+
throw new Error('Invalid value for opts.mode')
|
|
55
|
+
}
|
|
56
|
+
self._mode = decideMode(preferBinary, useFetch)
|
|
57
|
+
|
|
58
|
+
self.on('finish', function() {
|
|
59
|
+
self._onFinish()
|
|
60
|
+
})
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
inherits(ClientRequest, Writable)
|
|
64
|
+
// Taken from http://www.w3.org/TR/XMLHttpRequest/#the-setrequestheader%28%29-method
|
|
65
|
+
var unsafeHeaders = [
|
|
66
|
+
'accept-charset',
|
|
67
|
+
'accept-encoding',
|
|
68
|
+
'access-control-request-headers',
|
|
69
|
+
'access-control-request-method',
|
|
70
|
+
'connection',
|
|
71
|
+
'content-length',
|
|
72
|
+
'cookie',
|
|
73
|
+
'cookie2',
|
|
74
|
+
'date',
|
|
75
|
+
'dnt',
|
|
76
|
+
'expect',
|
|
77
|
+
'host',
|
|
78
|
+
'keep-alive',
|
|
79
|
+
'origin',
|
|
80
|
+
'referer',
|
|
81
|
+
'te',
|
|
82
|
+
'trailer',
|
|
83
|
+
'transfer-encoding',
|
|
84
|
+
'upgrade',
|
|
85
|
+
'user-agent',
|
|
86
|
+
'via'
|
|
87
|
+
]
|
|
88
|
+
ClientRequest.prototype.setHeader = function(name, value) {
|
|
89
|
+
var self = this
|
|
90
|
+
var lowerName = name.toLowerCase()
|
|
91
|
+
// This check is not necessary, but it prevents warnings from browsers about setting unsafe
|
|
92
|
+
// headers. To be honest I'm not entirely sure hiding these warnings is a good thing, but
|
|
93
|
+
// http-browserify did it, so I will too.
|
|
94
|
+
if (unsafeHeaders.indexOf(lowerName) !== -1)
|
|
95
|
+
return
|
|
96
|
+
|
|
97
|
+
self._headers[lowerName] = {
|
|
98
|
+
name: name,
|
|
99
|
+
value: value
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
ClientRequest.prototype.getHeader = function(name) {
|
|
104
|
+
var self = this
|
|
105
|
+
return self._headers[name.toLowerCase()].value
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
ClientRequest.prototype.removeHeader = function(name) {
|
|
109
|
+
var self = this
|
|
110
|
+
delete self._headers[name.toLowerCase()]
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
ClientRequest.prototype._onFinish = function() {
|
|
114
|
+
var self = this
|
|
115
|
+
|
|
116
|
+
if (self._destroyed)
|
|
117
|
+
return
|
|
118
|
+
var opts = self._opts
|
|
119
|
+
|
|
120
|
+
var headersObj = self._headers
|
|
121
|
+
var body
|
|
122
|
+
if (opts.method === 'POST' || opts.method === 'PUT' || opts.method === 'PATCH') {
|
|
123
|
+
if (capability.blobConstructor()) {
|
|
124
|
+
body = new global.Blob(self._body.map(function(buffer) {
|
|
125
|
+
return toArrayBuffer(buffer)
|
|
126
|
+
}), {
|
|
127
|
+
type: (headersObj['content-type'] || {}).value || ''
|
|
128
|
+
})
|
|
129
|
+
} else {
|
|
130
|
+
// get utf8 string
|
|
131
|
+
body = Buffer.concat(self._body).toString()
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (self._mode === 'fetch') {
|
|
136
|
+
var headers = Object.keys(headersObj).map(function(name) {
|
|
137
|
+
return [headersObj[name].name, headersObj[name].value]
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
global.fetch(self._opts.url, {
|
|
141
|
+
method: self._opts.method,
|
|
142
|
+
headers: headers,
|
|
143
|
+
body: body,
|
|
144
|
+
mode: 'cors',
|
|
145
|
+
credentials: opts.withCredentials ? 'include' : 'same-origin'
|
|
146
|
+
}).then(function(response) {
|
|
147
|
+
self._fetchResponse = response
|
|
148
|
+
self._connect()
|
|
149
|
+
}, function(reason) {
|
|
150
|
+
self.emit('error', reason)
|
|
151
|
+
})
|
|
152
|
+
} else {
|
|
153
|
+
var xhr = self._xhr = new global.XMLHttpRequest()
|
|
154
|
+
try {
|
|
155
|
+
xhr.open(self._opts.method, self._opts.url, true)
|
|
156
|
+
} catch (err) {
|
|
157
|
+
process.nextTick(function() {
|
|
158
|
+
self.emit('error', err)
|
|
159
|
+
})
|
|
160
|
+
return
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// Can't set responseType on really old browsers
|
|
164
|
+
if ('responseType' in xhr)
|
|
165
|
+
xhr.responseType = self._mode.split(':')[0]
|
|
166
|
+
|
|
167
|
+
if ('withCredentials' in xhr)
|
|
168
|
+
xhr.withCredentials = !!opts.withCredentials
|
|
169
|
+
|
|
170
|
+
if (self._mode === 'text' && 'overrideMimeType' in xhr)
|
|
171
|
+
xhr.overrideMimeType('text/plain; charset=x-user-defined')
|
|
172
|
+
|
|
173
|
+
Object.keys(headersObj).forEach(function(name) {
|
|
174
|
+
xhr.setRequestHeader(headersObj[name].name, headersObj[name].value)
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
self._response = null
|
|
178
|
+
xhr.onreadystatechange = function() {
|
|
179
|
+
switch (xhr.readyState) {
|
|
180
|
+
case rStates.LOADING:
|
|
181
|
+
case rStates.DONE:
|
|
182
|
+
self._onXHRProgress()
|
|
183
|
+
break
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
// Necessary for streaming in Firefox, since xhr.response is ONLY defined
|
|
187
|
+
// in onprogress, not in onreadystatechange with xhr.readyState = 3
|
|
188
|
+
if (self._mode === 'moz-chunked-arraybuffer') {
|
|
189
|
+
xhr.onprogress = function() {
|
|
190
|
+
self._onXHRProgress()
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
xhr.onerror = function() {
|
|
195
|
+
if (self._destroyed)
|
|
196
|
+
return
|
|
197
|
+
self.emit('error', new Error('XHR error'))
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
try {
|
|
201
|
+
xhr.send(body)
|
|
202
|
+
} catch (err) {
|
|
203
|
+
process.nextTick(function() {
|
|
204
|
+
self.emit('error', err)
|
|
205
|
+
})
|
|
206
|
+
return
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Checks if xhr.status is readable and non-zero, indicating no error.
|
|
213
|
+
* Even though the spec says it should be available in readyState 3,
|
|
214
|
+
* accessing it throws an exception in IE8
|
|
215
|
+
*/
|
|
216
|
+
function statusValid(xhr) {
|
|
217
|
+
try {
|
|
218
|
+
var status = xhr.status
|
|
219
|
+
return (status !== null && status !== 0)
|
|
220
|
+
} catch (e) {
|
|
221
|
+
return false
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
ClientRequest.prototype._onXHRProgress = function() {
|
|
226
|
+
var self = this
|
|
227
|
+
|
|
228
|
+
if (!statusValid(self._xhr) || self._destroyed)
|
|
229
|
+
return
|
|
230
|
+
|
|
231
|
+
if (!self._response)
|
|
232
|
+
self._connect()
|
|
233
|
+
|
|
234
|
+
self._response._onXHRProgress()
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
ClientRequest.prototype._connect = function() {
|
|
238
|
+
var self = this
|
|
239
|
+
|
|
240
|
+
if (self._destroyed)
|
|
241
|
+
return
|
|
242
|
+
|
|
243
|
+
self._response = new IncomingMessage(self._xhr, self._fetchResponse, self._mode)
|
|
244
|
+
self.emit('response', self._response)
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
ClientRequest.prototype._write = function(chunk, encoding, cb) {
|
|
248
|
+
var self = this
|
|
249
|
+
|
|
250
|
+
self._body.push(chunk)
|
|
251
|
+
cb()
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
ClientRequest.prototype.abort = ClientRequest.prototype.destroy = function() {
|
|
255
|
+
var self = this
|
|
256
|
+
self._destroyed = true
|
|
257
|
+
if (self._response)
|
|
258
|
+
self._response._destroyed = true
|
|
259
|
+
if (self._xhr)
|
|
260
|
+
self._xhr.abort()
|
|
261
|
+
// Currently, there isn't a way to truly abort a fetch.
|
|
262
|
+
// If you like bikeshedding, see https://github.com/whatwg/fetch/issues/27
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
ClientRequest.prototype.end = function(data, encoding, cb) {
|
|
266
|
+
var self = this
|
|
267
|
+
if (typeof data === 'function') {
|
|
268
|
+
cb = data
|
|
269
|
+
data = undefined
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
Writable.prototype.end.call(self, data, encoding, cb)
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
ClientRequest.prototype.flushHeaders = function() {}
|
|
276
|
+
ClientRequest.prototype.setTimeout = function() {}
|
|
277
|
+
ClientRequest.prototype.setNoDelay = function() {}
|
|
278
|
+
ClientRequest.prototype.setSocketKeepAlive = function() {}
|