diff options
Diffstat (limited to 'deps/npm/node_modules/make-fetch-happen')
21 files changed, 993 insertions, 1559 deletions
diff --git a/deps/npm/node_modules/make-fetch-happen/CHANGELOG.md b/deps/npm/node_modules/make-fetch-happen/CHANGELOG.md deleted file mode 100644 index 324dfc1058..0000000000 --- a/deps/npm/node_modules/make-fetch-happen/CHANGELOG.md +++ /dev/null @@ -1,654 +0,0 @@ -# Changelog - -All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. - -### [8.0.3](https://github.com/npm/make-fetch-happen/compare/v8.0.2...v8.0.3) (2020-03-03) - - -### Bug Fixes - -* remoteFetch takes instance of fetch.Headers ([6e0de7b](https://github.com/npm/make-fetch-happen/commit/6e0de7b10b8597eaff69fea06a266914766cf5ab)), closes [#22](https://github.com/npm/make-fetch-happen/issues/22) - -### [8.0.1](https://github.com/npm/make-fetch-happen/compare/v8.0.0...v8.0.1) (2020-02-18) - -## [8.0.0](https://github.com/npm/make-fetch-happen/compare/v7.1.1...v8.0.0) (2020-02-18) - - -### ⚠ BREAKING CHANGES - -* this module now only supports taking a plain JavaScript -options object, not a figgy pudding config object. - -* update cacache and ssri ([09e4f97](https://github.com/npm/make-fetch-happen/commit/09e4f9794a6f134d3f1d8e65eb9bd940e38e5bfc)) - -### [7.1.1](https://github.com/npm/make-fetch-happen/compare/v7.1.0...v7.1.1) (2020-01-28) - -## [7.1.0](https://github.com/npm/make-fetch-happen/compare/v7.0.0...v7.1.0) (2019-12-17) - - -### Features - -* use globalAgent when in lambda ([bd9409d](https://github.com/npm/make-fetch-happen/commit/bd9409da246a979b665ebd23967ec01dd928ce47)), closes [#4](https://github.com/npm/make-fetch-happen/issues/4) - -## [7.0.0](https://github.com/npm/make-fetch-happen/compare/v6.1.0...v7.0.0) (2019-12-17) - - -### ⚠ BREAKING CHANGES - -* drops support for node v8, since it's EOL as of 2020-01-01 - -### Features - -* **github:** added github actions with coveralls integration ([1913c1b](https://github.com/npm/make-fetch-happen/commit/1913c1b51aaac6044b4dab65b3d19ec943a35f39)) -* updated fetch module; linting mostly; based on testing ([063f28e](https://github.com/npm/make-fetch-happen/commit/063f28ea1ac23f7e9d9d79e15949ca82b634ce97)) -* **utils:** fixed configure-options based on testing ([9dd4f6f](https://github.com/npm/make-fetch-happen/commit/9dd4f6f108442dc247de44e1ddc0341edcb84c9b)) -* fixed test dep requires; added mockRequire function to mock tests properly ([95de7a1](https://github.com/npm/make-fetch-happen/commit/95de7a171110907e30f41f489e4be983cd8184a5)) -* refactored functions into utilities ([74620dd](https://github.com/npm/make-fetch-happen/commit/74620dd7c2262ac46d9b4f6ac2dc9ff45a4f19ee)) -* updated dev deps; update tap; updated standard ([dce6eec](https://github.com/npm/make-fetch-happen/commit/dce6eece130fb20164a62eeabc6090811d8f14a4)) -* updated fetch tests; linting, logic, added tests ([d50aeaf](https://github.com/npm/make-fetch-happen/commit/d50aeafebeb5d8f7118d7f6660208f40ac487804)) - - -### Bug Fixes - -* format cache key with new URL object shape ([21cb6cc](https://github.com/npm/make-fetch-happen/commit/21cb6cc968aabff8b5c5c02e3666fb093fd6578c)) -* polish out an unnecessary URL object creation ([67a01d4](https://github.com/npm/make-fetch-happen/commit/67a01d46b2cacbadc22f49604ee524526cee3912)), closes [#14](https://github.com/npm/make-fetch-happen/issues/14) -* support user without password in proxy auth ([e24bbf9](https://github.com/npm/make-fetch-happen/commit/e24bbf935bc8a2c49070cdb2518e5ee290143191)) -* updated 'files' property in package file ([945e40c](https://github.com/npm/make-fetch-happen/commit/945e40c7fbb59333e0c632c490683e4babc68dc1)) -* Use WhatWG URL objects over deprecated legacy url API ([28aca97](https://github.com/npm/make-fetch-happen/commit/28aca97dfb63ca003ebf62d1b961771cfbb2481d)) - - -* drop node 8 ([9fa7944](https://github.com/npm/make-fetch-happen/commit/9fa7944cbc603f3a194dfb440f519a7d5265653e)) - -## [6.1.0](https://github.com/npm/make-fetch-happen/compare/v6.0.1...v6.1.0) (2019-11-14) - - -### Bug Fixes - -* **streams:** change condition/logic of fitInMemory used when defining memoize ([c173723](https://github.com/npm/make-fetch-happen/commit/c173723)) - -### [6.0.1](https://github.com/npm/make-fetch-happen/compare/v6.0.0...v6.0.1) (2019-10-23) - -<a name="6.0.0"></a> -# [6.0.0](https://github.com/npm/make-fetch-happen/compare/v5.0.0...v6.0.0) (2019-10-01) - -### Bug Fixes - -* preserve rfc7234 5.5.4 warnings ([001b91e](https://github.com/npm/make-fetch-happen/commit/001b91e)) -* properly detect thrown HTTP "error" objects ([d7cbeb4](https://github.com/npm/make-fetch-happen/commit/d7cbeb4)) -* safely create synthetic response body for 304 ([bc70f88](https://github.com/npm/make-fetch-happen/commit/bc70f88)) - -### Features - -* **promises:** refactor bluebird with native promises ([7482d54](https://github.com/npm/make-fetch-happen/commit/7482d54)) - -### BREAKING CHANGES - -* **streams:** refactor node streams with minipass ([1d7f5a3](https://github.com/npm/make-fetch-happen/commit/1d7f5a3)) - -<a name="5.0.0"></a> -# [5.0.0](https://github.com/npm/make-fetch-happen/compare/v4.0.2...v5.0.0) (2019-07-15) - - -### Features - -* cacache@12, no need for uid/gid opts ([fdb956f](https://github.com/npm/make-fetch-happen/commit/fdb956f)) - - -### BREAKING CHANGES - -* cache uid and gid are inferred from the cache folder itself, -not passed in as options. - - - -<a name="4.0.2"></a> -## [4.0.2](https://github.com/npm/make-fetch-happen/compare/v4.0.1...v4.0.2) (2019-07-02) - - - -<a name="4.0.1"></a> -## [4.0.1](https://github.com/npm/make-fetch-happen/compare/v4.0.0...v4.0.1) (2018-04-12) - - -### Bug Fixes - -* **integrity:** use new sri.match() for verification ([4f371a0](https://github.com/npm/make-fetch-happen/commit/4f371a0)) - - - -<a name="4.0.0"></a> -# [4.0.0](https://github.com/npm/make-fetch-happen/compare/v3.0.0...v4.0.0) (2018-04-09) - - -### meta - -* drop node@4, add node@9 ([7b0191a](https://github.com/npm/make-fetch-happen/commit/7b0191a)) - - -### BREAKING CHANGES - -* node@4 is no longer supported - - - -<a name="3.0.0"></a> -# [3.0.0](https://github.com/npm/make-fetch-happen/compare/v2.6.0...v3.0.0) (2018-03-12) - - -### Bug Fixes - -* **license:** switch to ISC ([#49](https://github.com/npm/make-fetch-happen/issues/49)) ([bf90c6d](https://github.com/npm/make-fetch-happen/commit/bf90c6d)) -* **standard:** standard@11 update ([ff0aa70](https://github.com/npm/make-fetch-happen/commit/ff0aa70)) - - -### BREAKING CHANGES - -* **license:** license changed from CC0 to ISC. - - - -<a name="2.6.0"></a> -# [2.6.0](https://github.com/npm/make-fetch-happen/compare/v2.5.0...v2.6.0) (2017-11-14) - - -### Bug Fixes - -* **integrity:** disable node-fetch compress when checking integrity (#42) ([a7cc74c](https://github.com/npm/make-fetch-happen/commit/a7cc74c)) - - -### Features - -* **onretry:** Add `options.onRetry` (#48) ([f90ccff](https://github.com/npm/make-fetch-happen/commit/f90ccff)) - - - -<a name="2.5.0"></a> -# [2.5.0](https://github.com/npm/make-fetch-happen/compare/v2.4.13...v2.5.0) (2017-08-24) - - -### Bug Fixes - -* **agent:** support timeout durations greater than 30 seconds ([04875ae](https://github.com/npm/make-fetch-happen/commit/04875ae)), closes [#35](https://github.com/npm/make-fetch-happen/issues/35) - - -### Features - -* **cache:** export cache deletion functionality (#40) ([3da4250](https://github.com/npm/make-fetch-happen/commit/3da4250)) - - - -<a name="2.4.13"></a> -## [2.4.13](https://github.com/npm/make-fetch-happen/compare/v2.4.12...v2.4.13) (2017-06-29) - - -### Bug Fixes - -* **deps:** bump other deps for bugfixes ([eab8297](https://github.com/npm/make-fetch-happen/commit/eab8297)) -* **proxy:** bump proxy deps with bugfixes (#32) ([632f860](https://github.com/npm/make-fetch-happen/commit/632f860)), closes [#32](https://github.com/npm/make-fetch-happen/issues/32) - - - -<a name="2.4.12"></a> -## [2.4.12](https://github.com/npm/make-fetch-happen/compare/v2.4.11...v2.4.12) (2017-06-06) - - -### Bug Fixes - -* **cache:** encode x-local-cache-etc headers to be header-safe ([dc9fb1b](https://github.com/npm/make-fetch-happen/commit/dc9fb1b)) - - - -<a name="2.4.11"></a> -## [2.4.11](https://github.com/npm/make-fetch-happen/compare/v2.4.10...v2.4.11) (2017-06-05) - - -### Bug Fixes - -* **deps:** bump deps with ssri fix ([bef1994](https://github.com/npm/make-fetch-happen/commit/bef1994)) - - - -<a name="2.4.10"></a> -## [2.4.10](https://github.com/npm/make-fetch-happen/compare/v2.4.9...v2.4.10) (2017-05-31) - - -### Bug Fixes - -* **deps:** bump dep versions with bugfixes ([0af4003](https://github.com/npm/make-fetch-happen/commit/0af4003)) -* **proxy:** use auth parameter for proxy authentication (#30) ([c687306](https://github.com/npm/make-fetch-happen/commit/c687306)) - - - -<a name="2.4.9"></a> -## [2.4.9](https://github.com/npm/make-fetch-happen/compare/v2.4.8...v2.4.9) (2017-05-25) - - -### Bug Fixes - -* **cache:** use the passed-in promise for resolving cache stuff ([4c46257](https://github.com/npm/make-fetch-happen/commit/4c46257)) - - - -<a name="2.4.8"></a> -## [2.4.8](https://github.com/npm/make-fetch-happen/compare/v2.4.7...v2.4.8) (2017-05-25) - - -### Bug Fixes - -* **cache:** pass uid/gid/Promise through to cache ([a847c92](https://github.com/npm/make-fetch-happen/commit/a847c92)) - - - -<a name="2.4.7"></a> -## [2.4.7](https://github.com/npm/make-fetch-happen/compare/v2.4.6...v2.4.7) (2017-05-24) - - -### Bug Fixes - -* **deps:** pull in various fixes from deps ([fc2a587](https://github.com/npm/make-fetch-happen/commit/fc2a587)) - - - -<a name="2.4.6"></a> -## [2.4.6](https://github.com/npm/make-fetch-happen/compare/v2.4.5...v2.4.6) (2017-05-24) - - -### Bug Fixes - -* **proxy:** choose agent for http(s)-proxy by protocol of destUrl ([ea4832a](https://github.com/npm/make-fetch-happen/commit/ea4832a)) -* **proxy:** make socks proxy working ([1de810a](https://github.com/npm/make-fetch-happen/commit/1de810a)) -* **proxy:** revert previous proxy solution ([563b0d8](https://github.com/npm/make-fetch-happen/commit/563b0d8)) - - - -<a name="2.4.5"></a> -## [2.4.5](https://github.com/npm/make-fetch-happen/compare/v2.4.4...v2.4.5) (2017-05-24) - - -### Bug Fixes - -* **proxy:** use the destination url when determining agent ([1a714e7](https://github.com/npm/make-fetch-happen/commit/1a714e7)) - - - -<a name="2.4.4"></a> -## [2.4.4](https://github.com/npm/make-fetch-happen/compare/v2.4.3...v2.4.4) (2017-05-23) - - -### Bug Fixes - -* **redirect:** handle redirects explicitly (#27) ([4c4af54](https://github.com/npm/make-fetch-happen/commit/4c4af54)) - - - -<a name="2.4.3"></a> -## [2.4.3](https://github.com/npm/make-fetch-happen/compare/v2.4.2...v2.4.3) (2017-05-06) - - -### Bug Fixes - -* **redirect:** redirects now delete authorization if hosts fail to match ([c071805](https://github.com/npm/make-fetch-happen/commit/c071805)) - - - -<a name="2.4.2"></a> -## [2.4.2](https://github.com/npm/make-fetch-happen/compare/v2.4.1...v2.4.2) (2017-05-04) - - -### Bug Fixes - -* **cache:** reduce race condition window by checking for content ([24544b1](https://github.com/npm/make-fetch-happen/commit/24544b1)) -* **match:** Rewrite the conditional stream logic (#25) ([66bba4b](https://github.com/npm/make-fetch-happen/commit/66bba4b)) - - - -<a name="2.4.1"></a> -## [2.4.1](https://github.com/npm/make-fetch-happen/compare/v2.4.0...v2.4.1) (2017-04-28) - - -### Bug Fixes - -* **memoization:** missed spots + allow passthrough of memo objs ([ac0cd12](https://github.com/npm/make-fetch-happen/commit/ac0cd12)) - - - -<a name="2.4.0"></a> -# [2.4.0](https://github.com/npm/make-fetch-happen/compare/v2.3.0...v2.4.0) (2017-04-28) - - -### Bug Fixes - -* **memoize:** cacache had a broken memoizer ([8a9ed4c](https://github.com/npm/make-fetch-happen/commit/8a9ed4c)) - - -### Features - -* **memoization:** only slurp stuff into memory if opts.memoize is not false ([0744adc](https://github.com/npm/make-fetch-happen/commit/0744adc)) - - - -<a name="2.3.0"></a> -# [2.3.0](https://github.com/npm/make-fetch-happen/compare/v2.2.6...v2.3.0) (2017-04-27) - - -### Features - -* **agent:** added opts.strictSSL and opts.localAddress ([c35015a](https://github.com/npm/make-fetch-happen/commit/c35015a)) -* **proxy:** Added opts.noProxy and NO_PROXY support ([f45c915](https://github.com/npm/make-fetch-happen/commit/f45c915)) - - - -<a name="2.2.6"></a> -## [2.2.6](https://github.com/npm/make-fetch-happen/compare/v2.2.5...v2.2.6) (2017-04-26) - - -### Bug Fixes - -* **agent:** check uppercase & lowercase proxy env (#24) ([acf2326](https://github.com/npm/make-fetch-happen/commit/acf2326)), closes [#22](https://github.com/npm/make-fetch-happen/issues/22) -* **deps:** switch to node-fetch-npm and stop bundling ([3db603b](https://github.com/npm/make-fetch-happen/commit/3db603b)) - - - -<a name="2.2.5"></a> -## [2.2.5](https://github.com/npm/make-fetch-happen/compare/v2.2.4...v2.2.5) (2017-04-23) - - -### Bug Fixes - -* **deps:** bump cacache and use its size feature ([926c1d3](https://github.com/npm/make-fetch-happen/commit/926c1d3)) - - - -<a name="2.2.4"></a> -## [2.2.4](https://github.com/npm/make-fetch-happen/compare/v2.2.3...v2.2.4) (2017-04-18) - - -### Bug Fixes - -* **integrity:** hash verification issues fixed ([07f9402](https://github.com/npm/make-fetch-happen/commit/07f9402)) - - - -<a name="2.2.3"></a> -## [2.2.3](https://github.com/npm/make-fetch-happen/compare/v2.2.2...v2.2.3) (2017-04-18) - - -### Bug Fixes - -* **staleness:** responses older than 8h were never stale :< ([b54dd75](https://github.com/npm/make-fetch-happen/commit/b54dd75)) -* **warning:** remove spurious warning, make format more spec-compliant ([2e4f6bb](https://github.com/npm/make-fetch-happen/commit/2e4f6bb)) - - - -<a name="2.2.2"></a> -## [2.2.2](https://github.com/npm/make-fetch-happen/compare/v2.2.1...v2.2.2) (2017-04-12) - - -### Bug Fixes - -* **retry:** stop retrying 404s ([6fafd53](https://github.com/npm/make-fetch-happen/commit/6fafd53)) - - - -<a name="2.2.1"></a> -## [2.2.1](https://github.com/npm/make-fetch-happen/compare/v2.2.0...v2.2.1) (2017-04-10) - - -### Bug Fixes - -* **deps:** move test-only deps to devDeps ([2daaf80](https://github.com/npm/make-fetch-happen/commit/2daaf80)) - - - -<a name="2.2.0"></a> -# [2.2.0](https://github.com/npm/make-fetch-happen/compare/v2.1.0...v2.2.0) (2017-04-09) - - -### Bug Fixes - -* **cache:** treat caches as private ([57b7dc2](https://github.com/npm/make-fetch-happen/commit/57b7dc2)) - - -### Features - -* **retry:** accept shorthand retry settings ([dfed69d](https://github.com/npm/make-fetch-happen/commit/dfed69d)) - - - -<a name="2.1.0"></a> -# [2.1.0](https://github.com/npm/make-fetch-happen/compare/v2.0.4...v2.1.0) (2017-04-09) - - -### Features - -* **cache:** cache now obeys Age and a variety of other things (#13) ([7b9652d](https://github.com/npm/make-fetch-happen/commit/7b9652d)) - - - -<a name="2.0.4"></a> -## [2.0.4](https://github.com/npm/make-fetch-happen/compare/v2.0.3...v2.0.4) (2017-04-09) - - -### Bug Fixes - -* **agent:** accept Request as fetch input, not just strings ([b71669a](https://github.com/npm/make-fetch-happen/commit/b71669a)) - - - -<a name="2.0.3"></a> -## [2.0.3](https://github.com/npm/make-fetch-happen/compare/v2.0.2...v2.0.3) (2017-04-09) - - -### Bug Fixes - -* **deps:** seriously ([c29e7e7](https://github.com/npm/make-fetch-happen/commit/c29e7e7)) - - - -<a name="2.0.2"></a> -## [2.0.2](https://github.com/npm/make-fetch-happen/compare/v2.0.1...v2.0.2) (2017-04-09) - - -### Bug Fixes - -* **deps:** use bundleDeps instead ([c36ebf0](https://github.com/npm/make-fetch-happen/commit/c36ebf0)) - - - -<a name="2.0.1"></a> -## [2.0.1](https://github.com/npm/make-fetch-happen/compare/v2.0.0...v2.0.1) (2017-04-09) - - -### Bug Fixes - -* **deps:** make sure node-fetch tarball included in release ([3bf49d1](https://github.com/npm/make-fetch-happen/commit/3bf49d1)) - - - -<a name="2.0.0"></a> -# [2.0.0](https://github.com/npm/make-fetch-happen/compare/v1.7.0...v2.0.0) (2017-04-09) - - -### Bug Fixes - -* **deps:** manually pull in newer node-fetch to avoid babel prod dep ([66e5e87](https://github.com/npm/make-fetch-happen/commit/66e5e87)) -* **retry:** be more specific about when we retry ([a47b782](https://github.com/npm/make-fetch-happen/commit/a47b782)) - - -### Features - -* **agent:** add ca/cert/key support to auto-agent (#15) ([57585a7](https://github.com/npm/make-fetch-happen/commit/57585a7)) - - -### BREAKING CHANGES - -* **agent:** pac proxies are no longer supported. -* **retry:** Retry logic has changes. - -* 404s, 420s, and 429s all retry now. -* ENOTFOUND no longer retries. -* Only ECONNRESET, ECONNREFUSED, EADDRINUSE, ETIMEDOUT, and `request-timeout` errors are retried. - - - -<a name="1.7.0"></a> -# [1.7.0](https://github.com/npm/make-fetch-happen/compare/v1.6.0...v1.7.0) (2017-04-08) - - -### Features - -* **cache:** add useful headers to inform users about cached data ([9bd7b00](https://github.com/npm/make-fetch-happen/commit/9bd7b00)) - - - -<a name="1.6.0"></a> -# [1.6.0](https://github.com/npm/make-fetch-happen/compare/v1.5.1...v1.6.0) (2017-04-06) - - -### Features - -* **agent:** better, keepalive-supporting, default http agents ([16277f6](https://github.com/npm/make-fetch-happen/commit/16277f6)) - - - -<a name="1.5.1"></a> -## [1.5.1](https://github.com/npm/make-fetch-happen/compare/v1.5.0...v1.5.1) (2017-04-05) - - -### Bug Fixes - -* **cache:** bump cacache for its fixed error messages ([2f2b916](https://github.com/npm/make-fetch-happen/commit/2f2b916)) -* **cache:** fix handling of errors in cache reads ([5729222](https://github.com/npm/make-fetch-happen/commit/5729222)) - - - -<a name="1.5.0"></a> -# [1.5.0](https://github.com/npm/make-fetch-happen/compare/v1.4.0...v1.5.0) (2017-04-04) - - -### Features - -* **retry:** retry requests on 408 timeouts, too ([8d8b5bd](https://github.com/npm/make-fetch-happen/commit/8d8b5bd)) - - - -<a name="1.4.0"></a> -# [1.4.0](https://github.com/npm/make-fetch-happen/compare/v1.3.1...v1.4.0) (2017-04-04) - - -### Bug Fixes - -* **cache:** stop relying on BB.catch ([2b04494](https://github.com/npm/make-fetch-happen/commit/2b04494)) - - -### Features - -* **retry:** report retry attempt number as extra header ([fd50927](https://github.com/npm/make-fetch-happen/commit/fd50927)) - - - -<a name="1.3.1"></a> -## [1.3.1](https://github.com/npm/make-fetch-happen/compare/v1.3.0...v1.3.1) (2017-04-04) - - -### Bug Fixes - -* **cache:** pretend cache entry is missing on ENOENT ([9c2bb26](https://github.com/npm/make-fetch-happen/commit/9c2bb26)) - - - -<a name="1.3.0"></a> -# [1.3.0](https://github.com/npm/make-fetch-happen/compare/v1.2.1...v1.3.0) (2017-04-04) - - -### Bug Fixes - -* **cache:** if metadata is missing for some odd reason, ignore the entry ([a021a6b](https://github.com/npm/make-fetch-happen/commit/a021a6b)) - - -### Features - -* **cache:** add special headers when request was loaded straight from cache ([8a7dbd1](https://github.com/npm/make-fetch-happen/commit/8a7dbd1)) -* **cache:** allow configuring algorithms to be calculated on insertion ([bf4a0f2](https://github.com/npm/make-fetch-happen/commit/bf4a0f2)) - - - -<a name="1.2.1"></a> -## [1.2.1](https://github.com/npm/make-fetch-happen/compare/v1.2.0...v1.2.1) (2017-04-03) - - -### Bug Fixes - -* **integrity:** update cacache and ssri and change EBADCHECKSUM -> EINTEGRITY ([b6cf6f6](https://github.com/npm/make-fetch-happen/commit/b6cf6f6)) - - - -<a name="1.2.0"></a> -# [1.2.0](https://github.com/npm/make-fetch-happen/compare/v1.1.0...v1.2.0) (2017-04-03) - - -### Features - -* **integrity:** full Subresource Integrity support (#10) ([a590159](https://github.com/npm/make-fetch-happen/commit/a590159)) - - - -<a name="1.1.0"></a> -# [1.1.0](https://github.com/npm/make-fetch-happen/compare/v1.0.1...v1.1.0) (2017-04-01) - - -### Features - -* **opts:** fetch.defaults() for default options ([522a65e](https://github.com/npm/make-fetch-happen/commit/522a65e)) - - - -<a name="1.0.1"></a> -## [1.0.1](https://github.com/npm/make-fetch-happen/compare/v1.0.0...v1.0.1) (2017-04-01) - - - -<a name="1.0.0"></a> -# 1.0.0 (2017-04-01) - - -### Bug Fixes - -* **cache:** default on cache-control header ([b872a2c](https://github.com/npm/make-fetch-happen/commit/b872a2c)) -* standard stuff and cache matching ([753f2c2](https://github.com/npm/make-fetch-happen/commit/753f2c2)) -* **agent:** nudge around things with opts.agent ([ed62b57](https://github.com/npm/make-fetch-happen/commit/ed62b57)) -* **agent:** {agent: false} has special behavior ([b8cc923](https://github.com/npm/make-fetch-happen/commit/b8cc923)) -* **cache:** invalidation on non-GET ([fe78fac](https://github.com/npm/make-fetch-happen/commit/fe78fac)) -* **cache:** make force-cache and only-if-cached work as expected ([f50e9df](https://github.com/npm/make-fetch-happen/commit/f50e9df)) -* **cache:** more spec compliance ([d5a56db](https://github.com/npm/make-fetch-happen/commit/d5a56db)) -* **cache:** only cache 200 gets ([0abb25a](https://github.com/npm/make-fetch-happen/commit/0abb25a)) -* **cache:** only load cache code if cache opt is a string ([250fcd5](https://github.com/npm/make-fetch-happen/commit/250fcd5)) -* **cache:** oops ([e3fa15a](https://github.com/npm/make-fetch-happen/commit/e3fa15a)) -* **cache:** refactored warning removal into main file ([5b0a9f9](https://github.com/npm/make-fetch-happen/commit/5b0a9f9)) -* **cache:** req constructor no longer needed in Cache ([5b74cbc](https://github.com/npm/make-fetch-happen/commit/5b74cbc)) -* **cache:** standard fetch api calls cacheMode "cache" ([6fba805](https://github.com/npm/make-fetch-happen/commit/6fba805)) -* **cache:** was using wrong method for non-GET/HEAD cache invalidation ([810763a](https://github.com/npm/make-fetch-happen/commit/810763a)) -* **caching:** a bunch of cache-related fixes ([8ebda1d](https://github.com/npm/make-fetch-happen/commit/8ebda1d)) -* **deps:** `cacache[@6](https://github.com/6).3.0` - race condition fixes ([9528442](https://github.com/npm/make-fetch-happen/commit/9528442)) -* **freshness:** fix regex for cacheControl matching ([070db86](https://github.com/npm/make-fetch-happen/commit/070db86)) -* **freshness:** fixed default freshness heuristic value ([5d29e88](https://github.com/npm/make-fetch-happen/commit/5d29e88)) -* **logging:** remove console.log calls ([a1d0a47](https://github.com/npm/make-fetch-happen/commit/a1d0a47)) -* **method:** node-fetch guarantees uppercase ([a1d68d6](https://github.com/npm/make-fetch-happen/commit/a1d68d6)) -* **opts:** simplified opts handling ([516fd6e](https://github.com/npm/make-fetch-happen/commit/516fd6e)) -* **proxy:** pass proxy option directly to ProxyAgent ([3398460](https://github.com/npm/make-fetch-happen/commit/3398460)) -* **retry:** false -> {retries: 0} ([297fbb6](https://github.com/npm/make-fetch-happen/commit/297fbb6)) -* **retry:** only retry put if body is not a stream ([a24e599](https://github.com/npm/make-fetch-happen/commit/a24e599)) -* **retry:** skip retries if body is a stream for ANY method ([780c0f8](https://github.com/npm/make-fetch-happen/commit/780c0f8)) - - -### Features - -* **api:** initial implementation -- can make and cache requests ([7d55b49](https://github.com/npm/make-fetch-happen/commit/7d55b49)) -* **fetch:** injectable cache, and retry support ([87b84bf](https://github.com/npm/make-fetch-happen/commit/87b84bf)) - - -### BREAKING CHANGES - -* **cache:** opts.cache -> opts.cacheManager; opts.cacheMode -> opts.cache -* **fetch:** opts.cache accepts a Cache-like obj or a path. Requests are now retried. -* **api:** actual api implemented diff --git a/deps/npm/node_modules/make-fetch-happen/README.md b/deps/npm/node_modules/make-fetch-happen/README.md index f454469e68..87659c9133 100644 --- a/deps/npm/node_modules/make-fetch-happen/README.md +++ b/deps/npm/node_modules/make-fetch-happen/README.md @@ -20,7 +20,7 @@ pooling, proxies, retries, [and more](#features)! * [`fetch.defaults`](#fetch-defaults) * [`minipass-fetch` options](#minipass-fetch-options) * [`make-fetch-happen` options](#extra-options) - * [`opts.cacheManager`](#opts-cache-manager) + * [`opts.cachePath`](#opts-cache-path) * [`opts.cache`](#opts-cache) * [`opts.proxy`](#opts-proxy) * [`opts.noProxy`](#opts-no-proxy) @@ -35,7 +35,7 @@ pooling, proxies, retries, [and more](#features)! ```javascript const fetch = require('make-fetch-happen').defaults({ - cacheManager: './my-cache' // path where cache will be written (and read) + cachePath: './my-cache' // path where cache will be written (and read) }) fetch('https://registry.npmjs.org/make-fetch-happen').then(res => { @@ -103,7 +103,7 @@ A defaulted `fetch` will also have a `.defaults()` method, so they can be chaine ```javascript const fetch = require('make-fetch-happen').defaults({ - cacheManager: './my-local-cache' + cachePath: './my-local-cache' }) fetch('https://registry.npmjs.org/make-fetch-happen') // will always use the cache @@ -136,7 +136,7 @@ For more details, see [the documentation for `minipass-fetch` itself](https://gi make-fetch-happen augments the `minipass-fetch` API with additional features available through extra options. The following extra options are available: -* [`opts.cacheManager`](#opts-cache-manager) - Cache target to read/write +* [`opts.cachePath`](#opts-cache-path) - Cache target to read/write * [`opts.cache`](#opts-cache) - `fetch` cache mode. Controls cache *behavior*. * [`opts.proxy`](#opts-proxy) - Proxy agent * [`opts.noProxy`](#opts-no-proxy) - Domain segments to disable proxying for. @@ -147,15 +147,9 @@ make-fetch-happen augments the `minipass-fetch` API with additional features ava * [`opts.onRetry`](#opts-onretry) - a function called whenever a retry is attempted * [`opts.integrity`](#opts-integrity) - [Subresource Integrity](https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity) metadata. -#### <a name="opts-cache-manager"></a> `> opts.cacheManager` +#### <a name="opts-cache-path"></a> `> opts.cachePath` -Either a `String` or a `Cache`. If the former, it will be assumed to be a `Path` to be used as the cache root for [`cacache`](https://npm.im/cacache). - -If an object is provided, it will be assumed to be a compliant [`Cache` instance](https://developer.mozilla.org/en-US/docs/Web/API/Cache). Only `Cache.match()`, `Cache.put()`, and `Cache.delete()` are required. Options objects will not be passed in to `match()` or `delete()`. - -By implementing this API, you can customize the storage backend for make-fetch-happen itself -- for example, you could implement a cache that uses `redis` for caching, or simply keeps everything in memory. Most of the caching logic exists entirely on the make-fetch-happen side, so the only thing you need to worry about is reading, writing, and deleting, as well as making sure `fetch.Response` objects are what gets returned. - -You can refer to `cache.js` in the make-fetch-happen source code for a reference implementation. +A string `Path` to be used as the cache root for [`cacache`](https://npm.im/cacache). **NOTE**: Requests will not be cached unless their response bodies are consumed. You will need to use one of the `res.json()`, `res.buffer()`, etc methods on the response, or drain the `res.body` stream, in order for it to be written. @@ -163,7 +157,9 @@ The default cache manager also adds the following headers to cached responses: * `X-Local-Cache`: Path to the cache the content was found in * `X-Local-Cache-Key`: Unique cache entry key for this response +* `X-Local-Cache-Mode`: Either `stream` or `buffer` to indicate how the response was read from cacache * `X-Local-Cache-Hash`: Specific integrity hash for the cached entry +* `X-Local-Cache-Status`: One of `miss`, `hit`, `stale`, `revalidated`, `updated`, or `skip` to signal how the response was created * `X-Local-Cache-Time`: UTCString of the cache insertion time for the entry Using [`cacache`](https://npm.im/cacache), a call like this may be used to @@ -181,12 +177,8 @@ cacache.get.byDigest(h.get('x-local-cache'), h.get('x-local-cache-hash')) ```javascript fetch('https://registry.npmjs.org/make-fetch-happen', { - cacheManager: './my-local-cache' + cachePath: './my-local-cache' }) // -> 200-level response will be written to disk - -fetch('https://npm.im/cacache', { - cacheManager: new MyCustomRedisCache(process.env.PORT) -}) // -> 200-level response will be written to redis ``` A possible (minimal) implementation for `MyCustomRedisCache`: @@ -230,7 +222,7 @@ class MyCustomRedisCache { #### <a name="opts-cache"></a> `> opts.cache` -This option follows the standard `fetch` API cache option. This option will do nothing if [`opts.cacheManager`](#opts-cache-manager) is null. The following values are accepted (as strings): +This option follows the standard `fetch` API cache option. This option will do nothing if [`opts.cachePath`](#opts-cache-path) is null. The following values are accepted (as strings): * `default` - Fetch will inspect the HTTP cache on the way to the network. If there is a fresh response it will be used. If there is a stale response a conditional request will be created, and a normal request otherwise. It then updates the HTTP cache with the response. If the revalidation request fails (for example, on a 500 or if you're offline), the stale response will be returned. * `no-store` - Fetch behaves as if there is no HTTP cache at all. @@ -245,7 +237,7 @@ This option follows the standard `fetch` API cache option. This option will do n ```javascript const fetch = require('make-fetch-happen').defaults({ - cacheManager: './my-cache' + cachePath: './my-cache' }) // Will error with ENOTCACHED if we haven't already cached this url @@ -330,7 +322,6 @@ An object that can be used to tune request retry settings. Retries will only be The following are worth noting as explicitly not retried: * `getaddrinfo ENOTFOUND` and will be assumed to be either an unreachable domain or the user will be assumed offline. If a response is cached, it will be returned immediately. -* `ECONNRESET` currently has no support for restarting. It will eventually be supported but requires a bit more juggling due to streaming. If `opts.retry` is `false`, it is equivalent to `{retries: 0}` diff --git a/deps/npm/node_modules/make-fetch-happen/cache.js b/deps/npm/node_modules/make-fetch-happen/cache.js deleted file mode 100644 index 234e3a41d0..0000000000 --- a/deps/npm/node_modules/make-fetch-happen/cache.js +++ /dev/null @@ -1,260 +0,0 @@ -'use strict' - -const fetch = require('minipass-fetch') -const cacache = require('cacache') -const ssri = require('ssri') -const url = require('url') - -const Minipass = require('minipass') -const MinipassFlush = require('minipass-flush') -const MinipassCollect = require('minipass-collect') -const MinipassPipeline = require('minipass-pipeline') - -const MAX_MEM_SIZE = 5 * 1024 * 1024 // 5MB - -// some headers should never be stored in the cache, either because -// they're a security footgun to leave lying around, or because we -// just don't need them taking up space. -// set to undefined so they're omitted from the JSON.stringify -const pruneHeaders = { - authorization: undefined, - 'npm-session': undefined, - 'set-cookie': undefined, - 'cf-ray': undefined, - 'cf-cache-status': undefined, - 'cf-request-id': undefined, - 'x-fetch-attempts': undefined, -} - -function cacheKey (req) { - const parsed = new url.URL(req.url) - return `make-fetch-happen:request-cache:${ - url.format({ - protocol: parsed.protocol, - slashes: true, - port: parsed.port, - hostname: parsed.hostname, - pathname: parsed.pathname, - search: parsed.search, - }) - }` -} - -// This is a cacache-based implementation of the Cache standard, -// using node-fetch. -// docs: https://developer.mozilla.org/en-US/docs/Web/API/Cache -// -module.exports = class Cache { - constructor (path, opts) { - this._path = path - this.Promise = (opts && opts.Promise) || Promise - } - - static get pruneHeaders () { - // exposed for testing, not modifiable - return { ...pruneHeaders } - } - - // Returns a Promise that resolves to the response associated with the first - // matching request in the Cache object. - match (req, opts) { - const key = cacheKey(req) - return cacache.get.info(this._path, key).then(info => { - return info && cacache.get.hasContent( - this._path, info.integrity, opts - ).then(exists => exists && info) - }).then(info => { - if (info && info.metadata && matchDetails(req, { - url: info.metadata.url, - reqHeaders: new fetch.Headers(info.metadata.reqHeaders), - resHeaders: new fetch.Headers(info.metadata.resHeaders), - cacheIntegrity: info.integrity, - integrity: opts && opts.integrity, - })) { - const resHeaders = new fetch.Headers(info.metadata.resHeaders) - addCacheHeaders(resHeaders, this._path, key, info.integrity, info.time) - if (req.method === 'HEAD') { - return new fetch.Response(null, { - url: req.url, - headers: resHeaders, - status: 200, - }) - } - const cachePath = this._path - // avoid opening cache file handles until a user actually tries to - // read from it. - const body = new Minipass() - const fitInMemory = info.size < MAX_MEM_SIZE - const removeOnResume = () => body.removeListener('resume', onResume) - const onResume = - opts.memoize !== false && fitInMemory - ? () => { - const c = cacache.get.stream.byDigest(cachePath, info.integrity, { - memoize: opts.memoize, - }) - c.on('error', /* istanbul ignore next */ err => { - body.emit('error', err) - }) - c.pipe(body) - } - : () => { - removeOnResume() - cacache.get.byDigest(cachePath, info.integrity, { - memoize: opts.memoize, - }) - .then(data => body.end(data)) - .catch(/* istanbul ignore next */ err => { - body.emit('error', err) - }) - } - body.once('resume', onResume) - body.once('end', () => removeOnResume) - return this.Promise.resolve(new fetch.Response(body, { - url: req.url, - headers: resHeaders, - status: 200, - size: info.size, - })) - } - }) - } - - // Takes both a request and its response and adds it to the given cache. - put (req, response, opts) { - opts = opts || {} - const size = response.headers.get('content-length') - const fitInMemory = !!size && opts.memoize !== false && size < MAX_MEM_SIZE - const ckey = cacheKey(req) - const cacheOpts = { - algorithms: opts.algorithms, - metadata: { - url: req.url, - reqHeaders: { - ...req.headers.raw(), - ...pruneHeaders, - }, - resHeaders: { - ...response.headers.raw(), - ...pruneHeaders, - }, - }, - size, - memoize: fitInMemory && opts.memoize, - } - if (req.method === 'HEAD' || response.status === 304) { - // Update metadata without writing - return cacache.get.info(this._path, ckey).then(info => { - // Providing these will bypass content write - cacheOpts.integrity = info.integrity - addCacheHeaders( - response.headers, this._path, ckey, info.integrity, info.time - ) - - return new MinipassPipeline( - cacache.get.stream.byDigest(this._path, info.integrity, cacheOpts), - cacache.put.stream(this._path, ckey, cacheOpts) - ).promise().then(() => { - return response - }) - }) - } - const oldBody = response.body - // the flush is the last thing in the pipeline. Build the pipeline - // back-to-front so we don't consume the data before we use it! - // We unshift in either a tee-stream to the cache put stream, - // or a collecter that dumps it to cache in one go, then the - // old body to bring in the data. - const newBody = new MinipassPipeline(new MinipassFlush({ - flush () { - return cacheWritePromise - }, - })) - - let cacheWriteResolve, cacheWriteReject - const cacheWritePromise = new Promise((resolve, reject) => { - cacheWriteResolve = resolve - cacheWriteReject = reject - }) - const cachePath = this._path - - if (fitInMemory) { - const collecter = new MinipassCollect.PassThrough() - collecter.on('collect', data => { - cacache.put( - cachePath, - ckey, - data, - cacheOpts - ).then(cacheWriteResolve, cacheWriteReject) - }) - newBody.unshift(collecter) - } else { - const tee = new Minipass() - const cacheStream = cacache.put.stream( - cachePath, - ckey, - cacheOpts - ) - tee.pipe(cacheStream) - cacheStream.promise().then(cacheWriteResolve, cacheWriteReject) - newBody.unshift(tee) - } - - newBody.unshift(oldBody) - return Promise.resolve(new fetch.Response(newBody, response)) - } - - // Finds the Cache entry whose key is the request, and if found, deletes the - // Cache entry and returns a Promise that resolves to true. If no Cache entry - // is found, it returns false. - 'delete' (req, opts) { - opts = opts || {} - if (typeof opts.memoize === 'object') { - if (opts.memoize.reset) - opts.memoize.reset() - else if (opts.memoize.clear) - opts.memoize.clear() - else { - Object.keys(opts.memoize).forEach(k => { - opts.memoize[k] = null - }) - } - } - return cacache.rm.entry( - this._path, - cacheKey(req) - // TODO - true/false - ).then(() => false) - } -} - -function matchDetails (req, cached) { - const reqUrl = new url.URL(req.url) - const cacheUrl = new url.URL(cached.url) - const vary = cached.resHeaders.get('Vary') - // https://tools.ietf.org/html/rfc7234#section-4.1 - if (vary) { - if (vary.match(/\*/)) - return false - else { - const fieldsMatch = vary.split(/\s*,\s*/).every(field => { - return cached.reqHeaders.get(field) === req.headers.get(field) - }) - if (!fieldsMatch) - return false - } - } - if (cached.integrity) - return ssri.parse(cached.integrity).match(cached.cacheIntegrity) - - reqUrl.hash = null - cacheUrl.hash = null - return url.format(reqUrl) === url.format(cacheUrl) -} - -function addCacheHeaders (resHeaders, path, key, hash, time) { - resHeaders.set('X-Local-Cache', encodeURIComponent(path)) - resHeaders.set('X-Local-Cache-Key', encodeURIComponent(key)) - resHeaders.set('X-Local-Cache-Hash', encodeURIComponent(hash)) - resHeaders.set('X-Local-Cache-Time', new Date(time).toUTCString()) -} diff --git a/deps/npm/node_modules/make-fetch-happen/index.js b/deps/npm/node_modules/make-fetch-happen/index.js deleted file mode 100644 index 54f72049c1..0000000000 --- a/deps/npm/node_modules/make-fetch-happen/index.js +++ /dev/null @@ -1,457 +0,0 @@ -'use strict' - -const url = require('url') -const fetch = require('minipass-fetch') -const pkg = require('./package.json') -const retry = require('promise-retry') -let ssri - -const Minipass = require('minipass') -const MinipassPipeline = require('minipass-pipeline') -const getAgent = require('./agent') -const setWarning = require('./warning') - -const configureOptions = require('./utils/configure-options') -const iterableToObject = require('./utils/iterable-to-object') -const makePolicy = require('./utils/make-policy') - -const isURL = /^https?:/ -const USER_AGENT = `${pkg.name}/${pkg.version} (+https://npm.im/${pkg.name})` - -const RETRY_ERRORS = [ - 'ECONNRESET', // remote socket closed on us - 'ECONNREFUSED', // remote host refused to open connection - 'EADDRINUSE', // failed to bind to a local port (proxy?) - 'ETIMEDOUT', // someone in the transaction is WAY TOO SLOW - // Known codes we do NOT retry on: - // ENOTFOUND (getaddrinfo failure. Either bad hostname, or offline) -] - -const RETRY_TYPES = [ - 'request-timeout', -] - -// https://fetch.spec.whatwg.org/#http-network-or-cache-fetch -module.exports = cachingFetch -cachingFetch.defaults = function (_uri, _opts) { - const fetch = this - if (typeof _uri === 'object') { - _opts = _uri - _uri = null - } - - function defaultedFetch (uri, opts) { - const finalOpts = Object.assign({}, _opts || {}, opts || {}) - return fetch(uri || _uri, finalOpts) - } - - defaultedFetch.defaults = fetch.defaults - defaultedFetch.delete = fetch.delete - return defaultedFetch -} - -cachingFetch.delete = cacheDelete -function cacheDelete (uri, opts) { - opts = configureOptions(opts) - if (opts.cacheManager) { - const req = new fetch.Request(uri, { - method: opts.method, - headers: opts.headers, - }) - return opts.cacheManager.delete(req, opts) - } -} - -function initializeSsri () { - if (!ssri) - ssri = require('ssri') -} - -function cachingFetch (uri, _opts) { - const opts = configureOptions(_opts) - - if (opts.integrity) { - initializeSsri() - // if verifying integrity, fetch must not decompress - opts.compress = false - } - - const isCachable = ( - ( - opts.method === 'GET' || - opts.method === 'HEAD' - ) && - Boolean(opts.cacheManager) && - opts.cache !== 'no-store' && - opts.cache !== 'reload' - ) - - if (isCachable) { - const req = new fetch.Request(uri, { - method: opts.method, - headers: opts.headers, - }) - - return opts.cacheManager.match(req, opts).then(res => { - if (res) { - const warningCode = (res.headers.get('Warning') || '').match(/^\d+/) - if (warningCode && +warningCode >= 100 && +warningCode < 200) { - // https://tools.ietf.org/html/rfc7234#section-4.3.4 - // - // If a stored response is selected for update, the cache MUST: - // - // * delete any Warning header fields in the stored response with - // warn-code 1xx (see Section 5.5); - // - // * retain any Warning header fields in the stored response with - // warn-code 2xx; - // - res.headers.delete('Warning') - } - - if (opts.cache === 'default' && !isStale(req, res)) - return res - - if (opts.cache === 'default' || opts.cache === 'no-cache') - return conditionalFetch(req, res, opts) - - if (opts.cache === 'force-cache' || opts.cache === 'only-if-cached') { - // 112 Disconnected operation - // SHOULD be included if the cache is intentionally disconnected from - // the rest of the network for a period of time. - // (https://tools.ietf.org/html/rfc2616#section-14.46) - setWarning(res, 112, 'Disconnected operation') - return res - } - } - - if (!res && opts.cache === 'only-if-cached') { - const errorMsg = `request to ${ - uri - } failed: cache mode is 'only-if-cached' but no cached response available.` - - const err = new Error(errorMsg) - err.code = 'ENOTCACHED' - throw err - } - - // Missing cache entry, or mode is default (if stale), reload, no-store - return remoteFetch(req.url, opts) - }) - } - return remoteFetch(uri, opts) -} - -// https://tools.ietf.org/html/rfc7234#section-4.2 -function isStale (req, res) { - const _req = { - url: req.url, - method: req.method, - headers: iterableToObject(req.headers), - } - - const policy = makePolicy(req, res) - - const responseTime = res.headers.get('x-local-cache-time') || - /* istanbul ignore next - would be weird to get a 'stale' - * response that didn't come from cache with a cache time header */ - (res.headers.get('date') || 0) - - policy._responseTime = new Date(responseTime) - - const bool = !policy.satisfiesWithoutRevalidation(_req) - const headers = policy.responseHeaders() - if (headers.warning && /^113\b/.test(headers.warning)) { - // Possible to pick up a rfc7234 warning at this point. - // This is kind of a weird place to stick this, should probably go - // in cachingFetch. But by putting it here, we save an extra - // CachePolicy object construction. - res.headers.append('warning', headers.warning) - } - return bool -} - -function mustRevalidate (res) { - return (res.headers.get('cache-control') || '').match(/must-revalidate/i) -} - -function conditionalFetch (req, cachedRes, opts) { - const _req = { - url: req.url, - method: req.method, - headers: Object.assign({}, opts.headers || {}), - } - - const policy = makePolicy(req, cachedRes) - opts.headers = policy.revalidationHeaders(_req) - - return remoteFetch(req.url, opts) - .then(condRes => { - const revalidatedPolicy = policy.revalidatedPolicy(_req, { - status: condRes.status, - headers: iterableToObject(condRes.headers), - }) - - if (condRes.status >= 500 && !mustRevalidate(cachedRes)) { - // 111 Revalidation failed - // MUST be included if a cache returns a stale response because an - // attempt to revalidate the response failed, due to an inability to - // reach the server. - // (https://tools.ietf.org/html/rfc2616#section-14.46) - setWarning(cachedRes, 111, 'Revalidation failed') - return cachedRes - } - - if (condRes.status === 304) { // 304 Not Modified - // Create a synthetic response from the cached body and original req - const synthRes = new fetch.Response(cachedRes.body, condRes) - return opts.cacheManager.put(req, synthRes, opts) - .then(newRes => { - // Get the list first, because if we delete while iterating, - // it'll throw off the count and not make it through all - // of them. - const newHeaders = revalidatedPolicy.policy.responseHeaders() - const toDelete = [...newRes.headers.keys()] - .filter(k => !newHeaders[k]) - for (const key of toDelete) - newRes.headers.delete(key) - - for (const [key, val] of Object.entries(newHeaders)) - newRes.headers.set(key, val) - - return newRes - }) - } - - return condRes - }) - .then(res => res) - .catch(err => { - if (mustRevalidate(cachedRes)) - throw err - else { - // 111 Revalidation failed - // MUST be included if a cache returns a stale response because an - // attempt to revalidate the response failed, due to an inability to - // reach the server. - // (https://tools.ietf.org/html/rfc2616#section-14.46) - setWarning(cachedRes, 111, 'Revalidation failed') - // 199 Miscellaneous warning - // The warning text MAY include arbitrary information to be presented to - // a human user, or logged. A system receiving this warning MUST NOT take - // any automated action, besides presenting the warning to the user. - // (https://tools.ietf.org/html/rfc2616#section-14.46) - setWarning( - cachedRes, - 199, - `Miscellaneous Warning ${err.code}: ${err.message}` - ) - - return cachedRes - } - }) -} - -function remoteFetchHandleIntegrity (res, integrity) { - if (res.status !== 200) - return res // Error responses aren't subject to integrity checks. - - const oldBod = res.body - const newBod = ssri.integrityStream({ - integrity, - }) - return new fetch.Response(new MinipassPipeline(oldBod, newBod), res) -} - -function remoteFetch (uri, opts) { - const agent = getAgent(uri, opts) - const headers = opts.headers instanceof fetch.Headers - ? opts.headers - : new fetch.Headers(opts.headers) - if (!headers.get('connection')) - headers.set('connection', agent ? 'keep-alive' : 'close') - - if (!headers.get('user-agent')) - headers.set('user-agent', USER_AGENT) - - const reqOpts = { - agent, - body: opts.body, - compress: opts.compress, - follow: opts.follow, - headers, - method: opts.method, - redirect: 'manual', - size: opts.size, - counter: opts.counter, - timeout: opts.timeout, - ca: opts.ca, - cert: opts.cert, - key: opts.key, - rejectUnauthorized: opts.strictSSL, - } - - return retry( - (retryHandler, attemptNum) => { - const req = new fetch.Request(uri, reqOpts) - return fetch(req) - .then((res) => { - if (opts.integrity) - res = remoteFetchHandleIntegrity(res, opts.integrity) - - res.headers.set('x-fetch-attempts', attemptNum) - - const isStream = Minipass.isStream(req.body) - - if (opts.cacheManager) { - const isMethodGetHead = ( - req.method === 'GET' || - req.method === 'HEAD' - ) - - const isCachable = ( - opts.cache !== 'no-store' && - isMethodGetHead && - makePolicy(req, res).storable() && - res.status === 200 // No other statuses should be stored! - ) - - if (isCachable) - return opts.cacheManager.put(req, res, opts) - - if (!isMethodGetHead) { - return opts.cacheManager.delete(req).then(() => { - if (res.status >= 500 && req.method !== 'POST' && !isStream) { - if (typeof opts.onRetry === 'function') - opts.onRetry(res) - - return retryHandler(res) - } - - return res - }) - } - } - - const isRetriable = ( - req.method !== 'POST' && - !isStream && - ( - res.status === 408 || // Request Timeout - res.status === 420 || // Enhance Your Calm (usually Twitter rate-limit) - res.status === 429 || // Too Many Requests ("standard" rate-limiting) - res.status >= 500 // Assume server errors are momentary hiccups - ) - ) - - if (isRetriable) { - if (typeof opts.onRetry === 'function') - opts.onRetry(res) - - return retryHandler(res) - } - - if (!fetch.isRedirect(res.status)) - return res - - if (opts.redirect === 'manual') - return res - - // if (!fetch.isRedirect(res.status) || opts.redirect === 'manual') { - // return res - // } - - // handle redirects - matches behavior of fetch: https://github.com/bitinn/node-fetch - if (opts.redirect === 'error') { - const err = new fetch.FetchError(`redirect mode is set to error: ${uri}`, 'no-redirect', { code: 'ENOREDIRECT' }) - throw err - } - - if (!res.headers.get('location')) { - const err = new fetch.FetchError(`redirect location header missing at: ${uri}`, 'no-location', { code: 'EINVALIDREDIRECT' }) - throw err - } - - if (req.counter >= req.follow) { - const err = new fetch.FetchError(`maximum redirect reached at: ${uri}`, 'max-redirect', { code: 'EMAXREDIRECT' }) - throw err - } - - const resolvedUrlParsed = new url.URL(res.headers.get('location'), req.url) - const resolvedUrl = url.format(resolvedUrlParsed) - const redirectURL = (isURL.test(res.headers.get('location'))) - ? new url.URL(res.headers.get('location')) - : resolvedUrlParsed - - // Comment below is used under the following license: - // Copyright (c) 2010-2012 Mikeal Rogers - // Licensed under the Apache License, Version 2.0 (the "License"); - // you may not use this file except in compliance with the License. - // You may obtain a copy of the License at - // http://www.apache.org/licenses/LICENSE-2.0 - // Unless required by applicable law or agreed to in writing, - // software distributed under the License is distributed on an "AS - // IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - // express or implied. See the License for the specific language - // governing permissions and limitations under the License. - - // Remove authorization if changing hostnames (but not if just - // changing ports or protocols). This matches the behavior of request: - // https://github.com/request/request/blob/b12a6245/lib/redirect.js#L134-L138 - if (new url.URL(req.url).hostname !== redirectURL.hostname) - req.headers.delete('authorization') - - // for POST request with 301/302 response, or any request with 303 response, - // use GET when following redirect - if ( - res.status === 303 || - ( - req.method === 'POST' && - ( - res.status === 301 || - res.status === 302 - ) - ) - ) { - opts.method = 'GET' - opts.body = null - req.headers.delete('content-length') - } - - opts.headers = {} - req.headers.forEach((value, name) => { - opts.headers[name] = value - }) - - opts.counter = ++req.counter - return cachingFetch(resolvedUrl, opts) - }) - .catch(err => { - const code = (err.code === 'EPROMISERETRY') - ? err.retried.code - : err.code - - const isRetryError = ( - RETRY_ERRORS.indexOf(code) === -1 && - RETRY_TYPES.indexOf(err.type) === -1 - ) - - if (req.method === 'POST' || isRetryError) - throw err - - if (typeof opts.onRetry === 'function') - opts.onRetry(err) - - return retryHandler(err) - }) - }, - opts.retry - ).catch(err => { - if (err.status >= 400 && err.type !== 'system') { - // this is an HTTP response "error" that we care about - return err - } - - throw err - }) -} diff --git a/deps/npm/node_modules/make-fetch-happen/agent.js b/deps/npm/node_modules/make-fetch-happen/lib/agent.js index e27eb4f3a8..873d69cf47 100644 --- a/deps/npm/node_modules/make-fetch-happen/agent.js +++ b/deps/npm/node_modules/make-fetch-happen/lib/agent.js @@ -4,8 +4,8 @@ const url = require('url') const isLambda = require('is-lambda') const AGENT_CACHE = new LRU({ max: 50 }) -let HttpsAgent -let HttpAgent +const HttpAgent = require('agentkeepalive') +const HttpsAgent = HttpAgent.HttpsAgent module.exports = getAgent @@ -66,11 +66,6 @@ function getAgent (uri, opts) { return proxy } - if (!HttpsAgent) { - HttpAgent = require('agentkeepalive') - HttpsAgent = HttpAgent.HttpsAgent - } - const agent = isHttps ? new HttpsAgent({ maxSockets: agentMaxSockets, ca: opts.ca, @@ -155,15 +150,15 @@ function getProxyUri (uri, opts) { } const getAuth = u => - u.username && u.password ? `${u.username}:${u.password}` - : u.username ? u.username + u.username && u.password ? decodeURIComponent(`${u.username}:${u.password}`) + : u.username ? decodeURIComponent(u.username) : null const getPath = u => u.pathname + u.search + u.hash -let HttpProxyAgent -let HttpsProxyAgent -let SocksProxyAgent +const HttpProxyAgent = require('http-proxy-agent') +const HttpsProxyAgent = require('https-proxy-agent') +const SocksProxyAgent = require('socks-proxy-agent') module.exports.getProxy = getProxy function getProxy (proxyUrl, opts, isHttps) { const popts = { @@ -182,23 +177,13 @@ function getProxy (proxyUrl, opts, isHttps) { } if (proxyUrl.protocol === 'http:' || proxyUrl.protocol === 'https:') { - if (!isHttps) { - if (!HttpProxyAgent) - HttpProxyAgent = require('http-proxy-agent') - + if (!isHttps) return new HttpProxyAgent(popts) - } else { - if (!HttpsProxyAgent) - HttpsProxyAgent = require('https-proxy-agent') - + else return new HttpsProxyAgent(popts) - } - } else if (proxyUrl.protocol.startsWith('socks')) { - if (!SocksProxyAgent) - SocksProxyAgent = require('socks-proxy-agent') - + } else if (proxyUrl.protocol.startsWith('socks')) return new SocksProxyAgent(popts) - } else { + else { throw Object.assign( new Error(`unsupported proxy protocol: '${proxyUrl.protocol}'`), { diff --git a/deps/npm/node_modules/make-fetch-happen/lib/cache/entry.js b/deps/npm/node_modules/make-fetch-happen/lib/cache/entry.js new file mode 100644 index 0000000000..0df006fe34 --- /dev/null +++ b/deps/npm/node_modules/make-fetch-happen/lib/cache/entry.js @@ -0,0 +1,432 @@ +const { Request, Response } = require('minipass-fetch') +const Minipass = require('minipass') +const MinipassCollect = require('minipass-collect') +const MinipassFlush = require('minipass-flush') +const MinipassPipeline = require('minipass-pipeline') +const cacache = require('cacache') +const url = require('url') + +const CachePolicy = require('./policy.js') +const cacheKey = require('./key.js') +const remote = require('../remote.js') + +const hasOwnProperty = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop) + +// maximum amount of data we will buffer into memory +// if we'll exceed this, we switch to streaming +const MAX_MEM_SIZE = 5 * 1024 * 1024 // 5MB + +// allow list for request headers that will be written to the cache index +// note: we will also store any request headers +// that are named in a response's vary header +const KEEP_REQUEST_HEADERS = [ + 'accept-charset', + 'accept-encoding', + 'accept-language', + 'accept', + 'cache-control', +] + +// allow list for response headers that will be written to the cache index +// note: we must not store the real response's age header, or when we load +// a cache policy based on the metadata it will think the cached response +// is always stale +const KEEP_RESPONSE_HEADERS = [ + 'cache-control', + 'content-encoding', + 'content-language', + 'content-type', + 'date', + 'etag', + 'expires', + 'last-modified', + 'location', + 'pragma', + 'vary', +] + +// return an object containing all metadata to be written to the index +const getMetadata = (request, response, options) => { + const metadata = { + url: request.url, + reqHeaders: {}, + resHeaders: {}, + } + + // only save the status if it's not a 200 or 304 + if (response.status !== 200 && response.status !== 304) + metadata.status = response.status + + for (const name of KEEP_REQUEST_HEADERS) { + if (request.headers.has(name)) + metadata.reqHeaders[name] = request.headers.get(name) + } + + // if the request's host header differs from the host in the url + // we need to keep it, otherwise it's just noise and we ignore it + const host = request.headers.get('host') + const parsedUrl = new url.URL(request.url) + if (host && parsedUrl.host !== host) + metadata.reqHeaders.host = host + + // if the response has a vary header, make sure + // we store the relevant request headers too + if (response.headers.has('vary')) { + const vary = response.headers.get('vary') + // a vary of "*" means every header causes a different response. + // in that scenario, we do not include any additional headers + // as the freshness check will always fail anyway and we don't + // want to bloat the cache indexes + if (vary !== '*') { + // copy any other request headers that will vary the response + const varyHeaders = vary.trim().toLowerCase().split(/\s*,\s*/) + for (const name of varyHeaders) { + // explicitly ignore accept-encoding here + if (name !== 'accept-encoding' && request.headers.has(name)) + metadata.reqHeaders[name] = request.headers.get(name) + } + } + } + + for (const name of KEEP_RESPONSE_HEADERS) { + if (response.headers.has(name)) + metadata.resHeaders[name] = response.headers.get(name) + } + + // we only store accept-encoding and content-encoding if the user + // has disabled automatic compression and decompression in minipass-fetch + // since if it's enabled (the default) then the content will have + // already been decompressed making the header a lie + if (options.compress === false) { + metadata.reqHeaders['accept-encoding'] = request.headers.get('accept-encoding') + metadata.resHeaders['content-encoding'] = response.headers.get('content-encoding') + } + + return metadata +} + +// symbols used to hide objects that may be lazily evaluated in a getter +const _request = Symbol('request') +const _response = Symbol('response') +const _policy = Symbol('policy') + +class CacheEntry { + constructor ({ entry, request, response, options }) { + this.entry = entry + this.options = options + this.key = entry ? entry.key : cacheKey(request) + + // these properties are behind getters that lazily evaluate + this[_request] = request + this[_response] = response + this[_policy] = null + } + + // returns a CacheEntry instance that satisfies the given request + // or undefined if no existing entry satisfies + static async find (request, options) { + try { + // compacts the index and returns an array of unique entries + var matches = await cacache.index.compact(options.cachePath, cacheKey(request), (A, B) => { + const entryA = new CacheEntry({ entry: A, options }) + const entryB = new CacheEntry({ entry: B, options }) + return entryA.policy.satisfies(entryB.request) + }, { + validateEntry: (entry) => { + // if an integrity is null, it needs to have a status specified + if (entry.integrity === null) + return !!(entry.metadata && entry.metadata.status) + + return true + }, + }) + } catch (err) { + // if the compact request fails, ignore the error and return + return + } + + // find the specific entry that satisfies the request + let match + for (const entry of matches) { + const _entry = new CacheEntry({ + entry, + options, + }) + + if (_entry.policy.satisfies(request)) { + match = _entry + break + } + } + + return match + } + + // if the user made a PUT/POST/PATCH then we invalidate our + // cache for the same url by deleting the index entirely + static async invalidate (request, options) { + const key = cacheKey(request) + try { + await cacache.rm.entry(options.cachePath, key, { removeFully: true }) + } catch (err) { + // ignore errors + } + } + + get request () { + if (!this[_request]) { + this[_request] = new Request(this.entry.metadata.url, { + method: 'GET', + headers: this.entry.metadata.reqHeaders, + }) + } + + return this[_request] + } + + get response () { + if (!this[_response]) { + this[_response] = new Response(null, { + url: this.entry.metadata.url, + counter: this.options.counter, + status: this.entry.metadata.status || 200, + headers: { + ...this.entry.metadata.resHeaders, + 'content-length': this.entry.size, + }, + }) + } + + return this[_response] + } + + get policy () { + if (!this[_policy]) { + this[_policy] = new CachePolicy({ + entry: this.entry, + request: this.request, + response: this.response, + options: this.options, + }) + } + + return this[_policy] + } + + // wraps the response in a pipeline that stores the data + // in the cache while the user consumes it + async store (status) { + // if we got a status other than 200, 301, or 308, + // or the CachePolicy forbid storage, append the + // cache status header and return it untouched + if (this.request.method !== 'GET' || ![200, 301, 308].includes(this.response.status) || !this.policy.storable()) { + this.response.headers.set('x-local-cache-status', 'skip') + return this.response + } + + const size = this.response.headers.get('content-length') + const fitsInMemory = !!size && Number(size) < MAX_MEM_SIZE + const shouldBuffer = this.options.memoize !== false && fitsInMemory + const cacheOpts = { + algorithms: this.options.algorithms, + metadata: getMetadata(this.request, this.response, this.options), + size, + memoize: fitsInMemory && this.options.memoize, + } + + let body = null + // we only set a body if the status is a 200, redirects are + // stored as metadata only + if (this.response.status === 200) { + let cacheWriteResolve, cacheWriteReject + const cacheWritePromise = new Promise((resolve, reject) => { + cacheWriteResolve = resolve + cacheWriteReject = reject + }) + + body = new MinipassPipeline(new MinipassFlush({ + flush () { + return cacheWritePromise + }, + })) + + let abortStream, onResume + if (shouldBuffer) { + // if the result fits in memory, use a collect stream to gather + // the response and write it to cacache while also passing it through + // to the user + onResume = () => { + const collector = new MinipassCollect.PassThrough() + abortStream = collector + collector.on('collect', (data) => { + // TODO if the cache write fails, log a warning but return the response anyway + cacache.put(this.options.cachePath, this.key, data, cacheOpts).then(cacheWriteResolve, cacheWriteReject) + }) + body.unshift(collector) + body.unshift(this.response.body) + } + } else { + // if it does not fit in memory, create a tee stream and use + // that to pipe to both the cache and the user simultaneously + onResume = () => { + const tee = new Minipass() + const cacheStream = cacache.put.stream(this.options.cachePath, this.key, cacheOpts) + abortStream = cacheStream + tee.pipe(cacheStream) + // TODO if the cache write fails, log a warning but return the response anyway + cacheStream.promise().then(cacheWriteResolve, cacheWriteReject) + body.unshift(tee) + body.unshift(this.response.body) + } + } + + body.once('resume', onResume) + body.once('end', () => body.removeListener('resume', onResume)) + this.response.body.on('error', (err) => { + // the abortStream will either be a MinipassCollect if we buffer + // or a cacache write stream, either way be sure to listen for + // errors from the actual response and avoid writing data that we + // know to be invalid to the cache + abortStream.destroy(err) + }) + } else + await cacache.index.insert(this.options.cachePath, this.key, null, cacheOpts) + + // note: we do not set the x-local-cache-hash header because we do not know + // the hash value until after the write to the cache completes, which doesn't + // happen until after the response has been sent and it's too late to write + // the header anyway + this.response.headers.set('x-local-cache', encodeURIComponent(this.options.cachePath)) + this.response.headers.set('x-local-cache-key', encodeURIComponent(this.key)) + this.response.headers.set('x-local-cache-mode', shouldBuffer ? 'buffer' : 'stream') + this.response.headers.set('x-local-cache-status', status) + this.response.headers.set('x-local-cache-time', new Date().toISOString()) + const newResponse = new Response(body, { + url: this.response.url, + status: this.response.status, + headers: this.response.headers, + counter: this.options.counter, + }) + return newResponse + } + + // use the cached data to create a response and return it + async respond (method, options, status) { + let response + const size = Number(this.response.headers.get('content-length')) + const fitsInMemory = !!size && size < MAX_MEM_SIZE + const shouldBuffer = this.options.memoize !== false && fitsInMemory + if (method === 'HEAD' || [301, 308].includes(this.response.status)) { + // if the request is a HEAD, or the response is a redirect, + // then the metadata in the entry already includes everything + // we need to build a response + response = this.response + } else { + // we're responding with a full cached response, so create a body + // that reads from cacache and attach it to a new Response + const body = new Minipass() + const removeOnResume = () => body.removeListener('resume', onResume) + let onResume + if (shouldBuffer) { + onResume = async () => { + removeOnResume() + try { + const content = await cacache.get.byDigest(this.options.cachePath, this.entry.integrity, { memoize: this.options.memoize }) + body.end(content) + } catch (err) { + body.emit('error', err) + } + } + } else { + onResume = () => { + const cacheStream = cacache.get.stream.byDigest(this.options.cachePath, this.entry.integrity, { memoize: this.options.memoize }) + cacheStream.on('error', (err) => body.emit('error', err)) + cacheStream.pipe(body) + } + } + + body.once('resume', onResume) + body.once('end', removeOnResume) + response = new Response(body, { + url: this.entry.metadata.url, + counter: options.counter, + status: 200, + headers: { + ...this.policy.responseHeaders(), + }, + }) + } + + response.headers.set('x-local-cache', encodeURIComponent(this.options.cachePath)) + response.headers.set('x-local-cache-hash', encodeURIComponent(this.entry.integrity)) + response.headers.set('x-local-cache-key', encodeURIComponent(this.key)) + response.headers.set('x-local-cache-mode', shouldBuffer ? 'buffer' : 'stream') + response.headers.set('x-local-cache-status', status) + response.headers.set('x-local-cache-time', new Date(this.entry.time).toUTCString()) + return response + } + + // use the provided request along with this cache entry to + // revalidate the stored response. returns a response, either + // from the cache or from the update + async revalidate (request, options) { + const revalidateRequest = new Request(request, { + headers: this.policy.revalidationHeaders(request), + }) + + try { + // NOTE: be sure to remove the headers property from the + // user supplied options, since we have already defined + // them on the new request object. if they're still in the + // options then those will overwrite the ones from the policy + var response = await remote(revalidateRequest, { + ...options, + headers: undefined, + }) + } catch (err) { + // if the network fetch fails, return the stale + // cached response unless it has a cache-control + // of 'must-revalidate' + if (!this.policy.mustRevalidate) + return this.respond(request.method, options, 'stale') + + throw err + } + + if (this.policy.revalidated(revalidateRequest, response)) { + // we got a 304, write a new index to the cache and respond from cache + const metadata = getMetadata(request, response, options) + // 304 responses do not include headers that are specific to the response data + // since they do not include a body, so we copy values for headers that were + // in the old cache entry to the new one, if the new metadata does not already + // include that header + for (const name of KEEP_RESPONSE_HEADERS) { + if (!hasOwnProperty(metadata.resHeaders, name) && hasOwnProperty(this.entry.metadata.resHeaders, name)) + metadata.resHeaders[name] = this.entry.metadata.resHeaders[name] + } + + try { + await cacache.index.insert(options.cachePath, this.key, this.entry.integrity, { + size: this.entry.size, + metadata, + }) + } catch (err) { + // if updating the cache index fails, we ignore it and + // respond anyway + } + return this.respond(request.method, options, 'revalidated') + } + + // if we got a modified response, create a new entry based on it + const newEntry = new CacheEntry({ + request, + response, + options, + }) + + // respond with the new entry while writing it to the cache + return newEntry.store('updated') + } +} + +module.exports = CacheEntry diff --git a/deps/npm/node_modules/make-fetch-happen/lib/cache/errors.js b/deps/npm/node_modules/make-fetch-happen/lib/cache/errors.js new file mode 100644 index 0000000000..31e97c4b03 --- /dev/null +++ b/deps/npm/node_modules/make-fetch-happen/lib/cache/errors.js @@ -0,0 +1,10 @@ +class NotCachedError extends Error { + constructor (url) { + super(`request to ${url} failed: cache mode is 'only-if-cached' but no cached response is available.`) + this.code = 'ENOTCACHED' + } +} + +module.exports = { + NotCachedError, +} diff --git a/deps/npm/node_modules/make-fetch-happen/lib/cache/index.js b/deps/npm/node_modules/make-fetch-happen/lib/cache/index.js new file mode 100644 index 0000000000..00df31dd15 --- /dev/null +++ b/deps/npm/node_modules/make-fetch-happen/lib/cache/index.js @@ -0,0 +1,46 @@ +const { NotCachedError } = require('./errors.js') +const CacheEntry = require('./entry.js') +const remote = require('../remote.js') + +// do whatever is necessary to get a Response and return it +const cacheFetch = async (request, options) => { + // try to find a cached entry that satisfies this request + const entry = await CacheEntry.find(request, options) + if (!entry) { + // no cached result, if the cache mode is only-if-cached that's a failure + if (options.cache === 'only-if-cached') + throw new NotCachedError(request.url) + + // otherwise, we make a request, store it and return it + const response = await remote(request, options) + const entry = new CacheEntry({ request, response, options }) + return entry.store('miss') + } + + // we have a cached response that satisfies this request, however + // if the cache mode is reload the user explicitly wants us to revalidate + if (options.cache === 'reload') + return entry.revalidate(request, options) + + // if the cache mode is either force-cache or only-if-cached we will only + // respond with a cached entry, even if it's stale. set the status to the + // appropriate value based on whether revalidation is needed and respond + // from the cache + const _needsRevalidation = entry.policy.needsRevalidation(request) + if (options.cache === 'force-cache' || + options.cache === 'only-if-cached' || + !_needsRevalidation) + return entry.respond(request.method, options, _needsRevalidation ? 'stale' : 'hit') + + // cache entry might be stale, revalidate it and return a response + return entry.revalidate(request, options) +} + +cacheFetch.invalidate = async (request, options) => { + if (!options.cachePath) + return + + return CacheEntry.invalidate(request, options) +} + +module.exports = cacheFetch diff --git a/deps/npm/node_modules/make-fetch-happen/lib/cache/key.js b/deps/npm/node_modules/make-fetch-happen/lib/cache/key.js new file mode 100644 index 0000000000..f7684d562b --- /dev/null +++ b/deps/npm/node_modules/make-fetch-happen/lib/cache/key.js @@ -0,0 +1,17 @@ +const { URL, format } = require('url') + +// options passed to url.format() when generating a key +const formatOptions = { + auth: false, + fragment: false, + search: true, + unicode: false, +} + +// returns a string to be used as the cache key for the Request +const cacheKey = (request) => { + const parsed = new URL(request.url) + return `make-fetch-happen:request-cache:${format(parsed, formatOptions)}` +} + +module.exports = cacheKey diff --git a/deps/npm/node_modules/make-fetch-happen/lib/cache/policy.js b/deps/npm/node_modules/make-fetch-happen/lib/cache/policy.js new file mode 100644 index 0000000000..189dce80ee --- /dev/null +++ b/deps/npm/node_modules/make-fetch-happen/lib/cache/policy.js @@ -0,0 +1,161 @@ +const CacheSemantics = require('http-cache-semantics') +const Negotiator = require('negotiator') +const ssri = require('ssri') + +// HACK: negotiator lazy loads several of its own modules +// as a micro optimization. we need to be sure that they're +// in memory as soon as possible at startup so that we do +// not try to lazy load them after the directory has been +// retired during a self update of the npm CLI, we do this +// by calling all of the methods that trigger a lazy load +// on a fake instance. +const preloadNegotiator = new Negotiator({ headers: {} }) +preloadNegotiator.charsets() +preloadNegotiator.encodings() +preloadNegotiator.languages() +preloadNegotiator.mediaTypes() + +// options passed to http-cache-semantics constructor +const policyOptions = { + shared: false, + ignoreCargoCult: true, +} + +// a fake empty response, used when only testing the +// request for storability +const emptyResponse = { status: 200, headers: {} } + +// returns a plain object representation of the Request +const requestObject = (request) => { + const _obj = { + method: request.method, + url: request.url, + headers: {}, + } + + request.headers.forEach((value, key) => { + _obj.headers[key] = value + }) + + return _obj +} + +// returns a plain object representation of the Response +const responseObject = (response) => { + const _obj = { + status: response.status, + headers: {}, + } + + response.headers.forEach((value, key) => { + _obj.headers[key] = value + }) + + return _obj +} + +class CachePolicy { + constructor ({ entry, request, response, options }) { + this.entry = entry + this.request = requestObject(request) + this.response = responseObject(response) + this.options = options + this.policy = new CacheSemantics(this.request, this.response, policyOptions) + + if (this.entry) { + // if we have an entry, copy the timestamp to the _responseTime + // this is necessary because the CacheSemantics constructor forces + // the value to Date.now() which means a policy created from a + // cache entry is likely to always identify itself as stale + this.policy._responseTime = this.entry.time + } + } + + // static method to quickly determine if a request alone is storable + static storable (request, options) { + // no cachePath means no caching + if (!options.cachePath) + return false + + // user explicitly asked not to cache + if (options.cache === 'no-store') + return false + + // we only cache GET and HEAD requests + if (!['GET', 'HEAD'].includes(request.method)) + return false + + // otherwise, let http-cache-semantics make the decision + // based on the request's headers + const policy = new CacheSemantics(requestObject(request), emptyResponse, policyOptions) + return policy.storable() + } + + // returns true if the policy satisfies the request + satisfies (request) { + const _req = requestObject(request) + if (this.request.headers.host !== _req.headers.host) + return false + + const negotiatorA = new Negotiator(this.request) + const negotiatorB = new Negotiator(_req) + + if (JSON.stringify(negotiatorA.mediaTypes()) !== JSON.stringify(negotiatorB.mediaTypes())) + return false + + if (JSON.stringify(negotiatorA.languages()) !== JSON.stringify(negotiatorB.languages())) + return false + + if (JSON.stringify(negotiatorA.encodings()) !== JSON.stringify(negotiatorB.encodings())) + return false + + if (this.options.integrity) + return ssri.parse(this.options.integrity).match(this.entry.integrity) + + return true + } + + // returns true if the request and response allow caching + storable () { + return this.policy.storable() + } + + // NOTE: this is a hack to avoid parsing the cache-control + // header ourselves, it returns true if the response's + // cache-control contains must-revalidate + get mustRevalidate () { + return !!this.policy._rescc['must-revalidate'] + } + + // returns true if the cached response requires revalidation + // for the given request + needsRevalidation (request) { + const _req = requestObject(request) + // force method to GET because we only cache GETs + // but can serve a HEAD from a cached GET + _req.method = 'GET' + return !this.policy.satisfiesWithoutRevalidation(_req) + } + + responseHeaders () { + return this.policy.responseHeaders() + } + + // returns a new object containing the appropriate headers + // to send a revalidation request + revalidationHeaders (request) { + const _req = requestObject(request) + return this.policy.revalidationHeaders(_req) + } + + // returns true if the request/response was revalidated + // successfully. returns false if a new response was received + revalidated (request, response) { + const _req = requestObject(request) + const _res = responseObject(response) + const policy = this.policy.revalidatedPolicy(_req, _res) + return !policy.modified + } +} + +module.exports = CachePolicy diff --git a/deps/npm/node_modules/make-fetch-happen/lib/fetch.js b/deps/npm/node_modules/make-fetch-happen/lib/fetch.js new file mode 100644 index 0000000000..dfded79295 --- /dev/null +++ b/deps/npm/node_modules/make-fetch-happen/lib/fetch.js @@ -0,0 +1,100 @@ +'use strict' + +const { FetchError, Request, isRedirect } = require('minipass-fetch') +const url = require('url') + +const CachePolicy = require('./cache/policy.js') +const cache = require('./cache/index.js') +const remote = require('./remote.js') + +// given a Request, a Response and user options +// return true if the response is a redirect that +// can be followed. we throw errors that will result +// in the fetch being rejected if the redirect is +// possible but invalid for some reason +const canFollowRedirect = (request, response, options) => { + if (!isRedirect(response.status)) + return false + + if (options.redirect === 'manual') + return false + + if (options.redirect === 'error') + throw new FetchError(`redirect mode is set to error: ${request.url}`, 'no-redirect', { code: 'ENOREDIRECT' }) + + if (!response.headers.has('location')) + throw new FetchError(`redirect location header missing for: ${request.url}`, 'no-location', { code: 'EINVALIDREDIRECT' }) + + if (request.counter >= request.follow) + throw new FetchError(`maximum redirect reached at: ${request.url}`, 'max-redirect', { code: 'EMAXREDIRECT' }) + + return true +} + +// given a Request, a Response, and the user's options return an object +// with a new Request and a new options object that will be used for +// following the redirect +const getRedirect = (request, response, options) => { + const _opts = { ...options } + const location = response.headers.get('location') + const redirectUrl = new url.URL(location, /^https?:/.test(location) ? undefined : request.url) + // Comment below is used under the following license: + // Copyright (c) 2010-2012 Mikeal Rogers + // Licensed under the Apache License, Version 2.0 (the "License"); + // you may not use this file except in compliance with the License. + // You may obtain a copy of the License at + // http://www.apache.org/licenses/LICENSE-2.0 + // Unless required by applicable law or agreed to in writing, + // software distributed under the License is distributed on an "AS + // IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + // express or implied. See the License for the specific language + // governing permissions and limitations under the License. + + // Remove authorization if changing hostnames (but not if just + // changing ports or protocols). This matches the behavior of request: + // https://github.com/request/request/blob/b12a6245/lib/redirect.js#L134-L138 + if (new url.URL(request.url).hostname !== redirectUrl.hostname) + request.headers.delete('authorization') + + // for POST request with 301/302 response, or any request with 303 response, + // use GET when following redirect + if (response.status === 303 || (request.method === 'POST' && [301, 302].includes(response.status))) { + _opts.method = 'GET' + _opts.body = null + request.headers.delete('content-length') + } + + _opts.headers = {} + request.headers.forEach((value, key) => { + _opts.headers[key] = value + }) + + _opts.counter = ++request.counter + const redirectReq = new Request(url.format(redirectUrl), _opts) + return { + request: redirectReq, + options: _opts, + } +} + +const fetch = async (request, options) => { + const response = CachePolicy.storable(request, options) + ? await cache(request, options) + : await remote(request, options) + + // if the request wasn't a GET or HEAD, and the response + // status is between 200 and 399 inclusive, invalidate the + // request url + if (!['GET', 'HEAD'].includes(request.method) && + response.status >= 200 && + response.status <= 399) + await cache.invalidate(request, options) + + if (!canFollowRedirect(request, response, options)) + return response + + const redirect = getRedirect(request, response, options) + return fetch(redirect.request, redirect.options) +} + +module.exports = fetch diff --git a/deps/npm/node_modules/make-fetch-happen/lib/index.js b/deps/npm/node_modules/make-fetch-happen/lib/index.js new file mode 100644 index 0000000000..6028bc0725 --- /dev/null +++ b/deps/npm/node_modules/make-fetch-happen/lib/index.js @@ -0,0 +1,40 @@ +const { FetchError, Headers, Request, Response } = require('minipass-fetch') + +const configureOptions = require('./options.js') +const fetch = require('./fetch.js') + +const makeFetchHappen = (url, opts) => { + const options = configureOptions(opts) + + const request = new Request(url, options) + return fetch(request, options) +} + +makeFetchHappen.defaults = (defaultUrl, defaultOptions = {}) => { + if (typeof defaultUrl === 'object') { + defaultOptions = defaultUrl + defaultUrl = null + } + + const defaultedFetch = (url, options = {}) => { + const finalUrl = url || defaultUrl + const finalOptions = { + ...defaultOptions, + ...options, + headers: { + ...defaultOptions.headers, + ...options.headers, + }, + } + return makeFetchHappen(finalUrl, finalOptions) + } + + defaultedFetch.defaults = makeFetchHappen.defaults + return defaultedFetch +} + +module.exports = makeFetchHappen +module.exports.FetchError = FetchError +module.exports.Headers = Headers +module.exports.Request = Request +module.exports.Response = Response diff --git a/deps/npm/node_modules/make-fetch-happen/lib/options.js b/deps/npm/node_modules/make-fetch-happen/lib/options.js new file mode 100644 index 0000000000..0889175486 --- /dev/null +++ b/deps/npm/node_modules/make-fetch-happen/lib/options.js @@ -0,0 +1,45 @@ +const conditionalHeaders = [ + 'if-modified-since', + 'if-none-match', + 'if-unmodified-since', + 'if-match', + 'if-range', +] + +const configureOptions = (opts) => { + const options = { ...opts } + options.method = options.method ? options.method.toUpperCase() : 'GET' + if (Object.prototype.hasOwnProperty.call(options, 'strictSSL')) + options.rejectUnauthorized = options.strictSSL + + if (!options.retry) + options.retry = { retries: 0 } + else if (typeof options.retry === 'string') { + const retries = parseInt(options.retry, 10) + if (isFinite(retries)) + options.retry = { retries } + else + options.retry = { retries: 0 } + } else if (typeof options.retry === 'number') + options.retry = { retries: options.retry } + else + options.retry = { retries: 0, ...options.retry } + + options.cache = options.cache || 'default' + if (options.cache === 'default') { + const hasConditionalHeader = Object.keys(options.headers || {}).some((name) => { + return conditionalHeaders.includes(name.toLowerCase()) + }) + if (hasConditionalHeader) + options.cache = 'no-store' + } + + // cacheManager is deprecated, but if it's set and + // cachePath is not we should copy it to the new field + if (options.cacheManager && !options.cachePath) + options.cachePath = options.cacheManager + + return options +} + +module.exports = configureOptions diff --git a/deps/npm/node_modules/make-fetch-happen/lib/remote.js b/deps/npm/node_modules/make-fetch-happen/lib/remote.js new file mode 100644 index 0000000000..e37f39de84 --- /dev/null +++ b/deps/npm/node_modules/make-fetch-happen/lib/remote.js @@ -0,0 +1,101 @@ +const Minipass = require('minipass') +const MinipassPipeline = require('minipass-pipeline') +const fetch = require('minipass-fetch') +const promiseRetry = require('promise-retry') +const ssri = require('ssri') + +const getAgent = require('./agent.js') +const pkg = require('../package.json') + +const USER_AGENT = `${pkg.name}/${pkg.version} (+https://npm.im/${pkg.name})` + +const RETRY_ERRORS = [ + 'ECONNRESET', // remote socket closed on us + 'ECONNREFUSED', // remote host refused to open connection + 'EADDRINUSE', // failed to bind to a local port (proxy?) + 'ETIMEDOUT', // someone in the transaction is WAY TOO SLOW + // Known codes we do NOT retry on: + // ENOTFOUND (getaddrinfo failure. Either bad hostname, or offline) +] + +const RETRY_TYPES = [ + 'request-timeout', +] + +// make a request directly to the remote source, +// retrying certain classes of errors as well as +// following redirects (through the cache if necessary) +// and verifying response integrity +const remoteFetch = (request, options) => { + const agent = getAgent(request.url, options) + if (!request.headers.has('connection')) + request.headers.set('connection', agent ? 'keep-alive' : 'close') + + if (!request.headers.has('user-agent')) + request.headers.set('user-agent', USER_AGENT) + + // keep our own options since we're overriding the agent + // and the redirect mode + const _opts = { + ...options, + agent, + redirect: 'manual', + } + + return promiseRetry(async (retryHandler, attemptNum) => { + const req = new fetch.Request(request, _opts) + try { + let res = await fetch(req, _opts) + if (_opts.integrity && res.status === 200) { + // we got a 200 response and the user has specified an expected + // integrity value, so wrap the response in an ssri stream to verify it + const integrityStream = ssri.integrityStream({ integrity: _opts.integrity }) + res = new fetch.Response(new MinipassPipeline(res.body, integrityStream), res) + } + + res.headers.set('x-fetch-attempts', attemptNum) + + // do not retry POST requests, or requests with a streaming body + // do retry requests with a 408, 420, 429 or 500+ status in the response + const isStream = Minipass.isStream(req.body) + const isRetriable = req.method !== 'POST' && + !isStream && + ([408, 420, 429].includes(res.status) || res.status >= 500) + + if (isRetriable) { + if (typeof options.onRetry === 'function') + options.onRetry(res) + + return retryHandler(res) + } + + return res + } catch (err) { + const code = (err.code === 'EPROMISERETRY') + ? err.retried.code + : err.code + + // err.retried will be the thing that was thrown from above + // if it's a response, we just got a bad status code and we + // can re-throw to allow the retry + const isRetryError = err.retried instanceof fetch.Response || + (RETRY_ERRORS.includes(code) && RETRY_TYPES.includes(err.type)) + + if (req.method === 'POST' || isRetryError) + throw err + + if (typeof options.onRetry === 'function') + options.onRetry(err) + + return retryHandler(err) + } + }, options.retry).catch((err) => { + // don't reject for http errors, just return them + if (err.status >= 400 && err.type !== 'system') + return err + + throw err + }) +} + +module.exports = remoteFetch diff --git a/deps/npm/node_modules/make-fetch-happen/package.json b/deps/npm/node_modules/make-fetch-happen/package.json index 7e854dcdf0..af97a161c6 100644 --- a/deps/npm/node_modules/make-fetch-happen/package.json +++ b/deps/npm/node_modules/make-fetch-happen/package.json @@ -1,21 +1,19 @@ { "name": "make-fetch-happen", - "version": "8.0.14", + "version": "9.0.2", "description": "Opinionated, caching, retrying fetch client", - "main": "index.js", + "main": "lib/index.js", "files": [ - "*.js", - "lib", - "utils" + "lib" ], "scripts": { "preversion": "npm t", "postversion": "npm publish", "prepublishOnly": "git push --follow-tags", - "test": "tap test/*.js", + "test": "tap", "posttest": "npm run lint", "eslint": "eslint", - "lint": "npm run eslint -- *.js utils test", + "lint": "npm run eslint -- lib test", "lintfix": "npm run lint -- --fix" }, "repository": "https://github.com/npm/make-fetch-happen", @@ -36,7 +34,7 @@ "license": "ISC", "dependencies": { "agentkeepalive": "^4.1.3", - "cacache": "^15.0.5", + "cacache": "^15.2.0", "http-cache-semantics": "^4.1.0", "http-proxy-agent": "^4.0.1", "https-proxy-agent": "^5.0.0", @@ -47,26 +45,32 @@ "minipass-fetch": "^1.3.2", "minipass-flush": "^1.0.5", "minipass-pipeline": "^1.2.4", + "negotiator": "^0.6.2", "promise-retry": "^2.0.1", "socks-proxy-agent": "^5.0.0", "ssri": "^8.0.0" }, "devDependencies": { - "eslint": "^7.14.0", - "eslint-plugin-import": "^2.22.1", + "eslint": "^7.26.0", + "eslint-plugin-import": "^2.23.2", "eslint-plugin-node": "^11.1.0", - "eslint-plugin-promise": "^4.2.1", + "eslint-plugin-promise": "^5.1.0", "eslint-plugin-standard": "^5.0.0", "mkdirp": "^1.0.4", - "nock": "^11.9.1", + "nock": "^13.0.11", "npmlog": "^4.1.2", "require-inject": "^1.4.2", - "rimraf": "^2.7.1", + "rimraf": "^3.0.2", "safe-buffer": "^5.2.1", - "standard-version": "^7.1.0", - "tap": "^14.11.0" + "standard-version": "^9.3.0", + "tap": "^15.0.9" }, "engines": { "node": ">= 10" + }, + "tap": { + "color": 1, + "files": "test/*.js", + "check-coverage": true } } diff --git a/deps/npm/node_modules/make-fetch-happen/utils/configure-options.js b/deps/npm/node_modules/make-fetch-happen/utils/configure-options.js deleted file mode 100644 index 75ea5d15ec..0000000000 --- a/deps/npm/node_modules/make-fetch-happen/utils/configure-options.js +++ /dev/null @@ -1,32 +0,0 @@ -'use strict' - -const initializeCache = require('./initialize-cache') - -module.exports = function configureOptions (_opts) { - const opts = Object.assign({}, _opts || {}) - opts.method = (opts.method || 'GET').toUpperCase() - - if (!opts.retry) { - // opts.retry was falsy; set default - opts.retry = { retries: 0 } - } else { - if (typeof opts.retry !== 'object') { - // Shorthand - if (typeof opts.retry === 'number') - opts.retry = { retries: opts.retry } - - if (typeof opts.retry === 'string') { - const value = parseInt(opts.retry, 10) - opts.retry = (value) ? { retries: value } : { retries: 0 } - } - } else { - // Set default retries - opts.retry = Object.assign({}, { retries: 0 }, opts.retry) - } - } - - if (opts.cacheManager) - initializeCache(opts) - - return opts -} diff --git a/deps/npm/node_modules/make-fetch-happen/utils/initialize-cache.js b/deps/npm/node_modules/make-fetch-happen/utils/initialize-cache.js deleted file mode 100644 index 9f96bf5622..0000000000 --- a/deps/npm/node_modules/make-fetch-happen/utils/initialize-cache.js +++ /dev/null @@ -1,26 +0,0 @@ -'use strict' - -const isHeaderConditional = require('./is-header-conditional') -// Default cacache-based cache -const Cache = require('../cache') - -module.exports = function initializeCache (opts) { - /** - * NOTE: `opts.cacheManager` is the path to cache - * We're making the assumption that if `opts.cacheManager` *isn't* a string, - * it's a cache object - */ - if (typeof opts.cacheManager === 'string') { - // Need to make a cache object - opts.cacheManager = new Cache(opts.cacheManager, opts) - } - - opts.cache = opts.cache || 'default' - - if (opts.cache === 'default' && isHeaderConditional(opts.headers)) { - // If header list contains `If-Modified-Since`, `If-None-Match`, - // `If-Unmodified-Since`, `If-Match`, or `If-Range`, fetch will set cache - // mode to "no-store" if it is "default". - opts.cache = 'no-store' - } -} diff --git a/deps/npm/node_modules/make-fetch-happen/utils/is-header-conditional.js b/deps/npm/node_modules/make-fetch-happen/utils/is-header-conditional.js deleted file mode 100644 index 5081e0ce12..0000000000 --- a/deps/npm/node_modules/make-fetch-happen/utils/is-header-conditional.js +++ /dev/null @@ -1,17 +0,0 @@ -'use strict' - -module.exports = function isHeaderConditional (headers) { - if (!headers || typeof headers !== 'object') - return false - - const modifiers = [ - 'if-modified-since', - 'if-none-match', - 'if-unmodified-since', - 'if-match', - 'if-range', - ] - - return Object.keys(headers) - .some(h => modifiers.indexOf(h.toLowerCase()) !== -1) -} diff --git a/deps/npm/node_modules/make-fetch-happen/utils/iterable-to-object.js b/deps/npm/node_modules/make-fetch-happen/utils/iterable-to-object.js deleted file mode 100644 index 1fe5ba6544..0000000000 --- a/deps/npm/node_modules/make-fetch-happen/utils/iterable-to-object.js +++ /dev/null @@ -1,9 +0,0 @@ -'use strict' - -module.exports = function iterableToObject (iter) { - const obj = {} - for (const k of iter.keys()) - obj[k] = iter.get(k) - - return obj -} diff --git a/deps/npm/node_modules/make-fetch-happen/utils/make-policy.js b/deps/npm/node_modules/make-fetch-happen/utils/make-policy.js deleted file mode 100644 index 5e884847dd..0000000000 --- a/deps/npm/node_modules/make-fetch-happen/utils/make-policy.js +++ /dev/null @@ -1,19 +0,0 @@ -'use strict' - -const CachePolicy = require('http-cache-semantics') - -const iterableToObject = require('./iterable-to-object') - -module.exports = function makePolicy (req, res) { - const _req = { - url: req.url, - method: req.method, - headers: iterableToObject(req.headers), - } - const _res = { - status: res.status, - headers: iterableToObject(res.headers), - } - - return new CachePolicy(_req, _res, { shared: false }) -} diff --git a/deps/npm/node_modules/make-fetch-happen/warning.js b/deps/npm/node_modules/make-fetch-happen/warning.js deleted file mode 100644 index 2b96024714..0000000000 --- a/deps/npm/node_modules/make-fetch-happen/warning.js +++ /dev/null @@ -1,24 +0,0 @@ -const url = require('url') - -module.exports = setWarning - -function setWarning (reqOrRes, code, message, replace) { - // Warning = "Warning" ":" 1#warning-value - // warning-value = warn-code SP warn-agent SP warn-text [SP warn-date] - // warn-code = 3DIGIT - // warn-agent = ( host [ ":" port ] ) | pseudonym - // ; the name or pseudonym of the server adding - // ; the Warning header, for use in debugging - // warn-text = quoted-string - // warn-date = <"> HTTP-date <"> - // (https://tools.ietf.org/html/rfc2616#section-14.46) - const host = new url.URL(reqOrRes.url).host - const jsonMessage = JSON.stringify(message) - const jsonDate = JSON.stringify(new Date().toUTCString()) - const header = replace ? 'set' : 'append' - - reqOrRes.headers[header]( - 'Warning', - `${code} ${host} ${jsonMessage} ${jsonDate}` - ) -} |