cdk-ecr-deployment 0.0.75 → 0.0.81
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitattributes +20 -21
- package/.jsii +43 -35
- package/lambda/Dockerfile +25 -0
- package/lambda/install.js +64 -0
- package/lib/index.js +40 -23
- package/node_modules/@sindresorhus/is/dist/index.d.ts +225 -0
- package/node_modules/@sindresorhus/is/dist/index.js +427 -0
- package/node_modules/@sindresorhus/is/dist/types.d.ts +24 -0
- package/node_modules/@sindresorhus/is/dist/types.js +3 -0
- package/node_modules/@sindresorhus/is/license +9 -0
- package/node_modules/@sindresorhus/is/package.json +96 -0
- package/node_modules/@sindresorhus/is/readme.md +628 -0
- package/node_modules/@szmarczak/http-timer/LICENSE +21 -0
- package/node_modules/@szmarczak/http-timer/README.md +93 -0
- package/node_modules/@szmarczak/http-timer/dist/source/index.d.ts +32 -0
- package/node_modules/@szmarczak/http-timer/dist/source/index.js +126 -0
- package/node_modules/@szmarczak/http-timer/package.json +72 -0
- package/node_modules/@types/cacheable-request/LICENSE +21 -0
- package/node_modules/@types/cacheable-request/README.md +16 -0
- package/node_modules/@types/cacheable-request/index.d.ts +137 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/LICENSE +21 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/README.md +16 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/assert/strict.d.ts +8 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/assert.d.ts +912 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/async_hooks.d.ts +497 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/buffer.d.ts +2142 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/child_process.d.ts +1366 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/cluster.d.ts +414 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/console.d.ts +412 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/constants.d.ts +18 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/crypto.d.ts +3307 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/dgram.d.ts +545 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/diagnostics_channel.d.ts +134 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/dns/promises.d.ts +368 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/dns.d.ts +654 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/domain.d.ts +169 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/events.d.ts +623 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/fs/promises.d.ts +1091 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/fs.d.ts +3784 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/globals.d.ts +284 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/globals.global.d.ts +1 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/http.d.ts +1369 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/http2.d.ts +2100 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/https.d.ts +391 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/index.d.ts +131 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/inspector.d.ts +2745 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/module.d.ts +114 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/net.d.ts +783 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/os.d.ts +455 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/package.json +230 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/path.d.ts +172 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/perf_hooks.d.ts +555 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/process.d.ts +1481 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/punycode.d.ts +117 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/querystring.d.ts +131 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/readline.d.ts +543 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/repl.d.ts +424 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/stream/consumers.d.ts +24 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/stream/promises.d.ts +42 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/stream/web.d.ts +6 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/stream.d.ts +1249 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/string_decoder.d.ts +67 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/timers/promises.d.ts +68 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/timers.d.ts +94 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/tls.d.ts +1019 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/trace_events.d.ts +161 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/tty.d.ts +204 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/url.d.ts +821 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/util.d.ts +1594 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/v8.d.ts +378 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/vm.d.ts +507 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/wasi.d.ts +158 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/worker_threads.d.ts +649 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/zlib.d.ts +517 -0
- package/node_modules/@types/cacheable-request/package.json +35 -0
- package/node_modules/@types/http-cache-semantics/LICENSE +21 -0
- package/node_modules/@types/http-cache-semantics/README.md +16 -0
- package/node_modules/@types/http-cache-semantics/index.d.ts +170 -0
- package/node_modules/@types/http-cache-semantics/package.json +25 -0
- package/node_modules/@types/keyv/LICENSE +21 -0
- package/node_modules/@types/keyv/README.md +16 -0
- package/node_modules/@types/keyv/index.d.ts +77 -0
- package/node_modules/@types/keyv/node_modules/@types/node/LICENSE +21 -0
- package/node_modules/@types/keyv/node_modules/@types/node/README.md +16 -0
- package/node_modules/@types/keyv/node_modules/@types/node/assert/strict.d.ts +8 -0
- package/node_modules/@types/keyv/node_modules/@types/node/assert.d.ts +912 -0
- package/node_modules/@types/keyv/node_modules/@types/node/async_hooks.d.ts +497 -0
- package/node_modules/@types/keyv/node_modules/@types/node/buffer.d.ts +2142 -0
- package/node_modules/@types/keyv/node_modules/@types/node/child_process.d.ts +1366 -0
- package/node_modules/@types/keyv/node_modules/@types/node/cluster.d.ts +414 -0
- package/node_modules/@types/keyv/node_modules/@types/node/console.d.ts +412 -0
- package/node_modules/@types/keyv/node_modules/@types/node/constants.d.ts +18 -0
- package/node_modules/@types/keyv/node_modules/@types/node/crypto.d.ts +3307 -0
- package/node_modules/@types/keyv/node_modules/@types/node/dgram.d.ts +545 -0
- package/node_modules/@types/keyv/node_modules/@types/node/diagnostics_channel.d.ts +134 -0
- package/node_modules/@types/keyv/node_modules/@types/node/dns/promises.d.ts +368 -0
- package/node_modules/@types/keyv/node_modules/@types/node/dns.d.ts +654 -0
- package/node_modules/@types/keyv/node_modules/@types/node/domain.d.ts +169 -0
- package/node_modules/@types/keyv/node_modules/@types/node/events.d.ts +623 -0
- package/node_modules/@types/keyv/node_modules/@types/node/fs/promises.d.ts +1091 -0
- package/node_modules/@types/keyv/node_modules/@types/node/fs.d.ts +3784 -0
- package/node_modules/@types/keyv/node_modules/@types/node/globals.d.ts +284 -0
- package/node_modules/@types/keyv/node_modules/@types/node/globals.global.d.ts +1 -0
- package/node_modules/@types/keyv/node_modules/@types/node/http.d.ts +1369 -0
- package/node_modules/@types/keyv/node_modules/@types/node/http2.d.ts +2100 -0
- package/node_modules/@types/keyv/node_modules/@types/node/https.d.ts +391 -0
- package/node_modules/@types/keyv/node_modules/@types/node/index.d.ts +131 -0
- package/node_modules/@types/keyv/node_modules/@types/node/inspector.d.ts +2745 -0
- package/node_modules/@types/keyv/node_modules/@types/node/module.d.ts +114 -0
- package/node_modules/@types/keyv/node_modules/@types/node/net.d.ts +783 -0
- package/node_modules/@types/keyv/node_modules/@types/node/os.d.ts +455 -0
- package/node_modules/@types/keyv/node_modules/@types/node/package.json +230 -0
- package/node_modules/@types/keyv/node_modules/@types/node/path.d.ts +172 -0
- package/node_modules/@types/keyv/node_modules/@types/node/perf_hooks.d.ts +555 -0
- package/node_modules/@types/keyv/node_modules/@types/node/process.d.ts +1481 -0
- package/node_modules/@types/keyv/node_modules/@types/node/punycode.d.ts +117 -0
- package/node_modules/@types/keyv/node_modules/@types/node/querystring.d.ts +131 -0
- package/node_modules/@types/keyv/node_modules/@types/node/readline.d.ts +543 -0
- package/node_modules/@types/keyv/node_modules/@types/node/repl.d.ts +424 -0
- package/node_modules/@types/keyv/node_modules/@types/node/stream/consumers.d.ts +24 -0
- package/node_modules/@types/keyv/node_modules/@types/node/stream/promises.d.ts +42 -0
- package/node_modules/@types/keyv/node_modules/@types/node/stream/web.d.ts +6 -0
- package/node_modules/@types/keyv/node_modules/@types/node/stream.d.ts +1249 -0
- package/node_modules/@types/keyv/node_modules/@types/node/string_decoder.d.ts +67 -0
- package/node_modules/@types/keyv/node_modules/@types/node/timers/promises.d.ts +68 -0
- package/node_modules/@types/keyv/node_modules/@types/node/timers.d.ts +94 -0
- package/node_modules/@types/keyv/node_modules/@types/node/tls.d.ts +1019 -0
- package/node_modules/@types/keyv/node_modules/@types/node/trace_events.d.ts +161 -0
- package/node_modules/@types/keyv/node_modules/@types/node/tty.d.ts +204 -0
- package/node_modules/@types/keyv/node_modules/@types/node/url.d.ts +821 -0
- package/node_modules/@types/keyv/node_modules/@types/node/util.d.ts +1594 -0
- package/node_modules/@types/keyv/node_modules/@types/node/v8.d.ts +378 -0
- package/node_modules/@types/keyv/node_modules/@types/node/vm.d.ts +507 -0
- package/node_modules/@types/keyv/node_modules/@types/node/wasi.d.ts +158 -0
- package/node_modules/@types/keyv/node_modules/@types/node/worker_threads.d.ts +649 -0
- package/node_modules/@types/keyv/node_modules/@types/node/zlib.d.ts +517 -0
- package/node_modules/@types/keyv/package.json +32 -0
- package/node_modules/@types/responselike/LICENSE +21 -0
- package/node_modules/@types/responselike/README.md +16 -0
- package/node_modules/@types/responselike/index.d.ts +34 -0
- package/node_modules/@types/responselike/node_modules/@types/node/LICENSE +21 -0
- package/node_modules/@types/responselike/node_modules/@types/node/README.md +16 -0
- package/node_modules/@types/responselike/node_modules/@types/node/assert/strict.d.ts +8 -0
- package/node_modules/@types/responselike/node_modules/@types/node/assert.d.ts +912 -0
- package/node_modules/@types/responselike/node_modules/@types/node/async_hooks.d.ts +497 -0
- package/node_modules/@types/responselike/node_modules/@types/node/buffer.d.ts +2142 -0
- package/node_modules/@types/responselike/node_modules/@types/node/child_process.d.ts +1366 -0
- package/node_modules/@types/responselike/node_modules/@types/node/cluster.d.ts +414 -0
- package/node_modules/@types/responselike/node_modules/@types/node/console.d.ts +412 -0
- package/node_modules/@types/responselike/node_modules/@types/node/constants.d.ts +18 -0
- package/node_modules/@types/responselike/node_modules/@types/node/crypto.d.ts +3307 -0
- package/node_modules/@types/responselike/node_modules/@types/node/dgram.d.ts +545 -0
- package/node_modules/@types/responselike/node_modules/@types/node/diagnostics_channel.d.ts +134 -0
- package/node_modules/@types/responselike/node_modules/@types/node/dns/promises.d.ts +368 -0
- package/node_modules/@types/responselike/node_modules/@types/node/dns.d.ts +654 -0
- package/node_modules/@types/responselike/node_modules/@types/node/domain.d.ts +169 -0
- package/node_modules/@types/responselike/node_modules/@types/node/events.d.ts +623 -0
- package/node_modules/@types/responselike/node_modules/@types/node/fs/promises.d.ts +1091 -0
- package/node_modules/@types/responselike/node_modules/@types/node/fs.d.ts +3784 -0
- package/node_modules/@types/responselike/node_modules/@types/node/globals.d.ts +284 -0
- package/node_modules/@types/responselike/node_modules/@types/node/globals.global.d.ts +1 -0
- package/node_modules/@types/responselike/node_modules/@types/node/http.d.ts +1369 -0
- package/node_modules/@types/responselike/node_modules/@types/node/http2.d.ts +2100 -0
- package/node_modules/@types/responselike/node_modules/@types/node/https.d.ts +391 -0
- package/node_modules/@types/responselike/node_modules/@types/node/index.d.ts +131 -0
- package/node_modules/@types/responselike/node_modules/@types/node/inspector.d.ts +2745 -0
- package/node_modules/@types/responselike/node_modules/@types/node/module.d.ts +114 -0
- package/node_modules/@types/responselike/node_modules/@types/node/net.d.ts +783 -0
- package/node_modules/@types/responselike/node_modules/@types/node/os.d.ts +455 -0
- package/node_modules/@types/responselike/node_modules/@types/node/package.json +230 -0
- package/node_modules/@types/responselike/node_modules/@types/node/path.d.ts +172 -0
- package/node_modules/@types/responselike/node_modules/@types/node/perf_hooks.d.ts +555 -0
- package/node_modules/@types/responselike/node_modules/@types/node/process.d.ts +1481 -0
- package/node_modules/@types/responselike/node_modules/@types/node/punycode.d.ts +117 -0
- package/node_modules/@types/responselike/node_modules/@types/node/querystring.d.ts +131 -0
- package/node_modules/@types/responselike/node_modules/@types/node/readline.d.ts +543 -0
- package/node_modules/@types/responselike/node_modules/@types/node/repl.d.ts +424 -0
- package/node_modules/@types/responselike/node_modules/@types/node/stream/consumers.d.ts +24 -0
- package/node_modules/@types/responselike/node_modules/@types/node/stream/promises.d.ts +42 -0
- package/node_modules/@types/responselike/node_modules/@types/node/stream/web.d.ts +6 -0
- package/node_modules/@types/responselike/node_modules/@types/node/stream.d.ts +1249 -0
- package/node_modules/@types/responselike/node_modules/@types/node/string_decoder.d.ts +67 -0
- package/node_modules/@types/responselike/node_modules/@types/node/timers/promises.d.ts +68 -0
- package/node_modules/@types/responselike/node_modules/@types/node/timers.d.ts +94 -0
- package/node_modules/@types/responselike/node_modules/@types/node/tls.d.ts +1019 -0
- package/node_modules/@types/responselike/node_modules/@types/node/trace_events.d.ts +161 -0
- package/node_modules/@types/responselike/node_modules/@types/node/tty.d.ts +204 -0
- package/node_modules/@types/responselike/node_modules/@types/node/url.d.ts +821 -0
- package/node_modules/@types/responselike/node_modules/@types/node/util.d.ts +1594 -0
- package/node_modules/@types/responselike/node_modules/@types/node/v8.d.ts +378 -0
- package/node_modules/@types/responselike/node_modules/@types/node/vm.d.ts +507 -0
- package/node_modules/@types/responselike/node_modules/@types/node/wasi.d.ts +158 -0
- package/node_modules/@types/responselike/node_modules/@types/node/worker_threads.d.ts +649 -0
- package/node_modules/@types/responselike/node_modules/@types/node/zlib.d.ts +517 -0
- package/node_modules/@types/responselike/package.json +25 -0
- package/node_modules/cacheable-lookup/LICENSE +21 -0
- package/node_modules/cacheable-lookup/README.md +240 -0
- package/node_modules/cacheable-lookup/index.d.ts +139 -0
- package/node_modules/cacheable-lookup/package.json +45 -0
- package/node_modules/cacheable-lookup/source/index.js +436 -0
- package/node_modules/cacheable-request/LICENSE +21 -0
- package/node_modules/cacheable-request/README.md +206 -0
- package/node_modules/cacheable-request/package.json +56 -0
- package/node_modules/cacheable-request/src/index.js +251 -0
- package/node_modules/clone-response/LICENSE +21 -0
- package/node_modules/clone-response/README.md +62 -0
- package/node_modules/clone-response/package.json +44 -0
- package/node_modules/clone-response/src/index.js +17 -0
- package/node_modules/decompress-response/index.d.ts +22 -0
- package/node_modules/decompress-response/index.js +58 -0
- package/node_modules/decompress-response/license +9 -0
- package/node_modules/decompress-response/node_modules/mimic-response/index.d.ts +17 -0
- package/node_modules/decompress-response/node_modules/mimic-response/index.js +77 -0
- package/node_modules/decompress-response/node_modules/mimic-response/license +9 -0
- package/node_modules/decompress-response/node_modules/mimic-response/package.json +42 -0
- package/node_modules/decompress-response/node_modules/mimic-response/readme.md +78 -0
- package/node_modules/decompress-response/package.json +56 -0
- package/node_modules/decompress-response/readme.md +48 -0
- package/node_modules/defer-to-connect/LICENSE +21 -0
- package/node_modules/defer-to-connect/README.md +38 -0
- package/node_modules/defer-to-connect/dist/source/index.d.ts +10 -0
- package/node_modules/defer-to-connect/dist/source/index.js +47 -0
- package/node_modules/defer-to-connect/package.json +71 -0
- package/node_modules/end-of-stream/LICENSE +21 -0
- package/node_modules/end-of-stream/README.md +54 -0
- package/node_modules/end-of-stream/index.js +94 -0
- package/node_modules/end-of-stream/package.json +37 -0
- package/node_modules/get-stream/buffer-stream.js +52 -0
- package/node_modules/get-stream/index.d.ts +108 -0
- package/node_modules/get-stream/index.js +60 -0
- package/node_modules/get-stream/license +9 -0
- package/node_modules/get-stream/package.json +50 -0
- package/node_modules/get-stream/readme.md +124 -0
- package/node_modules/got/dist/source/as-promise/create-rejection.d.ts +2 -0
- package/node_modules/got/dist/source/as-promise/create-rejection.js +30 -0
- package/node_modules/got/dist/source/as-promise/index.d.ts +3 -0
- package/node_modules/got/dist/source/as-promise/index.js +175 -0
- package/node_modules/got/dist/source/as-promise/normalize-arguments.d.ts +3 -0
- package/node_modules/got/dist/source/as-promise/normalize-arguments.js +78 -0
- package/node_modules/got/dist/source/as-promise/parse-body.d.ts +3 -0
- package/node_modules/got/dist/source/as-promise/parse-body.js +25 -0
- package/node_modules/got/dist/source/as-promise/types.d.ts +256 -0
- package/node_modules/got/dist/source/as-promise/types.js +40 -0
- package/node_modules/got/dist/source/core/calculate-retry-delay.d.ts +5 -0
- package/node_modules/got/dist/source/core/calculate-retry-delay.js +29 -0
- package/node_modules/got/dist/source/core/index.d.ts +1124 -0
- package/node_modules/got/dist/source/core/index.js +1491 -0
- package/node_modules/got/dist/source/core/utils/dns-ip-version.d.ts +5 -0
- package/node_modules/got/dist/source/core/utils/dns-ip-version.js +17 -0
- package/node_modules/got/dist/source/core/utils/get-body-size.d.ts +3 -0
- package/node_modules/got/dist/source/core/utils/get-body-size.js +32 -0
- package/node_modules/got/dist/source/core/utils/get-buffer.d.ts +4 -0
- package/node_modules/got/dist/source/core/utils/get-buffer.js +16 -0
- package/node_modules/got/dist/source/core/utils/is-form-data.d.ts +8 -0
- package/node_modules/got/dist/source/core/utils/is-form-data.js +4 -0
- package/node_modules/got/dist/source/core/utils/is-response-ok.d.ts +2 -0
- package/node_modules/got/dist/source/core/utils/is-response-ok.js +8 -0
- package/node_modules/got/dist/source/core/utils/options-to-url.d.ts +14 -0
- package/node_modules/got/dist/source/core/utils/options-to-url.js +53 -0
- package/node_modules/got/dist/source/core/utils/proxy-events.d.ts +3 -0
- package/node_modules/got/dist/source/core/utils/proxy-events.js +17 -0
- package/node_modules/got/dist/source/core/utils/timed-out.d.ts +29 -0
- package/node_modules/got/dist/source/core/utils/timed-out.js +121 -0
- package/node_modules/got/dist/source/core/utils/unhandle.d.ts +11 -0
- package/node_modules/got/dist/source/core/utils/unhandle.js +22 -0
- package/node_modules/got/dist/source/core/utils/url-to-options.d.ts +15 -0
- package/node_modules/got/dist/source/core/utils/url-to-options.js +24 -0
- package/node_modules/got/dist/source/core/utils/weakable-map.d.ts +8 -0
- package/node_modules/got/dist/source/core/utils/weakable-map.js +29 -0
- package/node_modules/got/dist/source/create.d.ts +5 -0
- package/node_modules/got/dist/source/create.js +240 -0
- package/node_modules/got/dist/source/index.d.ts +4 -0
- package/node_modules/got/dist/source/index.js +132 -0
- package/node_modules/got/dist/source/types.d.ts +342 -0
- package/node_modules/got/dist/source/types.js +2 -0
- package/node_modules/got/dist/source/utils/deep-freeze.d.ts +1 -0
- package/node_modules/got/dist/source/utils/deep-freeze.js +12 -0
- package/node_modules/got/dist/source/utils/deprecation-warning.d.ts +2 -0
- package/node_modules/got/dist/source/utils/deprecation-warning.js +13 -0
- package/node_modules/got/license +9 -0
- package/node_modules/got/package.json +130 -0
- package/node_modules/got/readme.md +2476 -0
- package/node_modules/http-cache-semantics/LICENSE +9 -0
- package/node_modules/http-cache-semantics/README.md +203 -0
- package/node_modules/http-cache-semantics/index.js +673 -0
- package/node_modules/http-cache-semantics/package.json +24 -0
- package/node_modules/http2-wrapper/LICENSE +21 -0
- package/node_modules/http2-wrapper/README.md +470 -0
- package/node_modules/http2-wrapper/package.json +54 -0
- package/node_modules/http2-wrapper/source/agent.js +670 -0
- package/node_modules/http2-wrapper/source/auto.js +149 -0
- package/node_modules/http2-wrapper/source/client-request.js +445 -0
- package/node_modules/http2-wrapper/source/incoming-message.js +58 -0
- package/node_modules/http2-wrapper/source/index.js +28 -0
- package/node_modules/http2-wrapper/source/utils/calculate-server-name.js +27 -0
- package/node_modules/http2-wrapper/source/utils/errors.js +45 -0
- package/node_modules/http2-wrapper/source/utils/is-request-pseudo-header.js +13 -0
- package/node_modules/http2-wrapper/source/utils/proxy-events.js +7 -0
- package/node_modules/http2-wrapper/source/utils/url-to-options.js +25 -0
- package/node_modules/json-buffer/.travis.yml +3 -0
- package/node_modules/json-buffer/LICENSE +22 -0
- package/node_modules/json-buffer/README.md +24 -0
- package/node_modules/json-buffer/index.js +58 -0
- package/node_modules/json-buffer/package.json +34 -0
- package/node_modules/json-buffer/test/index.js +63 -0
- package/node_modules/keyv/LICENSE +21 -0
- package/node_modules/keyv/README.md +288 -0
- package/node_modules/keyv/package.json +49 -0
- package/node_modules/keyv/src/index.js +111 -0
- package/node_modules/lowercase-keys/index.d.ts +16 -0
- package/node_modules/lowercase-keys/index.js +10 -0
- package/node_modules/lowercase-keys/license +9 -0
- package/node_modules/lowercase-keys/package.json +38 -0
- package/node_modules/lowercase-keys/readme.md +32 -0
- package/node_modules/mimic-response/index.js +32 -0
- package/node_modules/mimic-response/license +9 -0
- package/node_modules/mimic-response/package.json +37 -0
- package/node_modules/mimic-response/readme.md +54 -0
- package/node_modules/normalize-url/index.d.ts +267 -0
- package/node_modules/normalize-url/index.js +216 -0
- package/node_modules/normalize-url/license +9 -0
- package/node_modules/normalize-url/package.json +50 -0
- package/node_modules/normalize-url/readme.md +286 -0
- package/node_modules/once/LICENSE +15 -0
- package/node_modules/once/README.md +79 -0
- package/node_modules/once/once.js +42 -0
- package/node_modules/once/package.json +33 -0
- package/node_modules/p-cancelable/index.d.ts +176 -0
- package/node_modules/p-cancelable/index.js +111 -0
- package/node_modules/p-cancelable/license +9 -0
- package/node_modules/p-cancelable/package.json +49 -0
- package/node_modules/p-cancelable/readme.md +153 -0
- package/node_modules/pump/.travis.yml +5 -0
- package/node_modules/pump/LICENSE +21 -0
- package/node_modules/pump/README.md +65 -0
- package/node_modules/pump/index.js +82 -0
- package/node_modules/pump/package.json +24 -0
- package/node_modules/pump/test-browser.js +66 -0
- package/node_modules/pump/test-node.js +53 -0
- package/node_modules/quick-lru/index.d.ts +97 -0
- package/node_modules/quick-lru/index.js +123 -0
- package/node_modules/quick-lru/license +9 -0
- package/node_modules/quick-lru/package.json +43 -0
- package/node_modules/quick-lru/readme.md +111 -0
- package/node_modules/resolve-alpn/LICENSE +22 -0
- package/node_modules/resolve-alpn/README.md +60 -0
- package/node_modules/resolve-alpn/index.js +43 -0
- package/node_modules/resolve-alpn/package.json +34 -0
- package/node_modules/responselike/LICENSE +19 -0
- package/node_modules/responselike/README.md +77 -0
- package/node_modules/responselike/package.json +38 -0
- package/node_modules/responselike/src/index.js +34 -0
- package/node_modules/wrappy/LICENSE +15 -0
- package/node_modules/wrappy/README.md +36 -0
- package/node_modules/wrappy/package.json +29 -0
- package/node_modules/wrappy/wrappy.js +33 -0
- package/package.json +41 -38
|
@@ -0,0 +1,1491 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UnsupportedProtocolError = exports.ReadError = exports.TimeoutError = exports.UploadError = exports.CacheError = exports.HTTPError = exports.MaxRedirectsError = exports.RequestError = exports.setNonEnumerableProperties = exports.knownHookEvents = exports.withoutBody = exports.kIsNormalizedAlready = void 0;
|
|
4
|
+
const util_1 = require("util");
|
|
5
|
+
const stream_1 = require("stream");
|
|
6
|
+
const fs_1 = require("fs");
|
|
7
|
+
const url_1 = require("url");
|
|
8
|
+
const http = require("http");
|
|
9
|
+
const http_1 = require("http");
|
|
10
|
+
const https = require("https");
|
|
11
|
+
const http_timer_1 = require("@szmarczak/http-timer");
|
|
12
|
+
const cacheable_lookup_1 = require("cacheable-lookup");
|
|
13
|
+
const CacheableRequest = require("cacheable-request");
|
|
14
|
+
const decompressResponse = require("decompress-response");
|
|
15
|
+
// @ts-expect-error Missing types
|
|
16
|
+
const http2wrapper = require("http2-wrapper");
|
|
17
|
+
const lowercaseKeys = require("lowercase-keys");
|
|
18
|
+
const is_1 = require("@sindresorhus/is");
|
|
19
|
+
const get_body_size_1 = require("./utils/get-body-size");
|
|
20
|
+
const is_form_data_1 = require("./utils/is-form-data");
|
|
21
|
+
const proxy_events_1 = require("./utils/proxy-events");
|
|
22
|
+
const timed_out_1 = require("./utils/timed-out");
|
|
23
|
+
const url_to_options_1 = require("./utils/url-to-options");
|
|
24
|
+
const options_to_url_1 = require("./utils/options-to-url");
|
|
25
|
+
const weakable_map_1 = require("./utils/weakable-map");
|
|
26
|
+
const get_buffer_1 = require("./utils/get-buffer");
|
|
27
|
+
const dns_ip_version_1 = require("./utils/dns-ip-version");
|
|
28
|
+
const is_response_ok_1 = require("./utils/is-response-ok");
|
|
29
|
+
const deprecation_warning_1 = require("../utils/deprecation-warning");
|
|
30
|
+
const normalize_arguments_1 = require("../as-promise/normalize-arguments");
|
|
31
|
+
const calculate_retry_delay_1 = require("./calculate-retry-delay");
|
|
32
|
+
let globalDnsCache;
|
|
33
|
+
const kRequest = Symbol('request');
|
|
34
|
+
const kResponse = Symbol('response');
|
|
35
|
+
const kResponseSize = Symbol('responseSize');
|
|
36
|
+
const kDownloadedSize = Symbol('downloadedSize');
|
|
37
|
+
const kBodySize = Symbol('bodySize');
|
|
38
|
+
const kUploadedSize = Symbol('uploadedSize');
|
|
39
|
+
const kServerResponsesPiped = Symbol('serverResponsesPiped');
|
|
40
|
+
const kUnproxyEvents = Symbol('unproxyEvents');
|
|
41
|
+
const kIsFromCache = Symbol('isFromCache');
|
|
42
|
+
const kCancelTimeouts = Symbol('cancelTimeouts');
|
|
43
|
+
const kStartedReading = Symbol('startedReading');
|
|
44
|
+
const kStopReading = Symbol('stopReading');
|
|
45
|
+
const kTriggerRead = Symbol('triggerRead');
|
|
46
|
+
const kBody = Symbol('body');
|
|
47
|
+
const kJobs = Symbol('jobs');
|
|
48
|
+
const kOriginalResponse = Symbol('originalResponse');
|
|
49
|
+
const kRetryTimeout = Symbol('retryTimeout');
|
|
50
|
+
exports.kIsNormalizedAlready = Symbol('isNormalizedAlready');
|
|
51
|
+
const supportsBrotli = is_1.default.string(process.versions.brotli);
|
|
52
|
+
exports.withoutBody = new Set(['GET', 'HEAD']);
|
|
53
|
+
exports.knownHookEvents = [
|
|
54
|
+
'init',
|
|
55
|
+
'beforeRequest',
|
|
56
|
+
'beforeRedirect',
|
|
57
|
+
'beforeError',
|
|
58
|
+
'beforeRetry',
|
|
59
|
+
// Promise-Only
|
|
60
|
+
'afterResponse'
|
|
61
|
+
];
|
|
62
|
+
function validateSearchParameters(searchParameters) {
|
|
63
|
+
// eslint-disable-next-line guard-for-in
|
|
64
|
+
for (const key in searchParameters) {
|
|
65
|
+
const value = searchParameters[key];
|
|
66
|
+
if (!is_1.default.string(value) && !is_1.default.number(value) && !is_1.default.boolean(value) && !is_1.default.null_(value) && !is_1.default.undefined(value)) {
|
|
67
|
+
throw new TypeError(`The \`searchParams\` value '${String(value)}' must be a string, number, boolean or null`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function isClientRequest(clientRequest) {
|
|
72
|
+
return is_1.default.object(clientRequest) && !('statusCode' in clientRequest);
|
|
73
|
+
}
|
|
74
|
+
const cacheableStore = new weakable_map_1.default();
|
|
75
|
+
const waitForOpenFile = async (file) => new Promise((resolve, reject) => {
|
|
76
|
+
const onError = (error) => {
|
|
77
|
+
reject(error);
|
|
78
|
+
};
|
|
79
|
+
// Node.js 12 has incomplete types
|
|
80
|
+
if (!file.pending) {
|
|
81
|
+
resolve();
|
|
82
|
+
}
|
|
83
|
+
file.once('error', onError);
|
|
84
|
+
file.once('ready', () => {
|
|
85
|
+
file.off('error', onError);
|
|
86
|
+
resolve();
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
const redirectCodes = new Set([300, 301, 302, 303, 304, 307, 308]);
|
|
90
|
+
const nonEnumerableProperties = [
|
|
91
|
+
'context',
|
|
92
|
+
'body',
|
|
93
|
+
'json',
|
|
94
|
+
'form'
|
|
95
|
+
];
|
|
96
|
+
exports.setNonEnumerableProperties = (sources, to) => {
|
|
97
|
+
// Non enumerable properties shall not be merged
|
|
98
|
+
const properties = {};
|
|
99
|
+
for (const source of sources) {
|
|
100
|
+
if (!source) {
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
for (const name of nonEnumerableProperties) {
|
|
104
|
+
if (!(name in source)) {
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
properties[name] = {
|
|
108
|
+
writable: true,
|
|
109
|
+
configurable: true,
|
|
110
|
+
enumerable: false,
|
|
111
|
+
// @ts-expect-error TS doesn't see the check above
|
|
112
|
+
value: source[name]
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
Object.defineProperties(to, properties);
|
|
117
|
+
};
|
|
118
|
+
/**
|
|
119
|
+
An error to be thrown when a request fails.
|
|
120
|
+
Contains a `code` property with error class code, like `ECONNREFUSED`.
|
|
121
|
+
*/
|
|
122
|
+
class RequestError extends Error {
|
|
123
|
+
constructor(message, error, self) {
|
|
124
|
+
var _a;
|
|
125
|
+
super(message);
|
|
126
|
+
Error.captureStackTrace(this, this.constructor);
|
|
127
|
+
this.name = 'RequestError';
|
|
128
|
+
this.code = error.code;
|
|
129
|
+
if (self instanceof Request) {
|
|
130
|
+
Object.defineProperty(this, 'request', {
|
|
131
|
+
enumerable: false,
|
|
132
|
+
value: self
|
|
133
|
+
});
|
|
134
|
+
Object.defineProperty(this, 'response', {
|
|
135
|
+
enumerable: false,
|
|
136
|
+
value: self[kResponse]
|
|
137
|
+
});
|
|
138
|
+
Object.defineProperty(this, 'options', {
|
|
139
|
+
// This fails because of TS 3.7.2 useDefineForClassFields
|
|
140
|
+
// Ref: https://github.com/microsoft/TypeScript/issues/34972
|
|
141
|
+
enumerable: false,
|
|
142
|
+
value: self.options
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
Object.defineProperty(this, 'options', {
|
|
147
|
+
// This fails because of TS 3.7.2 useDefineForClassFields
|
|
148
|
+
// Ref: https://github.com/microsoft/TypeScript/issues/34972
|
|
149
|
+
enumerable: false,
|
|
150
|
+
value: self
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
this.timings = (_a = this.request) === null || _a === void 0 ? void 0 : _a.timings;
|
|
154
|
+
// Recover the original stacktrace
|
|
155
|
+
if (is_1.default.string(error.stack) && is_1.default.string(this.stack)) {
|
|
156
|
+
const indexOfMessage = this.stack.indexOf(this.message) + this.message.length;
|
|
157
|
+
const thisStackTrace = this.stack.slice(indexOfMessage).split('\n').reverse();
|
|
158
|
+
const errorStackTrace = error.stack.slice(error.stack.indexOf(error.message) + error.message.length).split('\n').reverse();
|
|
159
|
+
// Remove duplicated traces
|
|
160
|
+
while (errorStackTrace.length !== 0 && errorStackTrace[0] === thisStackTrace[0]) {
|
|
161
|
+
thisStackTrace.shift();
|
|
162
|
+
}
|
|
163
|
+
this.stack = `${this.stack.slice(0, indexOfMessage)}${thisStackTrace.reverse().join('\n')}${errorStackTrace.reverse().join('\n')}`;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
exports.RequestError = RequestError;
|
|
168
|
+
/**
|
|
169
|
+
An error to be thrown when the server redirects you more than ten times.
|
|
170
|
+
Includes a `response` property.
|
|
171
|
+
*/
|
|
172
|
+
class MaxRedirectsError extends RequestError {
|
|
173
|
+
constructor(request) {
|
|
174
|
+
super(`Redirected ${request.options.maxRedirects} times. Aborting.`, {}, request);
|
|
175
|
+
this.name = 'MaxRedirectsError';
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
exports.MaxRedirectsError = MaxRedirectsError;
|
|
179
|
+
/**
|
|
180
|
+
An error to be thrown when the server response code is not 2xx nor 3xx if `options.followRedirect` is `true`, but always except for 304.
|
|
181
|
+
Includes a `response` property.
|
|
182
|
+
*/
|
|
183
|
+
class HTTPError extends RequestError {
|
|
184
|
+
constructor(response) {
|
|
185
|
+
super(`Response code ${response.statusCode} (${response.statusMessage})`, {}, response.request);
|
|
186
|
+
this.name = 'HTTPError';
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
exports.HTTPError = HTTPError;
|
|
190
|
+
/**
|
|
191
|
+
An error to be thrown when a cache method fails.
|
|
192
|
+
For example, if the database goes down or there's a filesystem error.
|
|
193
|
+
*/
|
|
194
|
+
class CacheError extends RequestError {
|
|
195
|
+
constructor(error, request) {
|
|
196
|
+
super(error.message, error, request);
|
|
197
|
+
this.name = 'CacheError';
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
exports.CacheError = CacheError;
|
|
201
|
+
/**
|
|
202
|
+
An error to be thrown when the request body is a stream and an error occurs while reading from that stream.
|
|
203
|
+
*/
|
|
204
|
+
class UploadError extends RequestError {
|
|
205
|
+
constructor(error, request) {
|
|
206
|
+
super(error.message, error, request);
|
|
207
|
+
this.name = 'UploadError';
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
exports.UploadError = UploadError;
|
|
211
|
+
/**
|
|
212
|
+
An error to be thrown when the request is aborted due to a timeout.
|
|
213
|
+
Includes an `event` and `timings` property.
|
|
214
|
+
*/
|
|
215
|
+
class TimeoutError extends RequestError {
|
|
216
|
+
constructor(error, timings, request) {
|
|
217
|
+
super(error.message, error, request);
|
|
218
|
+
this.name = 'TimeoutError';
|
|
219
|
+
this.event = error.event;
|
|
220
|
+
this.timings = timings;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
exports.TimeoutError = TimeoutError;
|
|
224
|
+
/**
|
|
225
|
+
An error to be thrown when reading from response stream fails.
|
|
226
|
+
*/
|
|
227
|
+
class ReadError extends RequestError {
|
|
228
|
+
constructor(error, request) {
|
|
229
|
+
super(error.message, error, request);
|
|
230
|
+
this.name = 'ReadError';
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
exports.ReadError = ReadError;
|
|
234
|
+
/**
|
|
235
|
+
An error to be thrown when given an unsupported protocol.
|
|
236
|
+
*/
|
|
237
|
+
class UnsupportedProtocolError extends RequestError {
|
|
238
|
+
constructor(options) {
|
|
239
|
+
super(`Unsupported protocol "${options.url.protocol}"`, {}, options);
|
|
240
|
+
this.name = 'UnsupportedProtocolError';
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
exports.UnsupportedProtocolError = UnsupportedProtocolError;
|
|
244
|
+
const proxiedRequestEvents = [
|
|
245
|
+
'socket',
|
|
246
|
+
'connect',
|
|
247
|
+
'continue',
|
|
248
|
+
'information',
|
|
249
|
+
'upgrade',
|
|
250
|
+
'timeout'
|
|
251
|
+
];
|
|
252
|
+
class Request extends stream_1.Duplex {
|
|
253
|
+
constructor(url, options = {}, defaults) {
|
|
254
|
+
super({
|
|
255
|
+
// This must be false, to enable throwing after destroy
|
|
256
|
+
// It is used for retry logic in Promise API
|
|
257
|
+
autoDestroy: false,
|
|
258
|
+
// It needs to be zero because we're just proxying the data to another stream
|
|
259
|
+
highWaterMark: 0
|
|
260
|
+
});
|
|
261
|
+
this[kDownloadedSize] = 0;
|
|
262
|
+
this[kUploadedSize] = 0;
|
|
263
|
+
this.requestInitialized = false;
|
|
264
|
+
this[kServerResponsesPiped] = new Set();
|
|
265
|
+
this.redirects = [];
|
|
266
|
+
this[kStopReading] = false;
|
|
267
|
+
this[kTriggerRead] = false;
|
|
268
|
+
this[kJobs] = [];
|
|
269
|
+
this.retryCount = 0;
|
|
270
|
+
// TODO: Remove this when targeting Node.js >= 12
|
|
271
|
+
this._progressCallbacks = [];
|
|
272
|
+
const unlockWrite = () => this._unlockWrite();
|
|
273
|
+
const lockWrite = () => this._lockWrite();
|
|
274
|
+
this.on('pipe', (source) => {
|
|
275
|
+
source.prependListener('data', unlockWrite);
|
|
276
|
+
source.on('data', lockWrite);
|
|
277
|
+
source.prependListener('end', unlockWrite);
|
|
278
|
+
source.on('end', lockWrite);
|
|
279
|
+
});
|
|
280
|
+
this.on('unpipe', (source) => {
|
|
281
|
+
source.off('data', unlockWrite);
|
|
282
|
+
source.off('data', lockWrite);
|
|
283
|
+
source.off('end', unlockWrite);
|
|
284
|
+
source.off('end', lockWrite);
|
|
285
|
+
});
|
|
286
|
+
this.on('pipe', source => {
|
|
287
|
+
if (source instanceof http_1.IncomingMessage) {
|
|
288
|
+
this.options.headers = {
|
|
289
|
+
...source.headers,
|
|
290
|
+
...this.options.headers
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
const { json, body, form } = options;
|
|
295
|
+
if (json || body || form) {
|
|
296
|
+
this._lockWrite();
|
|
297
|
+
}
|
|
298
|
+
if (exports.kIsNormalizedAlready in options) {
|
|
299
|
+
this.options = options;
|
|
300
|
+
}
|
|
301
|
+
else {
|
|
302
|
+
try {
|
|
303
|
+
// @ts-expect-error Common TypeScript bug saying that `this.constructor` is not accessible
|
|
304
|
+
this.options = this.constructor.normalizeArguments(url, options, defaults);
|
|
305
|
+
}
|
|
306
|
+
catch (error) {
|
|
307
|
+
// TODO: Move this to `_destroy()`
|
|
308
|
+
if (is_1.default.nodeStream(options.body)) {
|
|
309
|
+
options.body.destroy();
|
|
310
|
+
}
|
|
311
|
+
this.destroy(error);
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
(async () => {
|
|
316
|
+
var _a;
|
|
317
|
+
try {
|
|
318
|
+
if (this.options.body instanceof fs_1.ReadStream) {
|
|
319
|
+
await waitForOpenFile(this.options.body);
|
|
320
|
+
}
|
|
321
|
+
const { url: normalizedURL } = this.options;
|
|
322
|
+
if (!normalizedURL) {
|
|
323
|
+
throw new TypeError('Missing `url` property');
|
|
324
|
+
}
|
|
325
|
+
this.requestUrl = normalizedURL.toString();
|
|
326
|
+
decodeURI(this.requestUrl);
|
|
327
|
+
await this._finalizeBody();
|
|
328
|
+
await this._makeRequest();
|
|
329
|
+
if (this.destroyed) {
|
|
330
|
+
(_a = this[kRequest]) === null || _a === void 0 ? void 0 : _a.destroy();
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
// Queued writes etc.
|
|
334
|
+
for (const job of this[kJobs]) {
|
|
335
|
+
job();
|
|
336
|
+
}
|
|
337
|
+
// Prevent memory leak
|
|
338
|
+
this[kJobs].length = 0;
|
|
339
|
+
this.requestInitialized = true;
|
|
340
|
+
}
|
|
341
|
+
catch (error) {
|
|
342
|
+
if (error instanceof RequestError) {
|
|
343
|
+
this._beforeError(error);
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
// This is a workaround for https://github.com/nodejs/node/issues/33335
|
|
347
|
+
if (!this.destroyed) {
|
|
348
|
+
this.destroy(error);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
})();
|
|
352
|
+
}
|
|
353
|
+
static normalizeArguments(url, options, defaults) {
|
|
354
|
+
var _a, _b, _c, _d, _e;
|
|
355
|
+
const rawOptions = options;
|
|
356
|
+
if (is_1.default.object(url) && !is_1.default.urlInstance(url)) {
|
|
357
|
+
options = { ...defaults, ...url, ...options };
|
|
358
|
+
}
|
|
359
|
+
else {
|
|
360
|
+
if (url && options && options.url !== undefined) {
|
|
361
|
+
throw new TypeError('The `url` option is mutually exclusive with the `input` argument');
|
|
362
|
+
}
|
|
363
|
+
options = { ...defaults, ...options };
|
|
364
|
+
if (url !== undefined) {
|
|
365
|
+
options.url = url;
|
|
366
|
+
}
|
|
367
|
+
if (is_1.default.urlInstance(options.url)) {
|
|
368
|
+
options.url = new url_1.URL(options.url.toString());
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
// TODO: Deprecate URL options in Got 12.
|
|
372
|
+
// Support extend-specific options
|
|
373
|
+
if (options.cache === false) {
|
|
374
|
+
options.cache = undefined;
|
|
375
|
+
}
|
|
376
|
+
if (options.dnsCache === false) {
|
|
377
|
+
options.dnsCache = undefined;
|
|
378
|
+
}
|
|
379
|
+
// Nice type assertions
|
|
380
|
+
is_1.assert.any([is_1.default.string, is_1.default.undefined], options.method);
|
|
381
|
+
is_1.assert.any([is_1.default.object, is_1.default.undefined], options.headers);
|
|
382
|
+
is_1.assert.any([is_1.default.string, is_1.default.urlInstance, is_1.default.undefined], options.prefixUrl);
|
|
383
|
+
is_1.assert.any([is_1.default.object, is_1.default.undefined], options.cookieJar);
|
|
384
|
+
is_1.assert.any([is_1.default.object, is_1.default.string, is_1.default.undefined], options.searchParams);
|
|
385
|
+
is_1.assert.any([is_1.default.object, is_1.default.string, is_1.default.undefined], options.cache);
|
|
386
|
+
is_1.assert.any([is_1.default.object, is_1.default.number, is_1.default.undefined], options.timeout);
|
|
387
|
+
is_1.assert.any([is_1.default.object, is_1.default.undefined], options.context);
|
|
388
|
+
is_1.assert.any([is_1.default.object, is_1.default.undefined], options.hooks);
|
|
389
|
+
is_1.assert.any([is_1.default.boolean, is_1.default.undefined], options.decompress);
|
|
390
|
+
is_1.assert.any([is_1.default.boolean, is_1.default.undefined], options.ignoreInvalidCookies);
|
|
391
|
+
is_1.assert.any([is_1.default.boolean, is_1.default.undefined], options.followRedirect);
|
|
392
|
+
is_1.assert.any([is_1.default.number, is_1.default.undefined], options.maxRedirects);
|
|
393
|
+
is_1.assert.any([is_1.default.boolean, is_1.default.undefined], options.throwHttpErrors);
|
|
394
|
+
is_1.assert.any([is_1.default.boolean, is_1.default.undefined], options.http2);
|
|
395
|
+
is_1.assert.any([is_1.default.boolean, is_1.default.undefined], options.allowGetBody);
|
|
396
|
+
is_1.assert.any([is_1.default.string, is_1.default.undefined], options.localAddress);
|
|
397
|
+
is_1.assert.any([dns_ip_version_1.isDnsLookupIpVersion, is_1.default.undefined], options.dnsLookupIpVersion);
|
|
398
|
+
is_1.assert.any([is_1.default.object, is_1.default.undefined], options.https);
|
|
399
|
+
is_1.assert.any([is_1.default.boolean, is_1.default.undefined], options.rejectUnauthorized);
|
|
400
|
+
if (options.https) {
|
|
401
|
+
is_1.assert.any([is_1.default.boolean, is_1.default.undefined], options.https.rejectUnauthorized);
|
|
402
|
+
is_1.assert.any([is_1.default.function_, is_1.default.undefined], options.https.checkServerIdentity);
|
|
403
|
+
is_1.assert.any([is_1.default.string, is_1.default.object, is_1.default.array, is_1.default.undefined], options.https.certificateAuthority);
|
|
404
|
+
is_1.assert.any([is_1.default.string, is_1.default.object, is_1.default.array, is_1.default.undefined], options.https.key);
|
|
405
|
+
is_1.assert.any([is_1.default.string, is_1.default.object, is_1.default.array, is_1.default.undefined], options.https.certificate);
|
|
406
|
+
is_1.assert.any([is_1.default.string, is_1.default.undefined], options.https.passphrase);
|
|
407
|
+
is_1.assert.any([is_1.default.string, is_1.default.buffer, is_1.default.array, is_1.default.undefined], options.https.pfx);
|
|
408
|
+
}
|
|
409
|
+
is_1.assert.any([is_1.default.object, is_1.default.undefined], options.cacheOptions);
|
|
410
|
+
// `options.method`
|
|
411
|
+
if (is_1.default.string(options.method)) {
|
|
412
|
+
options.method = options.method.toUpperCase();
|
|
413
|
+
}
|
|
414
|
+
else {
|
|
415
|
+
options.method = 'GET';
|
|
416
|
+
}
|
|
417
|
+
// `options.headers`
|
|
418
|
+
if (options.headers === (defaults === null || defaults === void 0 ? void 0 : defaults.headers)) {
|
|
419
|
+
options.headers = { ...options.headers };
|
|
420
|
+
}
|
|
421
|
+
else {
|
|
422
|
+
options.headers = lowercaseKeys({ ...(defaults === null || defaults === void 0 ? void 0 : defaults.headers), ...options.headers });
|
|
423
|
+
}
|
|
424
|
+
// Disallow legacy `url.Url`
|
|
425
|
+
if ('slashes' in options) {
|
|
426
|
+
throw new TypeError('The legacy `url.Url` has been deprecated. Use `URL` instead.');
|
|
427
|
+
}
|
|
428
|
+
// `options.auth`
|
|
429
|
+
if ('auth' in options) {
|
|
430
|
+
throw new TypeError('Parameter `auth` is deprecated. Use `username` / `password` instead.');
|
|
431
|
+
}
|
|
432
|
+
// `options.searchParams`
|
|
433
|
+
if ('searchParams' in options) {
|
|
434
|
+
if (options.searchParams && options.searchParams !== (defaults === null || defaults === void 0 ? void 0 : defaults.searchParams)) {
|
|
435
|
+
let searchParameters;
|
|
436
|
+
if (is_1.default.string(options.searchParams) || (options.searchParams instanceof url_1.URLSearchParams)) {
|
|
437
|
+
searchParameters = new url_1.URLSearchParams(options.searchParams);
|
|
438
|
+
}
|
|
439
|
+
else {
|
|
440
|
+
validateSearchParameters(options.searchParams);
|
|
441
|
+
searchParameters = new url_1.URLSearchParams();
|
|
442
|
+
// eslint-disable-next-line guard-for-in
|
|
443
|
+
for (const key in options.searchParams) {
|
|
444
|
+
const value = options.searchParams[key];
|
|
445
|
+
if (value === null) {
|
|
446
|
+
searchParameters.append(key, '');
|
|
447
|
+
}
|
|
448
|
+
else if (value !== undefined) {
|
|
449
|
+
searchParameters.append(key, value);
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
// `normalizeArguments()` is also used to merge options
|
|
454
|
+
(_a = defaults === null || defaults === void 0 ? void 0 : defaults.searchParams) === null || _a === void 0 ? void 0 : _a.forEach((value, key) => {
|
|
455
|
+
// Only use default if one isn't already defined
|
|
456
|
+
if (!searchParameters.has(key)) {
|
|
457
|
+
searchParameters.append(key, value);
|
|
458
|
+
}
|
|
459
|
+
});
|
|
460
|
+
options.searchParams = searchParameters;
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
// `options.username` & `options.password`
|
|
464
|
+
options.username = (_b = options.username) !== null && _b !== void 0 ? _b : '';
|
|
465
|
+
options.password = (_c = options.password) !== null && _c !== void 0 ? _c : '';
|
|
466
|
+
// `options.prefixUrl` & `options.url`
|
|
467
|
+
if (is_1.default.undefined(options.prefixUrl)) {
|
|
468
|
+
options.prefixUrl = (_d = defaults === null || defaults === void 0 ? void 0 : defaults.prefixUrl) !== null && _d !== void 0 ? _d : '';
|
|
469
|
+
}
|
|
470
|
+
else {
|
|
471
|
+
options.prefixUrl = options.prefixUrl.toString();
|
|
472
|
+
if (options.prefixUrl !== '' && !options.prefixUrl.endsWith('/')) {
|
|
473
|
+
options.prefixUrl += '/';
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
if (is_1.default.string(options.url)) {
|
|
477
|
+
if (options.url.startsWith('/')) {
|
|
478
|
+
throw new Error('`input` must not start with a slash when using `prefixUrl`');
|
|
479
|
+
}
|
|
480
|
+
options.url = options_to_url_1.default(options.prefixUrl + options.url, options);
|
|
481
|
+
}
|
|
482
|
+
else if ((is_1.default.undefined(options.url) && options.prefixUrl !== '') || options.protocol) {
|
|
483
|
+
options.url = options_to_url_1.default(options.prefixUrl, options);
|
|
484
|
+
}
|
|
485
|
+
if (options.url) {
|
|
486
|
+
if ('port' in options) {
|
|
487
|
+
delete options.port;
|
|
488
|
+
}
|
|
489
|
+
// Make it possible to change `options.prefixUrl`
|
|
490
|
+
let { prefixUrl } = options;
|
|
491
|
+
Object.defineProperty(options, 'prefixUrl', {
|
|
492
|
+
set: (value) => {
|
|
493
|
+
const url = options.url;
|
|
494
|
+
if (!url.href.startsWith(value)) {
|
|
495
|
+
throw new Error(`Cannot change \`prefixUrl\` from ${prefixUrl} to ${value}: ${url.href}`);
|
|
496
|
+
}
|
|
497
|
+
options.url = new url_1.URL(value + url.href.slice(prefixUrl.length));
|
|
498
|
+
prefixUrl = value;
|
|
499
|
+
},
|
|
500
|
+
get: () => prefixUrl
|
|
501
|
+
});
|
|
502
|
+
// Support UNIX sockets
|
|
503
|
+
let { protocol } = options.url;
|
|
504
|
+
if (protocol === 'unix:') {
|
|
505
|
+
protocol = 'http:';
|
|
506
|
+
options.url = new url_1.URL(`http://unix${options.url.pathname}${options.url.search}`);
|
|
507
|
+
}
|
|
508
|
+
// Set search params
|
|
509
|
+
if (options.searchParams) {
|
|
510
|
+
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
|
511
|
+
options.url.search = options.searchParams.toString();
|
|
512
|
+
}
|
|
513
|
+
// Protocol check
|
|
514
|
+
if (protocol !== 'http:' && protocol !== 'https:') {
|
|
515
|
+
throw new UnsupportedProtocolError(options);
|
|
516
|
+
}
|
|
517
|
+
// Update `username`
|
|
518
|
+
if (options.username === '') {
|
|
519
|
+
options.username = options.url.username;
|
|
520
|
+
}
|
|
521
|
+
else {
|
|
522
|
+
options.url.username = options.username;
|
|
523
|
+
}
|
|
524
|
+
// Update `password`
|
|
525
|
+
if (options.password === '') {
|
|
526
|
+
options.password = options.url.password;
|
|
527
|
+
}
|
|
528
|
+
else {
|
|
529
|
+
options.url.password = options.password;
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
// `options.cookieJar`
|
|
533
|
+
const { cookieJar } = options;
|
|
534
|
+
if (cookieJar) {
|
|
535
|
+
let { setCookie, getCookieString } = cookieJar;
|
|
536
|
+
is_1.assert.function_(setCookie);
|
|
537
|
+
is_1.assert.function_(getCookieString);
|
|
538
|
+
/* istanbul ignore next: Horrible `tough-cookie` v3 check */
|
|
539
|
+
if (setCookie.length === 4 && getCookieString.length === 0) {
|
|
540
|
+
setCookie = util_1.promisify(setCookie.bind(options.cookieJar));
|
|
541
|
+
getCookieString = util_1.promisify(getCookieString.bind(options.cookieJar));
|
|
542
|
+
options.cookieJar = {
|
|
543
|
+
setCookie,
|
|
544
|
+
getCookieString: getCookieString
|
|
545
|
+
};
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
// `options.cache`
|
|
549
|
+
const { cache } = options;
|
|
550
|
+
if (cache) {
|
|
551
|
+
if (!cacheableStore.has(cache)) {
|
|
552
|
+
cacheableStore.set(cache, new CacheableRequest(((requestOptions, handler) => {
|
|
553
|
+
const result = requestOptions[kRequest](requestOptions, handler);
|
|
554
|
+
// TODO: remove this when `cacheable-request` supports async request functions.
|
|
555
|
+
if (is_1.default.promise(result)) {
|
|
556
|
+
// @ts-expect-error
|
|
557
|
+
// We only need to implement the error handler in order to support HTTP2 caching.
|
|
558
|
+
// The result will be a promise anyway.
|
|
559
|
+
result.once = (event, handler) => {
|
|
560
|
+
if (event === 'error') {
|
|
561
|
+
result.catch(handler);
|
|
562
|
+
}
|
|
563
|
+
else if (event === 'abort') {
|
|
564
|
+
// The empty catch is needed here in case when
|
|
565
|
+
// it rejects before it's `await`ed in `_makeRequest`.
|
|
566
|
+
(async () => {
|
|
567
|
+
try {
|
|
568
|
+
const request = (await result);
|
|
569
|
+
request.once('abort', handler);
|
|
570
|
+
}
|
|
571
|
+
catch (_a) { }
|
|
572
|
+
})();
|
|
573
|
+
}
|
|
574
|
+
else {
|
|
575
|
+
/* istanbul ignore next: safety check */
|
|
576
|
+
throw new Error(`Unknown HTTP2 promise event: ${event}`);
|
|
577
|
+
}
|
|
578
|
+
return result;
|
|
579
|
+
};
|
|
580
|
+
}
|
|
581
|
+
return result;
|
|
582
|
+
}), cache));
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
// `options.cacheOptions`
|
|
586
|
+
options.cacheOptions = { ...options.cacheOptions };
|
|
587
|
+
// `options.dnsCache`
|
|
588
|
+
if (options.dnsCache === true) {
|
|
589
|
+
if (!globalDnsCache) {
|
|
590
|
+
globalDnsCache = new cacheable_lookup_1.default();
|
|
591
|
+
}
|
|
592
|
+
options.dnsCache = globalDnsCache;
|
|
593
|
+
}
|
|
594
|
+
else if (!is_1.default.undefined(options.dnsCache) && !options.dnsCache.lookup) {
|
|
595
|
+
throw new TypeError(`Parameter \`dnsCache\` must be a CacheableLookup instance or a boolean, got ${is_1.default(options.dnsCache)}`);
|
|
596
|
+
}
|
|
597
|
+
// `options.timeout`
|
|
598
|
+
if (is_1.default.number(options.timeout)) {
|
|
599
|
+
options.timeout = { request: options.timeout };
|
|
600
|
+
}
|
|
601
|
+
else if (defaults && options.timeout !== defaults.timeout) {
|
|
602
|
+
options.timeout = {
|
|
603
|
+
...defaults.timeout,
|
|
604
|
+
...options.timeout
|
|
605
|
+
};
|
|
606
|
+
}
|
|
607
|
+
else {
|
|
608
|
+
options.timeout = { ...options.timeout };
|
|
609
|
+
}
|
|
610
|
+
// `options.context`
|
|
611
|
+
if (!options.context) {
|
|
612
|
+
options.context = {};
|
|
613
|
+
}
|
|
614
|
+
// `options.hooks`
|
|
615
|
+
const areHooksDefault = options.hooks === (defaults === null || defaults === void 0 ? void 0 : defaults.hooks);
|
|
616
|
+
options.hooks = { ...options.hooks };
|
|
617
|
+
for (const event of exports.knownHookEvents) {
|
|
618
|
+
if (event in options.hooks) {
|
|
619
|
+
if (is_1.default.array(options.hooks[event])) {
|
|
620
|
+
// See https://github.com/microsoft/TypeScript/issues/31445#issuecomment-576929044
|
|
621
|
+
options.hooks[event] = [...options.hooks[event]];
|
|
622
|
+
}
|
|
623
|
+
else {
|
|
624
|
+
throw new TypeError(`Parameter \`${event}\` must be an Array, got ${is_1.default(options.hooks[event])}`);
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
else {
|
|
628
|
+
options.hooks[event] = [];
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
if (defaults && !areHooksDefault) {
|
|
632
|
+
for (const event of exports.knownHookEvents) {
|
|
633
|
+
const defaultHooks = defaults.hooks[event];
|
|
634
|
+
if (defaultHooks.length > 0) {
|
|
635
|
+
// See https://github.com/microsoft/TypeScript/issues/31445#issuecomment-576929044
|
|
636
|
+
options.hooks[event] = [
|
|
637
|
+
...defaults.hooks[event],
|
|
638
|
+
...options.hooks[event]
|
|
639
|
+
];
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
// DNS options
|
|
644
|
+
if ('family' in options) {
|
|
645
|
+
deprecation_warning_1.default('"options.family" was never documented, please use "options.dnsLookupIpVersion"');
|
|
646
|
+
}
|
|
647
|
+
// HTTPS options
|
|
648
|
+
if (defaults === null || defaults === void 0 ? void 0 : defaults.https) {
|
|
649
|
+
options.https = { ...defaults.https, ...options.https };
|
|
650
|
+
}
|
|
651
|
+
if ('rejectUnauthorized' in options) {
|
|
652
|
+
deprecation_warning_1.default('"options.rejectUnauthorized" is now deprecated, please use "options.https.rejectUnauthorized"');
|
|
653
|
+
}
|
|
654
|
+
if ('checkServerIdentity' in options) {
|
|
655
|
+
deprecation_warning_1.default('"options.checkServerIdentity" was never documented, please use "options.https.checkServerIdentity"');
|
|
656
|
+
}
|
|
657
|
+
if ('ca' in options) {
|
|
658
|
+
deprecation_warning_1.default('"options.ca" was never documented, please use "options.https.certificateAuthority"');
|
|
659
|
+
}
|
|
660
|
+
if ('key' in options) {
|
|
661
|
+
deprecation_warning_1.default('"options.key" was never documented, please use "options.https.key"');
|
|
662
|
+
}
|
|
663
|
+
if ('cert' in options) {
|
|
664
|
+
deprecation_warning_1.default('"options.cert" was never documented, please use "options.https.certificate"');
|
|
665
|
+
}
|
|
666
|
+
if ('passphrase' in options) {
|
|
667
|
+
deprecation_warning_1.default('"options.passphrase" was never documented, please use "options.https.passphrase"');
|
|
668
|
+
}
|
|
669
|
+
if ('pfx' in options) {
|
|
670
|
+
deprecation_warning_1.default('"options.pfx" was never documented, please use "options.https.pfx"');
|
|
671
|
+
}
|
|
672
|
+
// Other options
|
|
673
|
+
if ('followRedirects' in options) {
|
|
674
|
+
throw new TypeError('The `followRedirects` option does not exist. Use `followRedirect` instead.');
|
|
675
|
+
}
|
|
676
|
+
if (options.agent) {
|
|
677
|
+
for (const key in options.agent) {
|
|
678
|
+
if (key !== 'http' && key !== 'https' && key !== 'http2') {
|
|
679
|
+
throw new TypeError(`Expected the \`options.agent\` properties to be \`http\`, \`https\` or \`http2\`, got \`${key}\``);
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
options.maxRedirects = (_e = options.maxRedirects) !== null && _e !== void 0 ? _e : 0;
|
|
684
|
+
// Set non-enumerable properties
|
|
685
|
+
exports.setNonEnumerableProperties([defaults, rawOptions], options);
|
|
686
|
+
return normalize_arguments_1.default(options, defaults);
|
|
687
|
+
}
|
|
688
|
+
_lockWrite() {
|
|
689
|
+
const onLockedWrite = () => {
|
|
690
|
+
throw new TypeError('The payload has been already provided');
|
|
691
|
+
};
|
|
692
|
+
this.write = onLockedWrite;
|
|
693
|
+
this.end = onLockedWrite;
|
|
694
|
+
}
|
|
695
|
+
_unlockWrite() {
|
|
696
|
+
this.write = super.write;
|
|
697
|
+
this.end = super.end;
|
|
698
|
+
}
|
|
699
|
+
async _finalizeBody() {
|
|
700
|
+
const { options } = this;
|
|
701
|
+
const { headers } = options;
|
|
702
|
+
const isForm = !is_1.default.undefined(options.form);
|
|
703
|
+
const isJSON = !is_1.default.undefined(options.json);
|
|
704
|
+
const isBody = !is_1.default.undefined(options.body);
|
|
705
|
+
const hasPayload = isForm || isJSON || isBody;
|
|
706
|
+
const cannotHaveBody = exports.withoutBody.has(options.method) && !(options.method === 'GET' && options.allowGetBody);
|
|
707
|
+
this._cannotHaveBody = cannotHaveBody;
|
|
708
|
+
if (hasPayload) {
|
|
709
|
+
if (cannotHaveBody) {
|
|
710
|
+
throw new TypeError(`The \`${options.method}\` method cannot be used with a body`);
|
|
711
|
+
}
|
|
712
|
+
if ([isBody, isForm, isJSON].filter(isTrue => isTrue).length > 1) {
|
|
713
|
+
throw new TypeError('The `body`, `json` and `form` options are mutually exclusive');
|
|
714
|
+
}
|
|
715
|
+
if (isBody &&
|
|
716
|
+
!(options.body instanceof stream_1.Readable) &&
|
|
717
|
+
!is_1.default.string(options.body) &&
|
|
718
|
+
!is_1.default.buffer(options.body) &&
|
|
719
|
+
!is_form_data_1.default(options.body)) {
|
|
720
|
+
throw new TypeError('The `body` option must be a stream.Readable, string or Buffer');
|
|
721
|
+
}
|
|
722
|
+
if (isForm && !is_1.default.object(options.form)) {
|
|
723
|
+
throw new TypeError('The `form` option must be an Object');
|
|
724
|
+
}
|
|
725
|
+
{
|
|
726
|
+
// Serialize body
|
|
727
|
+
const noContentType = !is_1.default.string(headers['content-type']);
|
|
728
|
+
if (isBody) {
|
|
729
|
+
// Special case for https://github.com/form-data/form-data
|
|
730
|
+
if (is_form_data_1.default(options.body) && noContentType) {
|
|
731
|
+
headers['content-type'] = `multipart/form-data; boundary=${options.body.getBoundary()}`;
|
|
732
|
+
}
|
|
733
|
+
this[kBody] = options.body;
|
|
734
|
+
}
|
|
735
|
+
else if (isForm) {
|
|
736
|
+
if (noContentType) {
|
|
737
|
+
headers['content-type'] = 'application/x-www-form-urlencoded';
|
|
738
|
+
}
|
|
739
|
+
this[kBody] = (new url_1.URLSearchParams(options.form)).toString();
|
|
740
|
+
}
|
|
741
|
+
else {
|
|
742
|
+
if (noContentType) {
|
|
743
|
+
headers['content-type'] = 'application/json';
|
|
744
|
+
}
|
|
745
|
+
this[kBody] = options.stringifyJson(options.json);
|
|
746
|
+
}
|
|
747
|
+
const uploadBodySize = await get_body_size_1.default(this[kBody], options.headers);
|
|
748
|
+
// See https://tools.ietf.org/html/rfc7230#section-3.3.2
|
|
749
|
+
// A user agent SHOULD send a Content-Length in a request message when
|
|
750
|
+
// no Transfer-Encoding is sent and the request method defines a meaning
|
|
751
|
+
// for an enclosed payload body. For example, a Content-Length header
|
|
752
|
+
// field is normally sent in a POST request even when the value is 0
|
|
753
|
+
// (indicating an empty payload body). A user agent SHOULD NOT send a
|
|
754
|
+
// Content-Length header field when the request message does not contain
|
|
755
|
+
// a payload body and the method semantics do not anticipate such a
|
|
756
|
+
// body.
|
|
757
|
+
if (is_1.default.undefined(headers['content-length']) && is_1.default.undefined(headers['transfer-encoding'])) {
|
|
758
|
+
if (!cannotHaveBody && !is_1.default.undefined(uploadBodySize)) {
|
|
759
|
+
headers['content-length'] = String(uploadBodySize);
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
else if (cannotHaveBody) {
|
|
765
|
+
this._lockWrite();
|
|
766
|
+
}
|
|
767
|
+
else {
|
|
768
|
+
this._unlockWrite();
|
|
769
|
+
}
|
|
770
|
+
this[kBodySize] = Number(headers['content-length']) || undefined;
|
|
771
|
+
}
|
|
772
|
+
async _onResponseBase(response) {
|
|
773
|
+
const { options } = this;
|
|
774
|
+
const { url } = options;
|
|
775
|
+
this[kOriginalResponse] = response;
|
|
776
|
+
if (options.decompress) {
|
|
777
|
+
response = decompressResponse(response);
|
|
778
|
+
}
|
|
779
|
+
const statusCode = response.statusCode;
|
|
780
|
+
const typedResponse = response;
|
|
781
|
+
typedResponse.statusMessage = typedResponse.statusMessage ? typedResponse.statusMessage : http.STATUS_CODES[statusCode];
|
|
782
|
+
typedResponse.url = options.url.toString();
|
|
783
|
+
typedResponse.requestUrl = this.requestUrl;
|
|
784
|
+
typedResponse.redirectUrls = this.redirects;
|
|
785
|
+
typedResponse.request = this;
|
|
786
|
+
typedResponse.isFromCache = response.fromCache || false;
|
|
787
|
+
typedResponse.ip = this.ip;
|
|
788
|
+
typedResponse.retryCount = this.retryCount;
|
|
789
|
+
this[kIsFromCache] = typedResponse.isFromCache;
|
|
790
|
+
this[kResponseSize] = Number(response.headers['content-length']) || undefined;
|
|
791
|
+
this[kResponse] = response;
|
|
792
|
+
response.once('end', () => {
|
|
793
|
+
this[kResponseSize] = this[kDownloadedSize];
|
|
794
|
+
this.emit('downloadProgress', this.downloadProgress);
|
|
795
|
+
});
|
|
796
|
+
response.once('error', (error) => {
|
|
797
|
+
// Force clean-up, because some packages don't do this.
|
|
798
|
+
// TODO: Fix decompress-response
|
|
799
|
+
response.destroy();
|
|
800
|
+
this._beforeError(new ReadError(error, this));
|
|
801
|
+
});
|
|
802
|
+
response.once('aborted', () => {
|
|
803
|
+
this._beforeError(new ReadError({
|
|
804
|
+
name: 'Error',
|
|
805
|
+
message: 'The server aborted pending request',
|
|
806
|
+
code: 'ECONNRESET'
|
|
807
|
+
}, this));
|
|
808
|
+
});
|
|
809
|
+
this.emit('downloadProgress', this.downloadProgress);
|
|
810
|
+
const rawCookies = response.headers['set-cookie'];
|
|
811
|
+
if (is_1.default.object(options.cookieJar) && rawCookies) {
|
|
812
|
+
let promises = rawCookies.map(async (rawCookie) => options.cookieJar.setCookie(rawCookie, url.toString()));
|
|
813
|
+
if (options.ignoreInvalidCookies) {
|
|
814
|
+
promises = promises.map(async (p) => p.catch(() => { }));
|
|
815
|
+
}
|
|
816
|
+
try {
|
|
817
|
+
await Promise.all(promises);
|
|
818
|
+
}
|
|
819
|
+
catch (error) {
|
|
820
|
+
this._beforeError(error);
|
|
821
|
+
return;
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
if (options.followRedirect && response.headers.location && redirectCodes.has(statusCode)) {
|
|
825
|
+
// We're being redirected, we don't care about the response.
|
|
826
|
+
// It'd be best to abort the request, but we can't because
|
|
827
|
+
// we would have to sacrifice the TCP connection. We don't want that.
|
|
828
|
+
response.resume();
|
|
829
|
+
if (this[kRequest]) {
|
|
830
|
+
this[kCancelTimeouts]();
|
|
831
|
+
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
|
832
|
+
delete this[kRequest];
|
|
833
|
+
this[kUnproxyEvents]();
|
|
834
|
+
}
|
|
835
|
+
const shouldBeGet = statusCode === 303 && options.method !== 'GET' && options.method !== 'HEAD';
|
|
836
|
+
if (shouldBeGet || !options.methodRewriting) {
|
|
837
|
+
// Server responded with "see other", indicating that the resource exists at another location,
|
|
838
|
+
// and the client should request it from that location via GET or HEAD.
|
|
839
|
+
options.method = 'GET';
|
|
840
|
+
if ('body' in options) {
|
|
841
|
+
delete options.body;
|
|
842
|
+
}
|
|
843
|
+
if ('json' in options) {
|
|
844
|
+
delete options.json;
|
|
845
|
+
}
|
|
846
|
+
if ('form' in options) {
|
|
847
|
+
delete options.form;
|
|
848
|
+
}
|
|
849
|
+
this[kBody] = undefined;
|
|
850
|
+
delete options.headers['content-length'];
|
|
851
|
+
}
|
|
852
|
+
if (this.redirects.length >= options.maxRedirects) {
|
|
853
|
+
this._beforeError(new MaxRedirectsError(this));
|
|
854
|
+
return;
|
|
855
|
+
}
|
|
856
|
+
try {
|
|
857
|
+
// Do not remove. See https://github.com/sindresorhus/got/pull/214
|
|
858
|
+
const redirectBuffer = Buffer.from(response.headers.location, 'binary').toString();
|
|
859
|
+
// Handles invalid URLs. See https://github.com/sindresorhus/got/issues/604
|
|
860
|
+
const redirectUrl = new url_1.URL(redirectBuffer, url);
|
|
861
|
+
const redirectString = redirectUrl.toString();
|
|
862
|
+
decodeURI(redirectString);
|
|
863
|
+
// Redirecting to a different site, clear sensitive data.
|
|
864
|
+
if (redirectUrl.hostname !== url.hostname || redirectUrl.port !== url.port) {
|
|
865
|
+
if ('host' in options.headers) {
|
|
866
|
+
delete options.headers.host;
|
|
867
|
+
}
|
|
868
|
+
if ('cookie' in options.headers) {
|
|
869
|
+
delete options.headers.cookie;
|
|
870
|
+
}
|
|
871
|
+
if ('authorization' in options.headers) {
|
|
872
|
+
delete options.headers.authorization;
|
|
873
|
+
}
|
|
874
|
+
if (options.username || options.password) {
|
|
875
|
+
options.username = '';
|
|
876
|
+
options.password = '';
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
else {
|
|
880
|
+
redirectUrl.username = options.username;
|
|
881
|
+
redirectUrl.password = options.password;
|
|
882
|
+
}
|
|
883
|
+
this.redirects.push(redirectString);
|
|
884
|
+
options.url = redirectUrl;
|
|
885
|
+
for (const hook of options.hooks.beforeRedirect) {
|
|
886
|
+
// eslint-disable-next-line no-await-in-loop
|
|
887
|
+
await hook(options, typedResponse);
|
|
888
|
+
}
|
|
889
|
+
this.emit('redirect', typedResponse, options);
|
|
890
|
+
await this._makeRequest();
|
|
891
|
+
}
|
|
892
|
+
catch (error) {
|
|
893
|
+
this._beforeError(error);
|
|
894
|
+
return;
|
|
895
|
+
}
|
|
896
|
+
return;
|
|
897
|
+
}
|
|
898
|
+
if (options.isStream && options.throwHttpErrors && !is_response_ok_1.isResponseOk(typedResponse)) {
|
|
899
|
+
this._beforeError(new HTTPError(typedResponse));
|
|
900
|
+
return;
|
|
901
|
+
}
|
|
902
|
+
response.on('readable', () => {
|
|
903
|
+
if (this[kTriggerRead]) {
|
|
904
|
+
this._read();
|
|
905
|
+
}
|
|
906
|
+
});
|
|
907
|
+
this.on('resume', () => {
|
|
908
|
+
response.resume();
|
|
909
|
+
});
|
|
910
|
+
this.on('pause', () => {
|
|
911
|
+
response.pause();
|
|
912
|
+
});
|
|
913
|
+
response.once('end', () => {
|
|
914
|
+
this.push(null);
|
|
915
|
+
});
|
|
916
|
+
this.emit('response', response);
|
|
917
|
+
for (const destination of this[kServerResponsesPiped]) {
|
|
918
|
+
if (destination.headersSent) {
|
|
919
|
+
continue;
|
|
920
|
+
}
|
|
921
|
+
// eslint-disable-next-line guard-for-in
|
|
922
|
+
for (const key in response.headers) {
|
|
923
|
+
const isAllowed = options.decompress ? key !== 'content-encoding' : true;
|
|
924
|
+
const value = response.headers[key];
|
|
925
|
+
if (isAllowed) {
|
|
926
|
+
destination.setHeader(key, value);
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
destination.statusCode = statusCode;
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
async _onResponse(response) {
|
|
933
|
+
try {
|
|
934
|
+
await this._onResponseBase(response);
|
|
935
|
+
}
|
|
936
|
+
catch (error) {
|
|
937
|
+
/* istanbul ignore next: better safe than sorry */
|
|
938
|
+
this._beforeError(error);
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
_onRequest(request) {
|
|
942
|
+
const { options } = this;
|
|
943
|
+
const { timeout, url } = options;
|
|
944
|
+
http_timer_1.default(request);
|
|
945
|
+
this[kCancelTimeouts] = timed_out_1.default(request, timeout, url);
|
|
946
|
+
const responseEventName = options.cache ? 'cacheableResponse' : 'response';
|
|
947
|
+
request.once(responseEventName, (response) => {
|
|
948
|
+
void this._onResponse(response);
|
|
949
|
+
});
|
|
950
|
+
request.once('error', (error) => {
|
|
951
|
+
var _a;
|
|
952
|
+
// Force clean-up, because some packages (e.g. nock) don't do this.
|
|
953
|
+
request.destroy();
|
|
954
|
+
// Node.js <= 12.18.2 mistakenly emits the response `end` first.
|
|
955
|
+
(_a = request.res) === null || _a === void 0 ? void 0 : _a.removeAllListeners('end');
|
|
956
|
+
error = error instanceof timed_out_1.TimeoutError ? new TimeoutError(error, this.timings, this) : new RequestError(error.message, error, this);
|
|
957
|
+
this._beforeError(error);
|
|
958
|
+
});
|
|
959
|
+
this[kUnproxyEvents] = proxy_events_1.default(request, this, proxiedRequestEvents);
|
|
960
|
+
this[kRequest] = request;
|
|
961
|
+
this.emit('uploadProgress', this.uploadProgress);
|
|
962
|
+
// Send body
|
|
963
|
+
const body = this[kBody];
|
|
964
|
+
const currentRequest = this.redirects.length === 0 ? this : request;
|
|
965
|
+
if (is_1.default.nodeStream(body)) {
|
|
966
|
+
body.pipe(currentRequest);
|
|
967
|
+
body.once('error', (error) => {
|
|
968
|
+
this._beforeError(new UploadError(error, this));
|
|
969
|
+
});
|
|
970
|
+
}
|
|
971
|
+
else {
|
|
972
|
+
this._unlockWrite();
|
|
973
|
+
if (!is_1.default.undefined(body)) {
|
|
974
|
+
this._writeRequest(body, undefined, () => { });
|
|
975
|
+
currentRequest.end();
|
|
976
|
+
this._lockWrite();
|
|
977
|
+
}
|
|
978
|
+
else if (this._cannotHaveBody || this._noPipe) {
|
|
979
|
+
currentRequest.end();
|
|
980
|
+
this._lockWrite();
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
this.emit('request', request);
|
|
984
|
+
}
|
|
985
|
+
async _createCacheableRequest(url, options) {
|
|
986
|
+
return new Promise((resolve, reject) => {
|
|
987
|
+
// TODO: Remove `utils/url-to-options.ts` when `cacheable-request` is fixed
|
|
988
|
+
Object.assign(options, url_to_options_1.default(url));
|
|
989
|
+
// `http-cache-semantics` checks this
|
|
990
|
+
// TODO: Fix this ignore.
|
|
991
|
+
// @ts-expect-error
|
|
992
|
+
delete options.url;
|
|
993
|
+
let request;
|
|
994
|
+
// This is ugly
|
|
995
|
+
const cacheRequest = cacheableStore.get(options.cache)(options, async (response) => {
|
|
996
|
+
// TODO: Fix `cacheable-response`
|
|
997
|
+
response._readableState.autoDestroy = false;
|
|
998
|
+
if (request) {
|
|
999
|
+
(await request).emit('cacheableResponse', response);
|
|
1000
|
+
}
|
|
1001
|
+
resolve(response);
|
|
1002
|
+
});
|
|
1003
|
+
// Restore options
|
|
1004
|
+
options.url = url;
|
|
1005
|
+
cacheRequest.once('error', reject);
|
|
1006
|
+
cacheRequest.once('request', async (requestOrPromise) => {
|
|
1007
|
+
request = requestOrPromise;
|
|
1008
|
+
resolve(request);
|
|
1009
|
+
});
|
|
1010
|
+
});
|
|
1011
|
+
}
|
|
1012
|
+
async _makeRequest() {
|
|
1013
|
+
var _a, _b, _c, _d, _e;
|
|
1014
|
+
const { options } = this;
|
|
1015
|
+
const { headers } = options;
|
|
1016
|
+
for (const key in headers) {
|
|
1017
|
+
if (is_1.default.undefined(headers[key])) {
|
|
1018
|
+
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
|
1019
|
+
delete headers[key];
|
|
1020
|
+
}
|
|
1021
|
+
else if (is_1.default.null_(headers[key])) {
|
|
1022
|
+
throw new TypeError(`Use \`undefined\` instead of \`null\` to delete the \`${key}\` header`);
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
if (options.decompress && is_1.default.undefined(headers['accept-encoding'])) {
|
|
1026
|
+
headers['accept-encoding'] = supportsBrotli ? 'gzip, deflate, br' : 'gzip, deflate';
|
|
1027
|
+
}
|
|
1028
|
+
// Set cookies
|
|
1029
|
+
if (options.cookieJar) {
|
|
1030
|
+
const cookieString = await options.cookieJar.getCookieString(options.url.toString());
|
|
1031
|
+
if (is_1.default.nonEmptyString(cookieString)) {
|
|
1032
|
+
options.headers.cookie = cookieString;
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
1035
|
+
for (const hook of options.hooks.beforeRequest) {
|
|
1036
|
+
// eslint-disable-next-line no-await-in-loop
|
|
1037
|
+
const result = await hook(options);
|
|
1038
|
+
if (!is_1.default.undefined(result)) {
|
|
1039
|
+
// @ts-expect-error Skip the type mismatch to support abstract responses
|
|
1040
|
+
options.request = () => result;
|
|
1041
|
+
break;
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1044
|
+
if (options.body && this[kBody] !== options.body) {
|
|
1045
|
+
this[kBody] = options.body;
|
|
1046
|
+
}
|
|
1047
|
+
const { agent, request, timeout, url } = options;
|
|
1048
|
+
if (options.dnsCache && !('lookup' in options)) {
|
|
1049
|
+
options.lookup = options.dnsCache.lookup;
|
|
1050
|
+
}
|
|
1051
|
+
// UNIX sockets
|
|
1052
|
+
if (url.hostname === 'unix') {
|
|
1053
|
+
const matches = /(?<socketPath>.+?):(?<path>.+)/.exec(`${url.pathname}${url.search}`);
|
|
1054
|
+
if (matches === null || matches === void 0 ? void 0 : matches.groups) {
|
|
1055
|
+
const { socketPath, path } = matches.groups;
|
|
1056
|
+
Object.assign(options, {
|
|
1057
|
+
socketPath,
|
|
1058
|
+
path,
|
|
1059
|
+
host: ''
|
|
1060
|
+
});
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
const isHttps = url.protocol === 'https:';
|
|
1064
|
+
// Fallback function
|
|
1065
|
+
let fallbackFn;
|
|
1066
|
+
if (options.http2) {
|
|
1067
|
+
fallbackFn = http2wrapper.auto;
|
|
1068
|
+
}
|
|
1069
|
+
else {
|
|
1070
|
+
fallbackFn = isHttps ? https.request : http.request;
|
|
1071
|
+
}
|
|
1072
|
+
const realFn = (_a = options.request) !== null && _a !== void 0 ? _a : fallbackFn;
|
|
1073
|
+
// Cache support
|
|
1074
|
+
const fn = options.cache ? this._createCacheableRequest : realFn;
|
|
1075
|
+
// Pass an agent directly when HTTP2 is disabled
|
|
1076
|
+
if (agent && !options.http2) {
|
|
1077
|
+
options.agent = agent[isHttps ? 'https' : 'http'];
|
|
1078
|
+
}
|
|
1079
|
+
// Prepare plain HTTP request options
|
|
1080
|
+
options[kRequest] = realFn;
|
|
1081
|
+
delete options.request;
|
|
1082
|
+
// TODO: Fix this ignore.
|
|
1083
|
+
// @ts-expect-error
|
|
1084
|
+
delete options.timeout;
|
|
1085
|
+
const requestOptions = options;
|
|
1086
|
+
requestOptions.shared = (_b = options.cacheOptions) === null || _b === void 0 ? void 0 : _b.shared;
|
|
1087
|
+
requestOptions.cacheHeuristic = (_c = options.cacheOptions) === null || _c === void 0 ? void 0 : _c.cacheHeuristic;
|
|
1088
|
+
requestOptions.immutableMinTimeToLive = (_d = options.cacheOptions) === null || _d === void 0 ? void 0 : _d.immutableMinTimeToLive;
|
|
1089
|
+
requestOptions.ignoreCargoCult = (_e = options.cacheOptions) === null || _e === void 0 ? void 0 : _e.ignoreCargoCult;
|
|
1090
|
+
// If `dnsLookupIpVersion` is not present do not override `family`
|
|
1091
|
+
if (options.dnsLookupIpVersion !== undefined) {
|
|
1092
|
+
try {
|
|
1093
|
+
requestOptions.family = dns_ip_version_1.dnsLookupIpVersionToFamily(options.dnsLookupIpVersion);
|
|
1094
|
+
}
|
|
1095
|
+
catch (_f) {
|
|
1096
|
+
throw new Error('Invalid `dnsLookupIpVersion` option value');
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
// HTTPS options remapping
|
|
1100
|
+
if (options.https) {
|
|
1101
|
+
if ('rejectUnauthorized' in options.https) {
|
|
1102
|
+
requestOptions.rejectUnauthorized = options.https.rejectUnauthorized;
|
|
1103
|
+
}
|
|
1104
|
+
if (options.https.checkServerIdentity) {
|
|
1105
|
+
requestOptions.checkServerIdentity = options.https.checkServerIdentity;
|
|
1106
|
+
}
|
|
1107
|
+
if (options.https.certificateAuthority) {
|
|
1108
|
+
requestOptions.ca = options.https.certificateAuthority;
|
|
1109
|
+
}
|
|
1110
|
+
if (options.https.certificate) {
|
|
1111
|
+
requestOptions.cert = options.https.certificate;
|
|
1112
|
+
}
|
|
1113
|
+
if (options.https.key) {
|
|
1114
|
+
requestOptions.key = options.https.key;
|
|
1115
|
+
}
|
|
1116
|
+
if (options.https.passphrase) {
|
|
1117
|
+
requestOptions.passphrase = options.https.passphrase;
|
|
1118
|
+
}
|
|
1119
|
+
if (options.https.pfx) {
|
|
1120
|
+
requestOptions.pfx = options.https.pfx;
|
|
1121
|
+
}
|
|
1122
|
+
}
|
|
1123
|
+
try {
|
|
1124
|
+
let requestOrResponse = await fn(url, requestOptions);
|
|
1125
|
+
if (is_1.default.undefined(requestOrResponse)) {
|
|
1126
|
+
requestOrResponse = fallbackFn(url, requestOptions);
|
|
1127
|
+
}
|
|
1128
|
+
// Restore options
|
|
1129
|
+
options.request = request;
|
|
1130
|
+
options.timeout = timeout;
|
|
1131
|
+
options.agent = agent;
|
|
1132
|
+
// HTTPS options restore
|
|
1133
|
+
if (options.https) {
|
|
1134
|
+
if ('rejectUnauthorized' in options.https) {
|
|
1135
|
+
delete requestOptions.rejectUnauthorized;
|
|
1136
|
+
}
|
|
1137
|
+
if (options.https.checkServerIdentity) {
|
|
1138
|
+
// @ts-expect-error - This one will be removed when we remove the alias.
|
|
1139
|
+
delete requestOptions.checkServerIdentity;
|
|
1140
|
+
}
|
|
1141
|
+
if (options.https.certificateAuthority) {
|
|
1142
|
+
delete requestOptions.ca;
|
|
1143
|
+
}
|
|
1144
|
+
if (options.https.certificate) {
|
|
1145
|
+
delete requestOptions.cert;
|
|
1146
|
+
}
|
|
1147
|
+
if (options.https.key) {
|
|
1148
|
+
delete requestOptions.key;
|
|
1149
|
+
}
|
|
1150
|
+
if (options.https.passphrase) {
|
|
1151
|
+
delete requestOptions.passphrase;
|
|
1152
|
+
}
|
|
1153
|
+
if (options.https.pfx) {
|
|
1154
|
+
delete requestOptions.pfx;
|
|
1155
|
+
}
|
|
1156
|
+
}
|
|
1157
|
+
if (isClientRequest(requestOrResponse)) {
|
|
1158
|
+
this._onRequest(requestOrResponse);
|
|
1159
|
+
// Emit the response after the stream has been ended
|
|
1160
|
+
}
|
|
1161
|
+
else if (this.writable) {
|
|
1162
|
+
this.once('finish', () => {
|
|
1163
|
+
void this._onResponse(requestOrResponse);
|
|
1164
|
+
});
|
|
1165
|
+
this._unlockWrite();
|
|
1166
|
+
this.end();
|
|
1167
|
+
this._lockWrite();
|
|
1168
|
+
}
|
|
1169
|
+
else {
|
|
1170
|
+
void this._onResponse(requestOrResponse);
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1173
|
+
catch (error) {
|
|
1174
|
+
if (error instanceof CacheableRequest.CacheError) {
|
|
1175
|
+
throw new CacheError(error, this);
|
|
1176
|
+
}
|
|
1177
|
+
throw new RequestError(error.message, error, this);
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1180
|
+
async _error(error) {
|
|
1181
|
+
try {
|
|
1182
|
+
for (const hook of this.options.hooks.beforeError) {
|
|
1183
|
+
// eslint-disable-next-line no-await-in-loop
|
|
1184
|
+
error = await hook(error);
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1187
|
+
catch (error_) {
|
|
1188
|
+
error = new RequestError(error_.message, error_, this);
|
|
1189
|
+
}
|
|
1190
|
+
this.destroy(error);
|
|
1191
|
+
}
|
|
1192
|
+
_beforeError(error) {
|
|
1193
|
+
if (this[kStopReading]) {
|
|
1194
|
+
return;
|
|
1195
|
+
}
|
|
1196
|
+
const { options } = this;
|
|
1197
|
+
const retryCount = this.retryCount + 1;
|
|
1198
|
+
this[kStopReading] = true;
|
|
1199
|
+
if (!(error instanceof RequestError)) {
|
|
1200
|
+
error = new RequestError(error.message, error, this);
|
|
1201
|
+
}
|
|
1202
|
+
const typedError = error;
|
|
1203
|
+
const { response } = typedError;
|
|
1204
|
+
void (async () => {
|
|
1205
|
+
if (response && !response.body) {
|
|
1206
|
+
response.setEncoding(this._readableState.encoding);
|
|
1207
|
+
try {
|
|
1208
|
+
response.rawBody = await get_buffer_1.default(response);
|
|
1209
|
+
response.body = response.rawBody.toString();
|
|
1210
|
+
}
|
|
1211
|
+
catch (_a) { }
|
|
1212
|
+
}
|
|
1213
|
+
if (this.listenerCount('retry') !== 0) {
|
|
1214
|
+
let backoff;
|
|
1215
|
+
try {
|
|
1216
|
+
let retryAfter;
|
|
1217
|
+
if (response && 'retry-after' in response.headers) {
|
|
1218
|
+
retryAfter = Number(response.headers['retry-after']);
|
|
1219
|
+
if (Number.isNaN(retryAfter)) {
|
|
1220
|
+
retryAfter = Date.parse(response.headers['retry-after']) - Date.now();
|
|
1221
|
+
if (retryAfter <= 0) {
|
|
1222
|
+
retryAfter = 1;
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1225
|
+
else {
|
|
1226
|
+
retryAfter *= 1000;
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
backoff = await options.retry.calculateDelay({
|
|
1230
|
+
attemptCount: retryCount,
|
|
1231
|
+
retryOptions: options.retry,
|
|
1232
|
+
error: typedError,
|
|
1233
|
+
retryAfter,
|
|
1234
|
+
computedValue: calculate_retry_delay_1.default({
|
|
1235
|
+
attemptCount: retryCount,
|
|
1236
|
+
retryOptions: options.retry,
|
|
1237
|
+
error: typedError,
|
|
1238
|
+
retryAfter,
|
|
1239
|
+
computedValue: 0
|
|
1240
|
+
})
|
|
1241
|
+
});
|
|
1242
|
+
}
|
|
1243
|
+
catch (error_) {
|
|
1244
|
+
void this._error(new RequestError(error_.message, error_, this));
|
|
1245
|
+
return;
|
|
1246
|
+
}
|
|
1247
|
+
if (backoff) {
|
|
1248
|
+
const retry = async () => {
|
|
1249
|
+
try {
|
|
1250
|
+
for (const hook of this.options.hooks.beforeRetry) {
|
|
1251
|
+
// eslint-disable-next-line no-await-in-loop
|
|
1252
|
+
await hook(this.options, typedError, retryCount);
|
|
1253
|
+
}
|
|
1254
|
+
}
|
|
1255
|
+
catch (error_) {
|
|
1256
|
+
void this._error(new RequestError(error_.message, error, this));
|
|
1257
|
+
return;
|
|
1258
|
+
}
|
|
1259
|
+
// Something forced us to abort the retry
|
|
1260
|
+
if (this.destroyed) {
|
|
1261
|
+
return;
|
|
1262
|
+
}
|
|
1263
|
+
this.destroy();
|
|
1264
|
+
this.emit('retry', retryCount, error);
|
|
1265
|
+
};
|
|
1266
|
+
this[kRetryTimeout] = setTimeout(retry, backoff);
|
|
1267
|
+
return;
|
|
1268
|
+
}
|
|
1269
|
+
}
|
|
1270
|
+
void this._error(typedError);
|
|
1271
|
+
})();
|
|
1272
|
+
}
|
|
1273
|
+
_read() {
|
|
1274
|
+
this[kTriggerRead] = true;
|
|
1275
|
+
const response = this[kResponse];
|
|
1276
|
+
if (response && !this[kStopReading]) {
|
|
1277
|
+
// We cannot put this in the `if` above
|
|
1278
|
+
// because `.read()` also triggers the `end` event
|
|
1279
|
+
if (response.readableLength) {
|
|
1280
|
+
this[kTriggerRead] = false;
|
|
1281
|
+
}
|
|
1282
|
+
let data;
|
|
1283
|
+
while ((data = response.read()) !== null) {
|
|
1284
|
+
this[kDownloadedSize] += data.length;
|
|
1285
|
+
this[kStartedReading] = true;
|
|
1286
|
+
const progress = this.downloadProgress;
|
|
1287
|
+
if (progress.percent < 1) {
|
|
1288
|
+
this.emit('downloadProgress', progress);
|
|
1289
|
+
}
|
|
1290
|
+
this.push(data);
|
|
1291
|
+
}
|
|
1292
|
+
}
|
|
1293
|
+
}
|
|
1294
|
+
// Node.js 12 has incorrect types, so the encoding must be a string
|
|
1295
|
+
_write(chunk, encoding, callback) {
|
|
1296
|
+
const write = () => {
|
|
1297
|
+
this._writeRequest(chunk, encoding, callback);
|
|
1298
|
+
};
|
|
1299
|
+
if (this.requestInitialized) {
|
|
1300
|
+
write();
|
|
1301
|
+
}
|
|
1302
|
+
else {
|
|
1303
|
+
this[kJobs].push(write);
|
|
1304
|
+
}
|
|
1305
|
+
}
|
|
1306
|
+
_writeRequest(chunk, encoding, callback) {
|
|
1307
|
+
if (this[kRequest].destroyed) {
|
|
1308
|
+
// Probably the `ClientRequest` instance will throw
|
|
1309
|
+
return;
|
|
1310
|
+
}
|
|
1311
|
+
this._progressCallbacks.push(() => {
|
|
1312
|
+
this[kUploadedSize] += Buffer.byteLength(chunk, encoding);
|
|
1313
|
+
const progress = this.uploadProgress;
|
|
1314
|
+
if (progress.percent < 1) {
|
|
1315
|
+
this.emit('uploadProgress', progress);
|
|
1316
|
+
}
|
|
1317
|
+
});
|
|
1318
|
+
// TODO: What happens if it's from cache? Then this[kRequest] won't be defined.
|
|
1319
|
+
this[kRequest].write(chunk, encoding, (error) => {
|
|
1320
|
+
if (!error && this._progressCallbacks.length > 0) {
|
|
1321
|
+
this._progressCallbacks.shift()();
|
|
1322
|
+
}
|
|
1323
|
+
callback(error);
|
|
1324
|
+
});
|
|
1325
|
+
}
|
|
1326
|
+
_final(callback) {
|
|
1327
|
+
const endRequest = () => {
|
|
1328
|
+
// FIX: Node.js 10 calls the write callback AFTER the end callback!
|
|
1329
|
+
while (this._progressCallbacks.length !== 0) {
|
|
1330
|
+
this._progressCallbacks.shift()();
|
|
1331
|
+
}
|
|
1332
|
+
// We need to check if `this[kRequest]` is present,
|
|
1333
|
+
// because it isn't when we use cache.
|
|
1334
|
+
if (!(kRequest in this)) {
|
|
1335
|
+
callback();
|
|
1336
|
+
return;
|
|
1337
|
+
}
|
|
1338
|
+
if (this[kRequest].destroyed) {
|
|
1339
|
+
callback();
|
|
1340
|
+
return;
|
|
1341
|
+
}
|
|
1342
|
+
this[kRequest].end((error) => {
|
|
1343
|
+
if (!error) {
|
|
1344
|
+
this[kBodySize] = this[kUploadedSize];
|
|
1345
|
+
this.emit('uploadProgress', this.uploadProgress);
|
|
1346
|
+
this[kRequest].emit('upload-complete');
|
|
1347
|
+
}
|
|
1348
|
+
callback(error);
|
|
1349
|
+
});
|
|
1350
|
+
};
|
|
1351
|
+
if (this.requestInitialized) {
|
|
1352
|
+
endRequest();
|
|
1353
|
+
}
|
|
1354
|
+
else {
|
|
1355
|
+
this[kJobs].push(endRequest);
|
|
1356
|
+
}
|
|
1357
|
+
}
|
|
1358
|
+
_destroy(error, callback) {
|
|
1359
|
+
var _a;
|
|
1360
|
+
this[kStopReading] = true;
|
|
1361
|
+
// Prevent further retries
|
|
1362
|
+
clearTimeout(this[kRetryTimeout]);
|
|
1363
|
+
if (kRequest in this) {
|
|
1364
|
+
this[kCancelTimeouts]();
|
|
1365
|
+
// TODO: Remove the next `if` when these get fixed:
|
|
1366
|
+
// - https://github.com/nodejs/node/issues/32851
|
|
1367
|
+
if (!((_a = this[kResponse]) === null || _a === void 0 ? void 0 : _a.complete)) {
|
|
1368
|
+
this[kRequest].destroy();
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1371
|
+
if (error !== null && !is_1.default.undefined(error) && !(error instanceof RequestError)) {
|
|
1372
|
+
error = new RequestError(error.message, error, this);
|
|
1373
|
+
}
|
|
1374
|
+
callback(error);
|
|
1375
|
+
}
|
|
1376
|
+
get _isAboutToError() {
|
|
1377
|
+
return this[kStopReading];
|
|
1378
|
+
}
|
|
1379
|
+
/**
|
|
1380
|
+
The remote IP address.
|
|
1381
|
+
*/
|
|
1382
|
+
get ip() {
|
|
1383
|
+
var _a;
|
|
1384
|
+
return (_a = this.socket) === null || _a === void 0 ? void 0 : _a.remoteAddress;
|
|
1385
|
+
}
|
|
1386
|
+
/**
|
|
1387
|
+
Indicates whether the request has been aborted or not.
|
|
1388
|
+
*/
|
|
1389
|
+
get aborted() {
|
|
1390
|
+
var _a, _b, _c;
|
|
1391
|
+
return ((_b = (_a = this[kRequest]) === null || _a === void 0 ? void 0 : _a.destroyed) !== null && _b !== void 0 ? _b : this.destroyed) && !((_c = this[kOriginalResponse]) === null || _c === void 0 ? void 0 : _c.complete);
|
|
1392
|
+
}
|
|
1393
|
+
get socket() {
|
|
1394
|
+
var _a, _b;
|
|
1395
|
+
return (_b = (_a = this[kRequest]) === null || _a === void 0 ? void 0 : _a.socket) !== null && _b !== void 0 ? _b : undefined;
|
|
1396
|
+
}
|
|
1397
|
+
/**
|
|
1398
|
+
Progress event for downloading (receiving a response).
|
|
1399
|
+
*/
|
|
1400
|
+
get downloadProgress() {
|
|
1401
|
+
let percent;
|
|
1402
|
+
if (this[kResponseSize]) {
|
|
1403
|
+
percent = this[kDownloadedSize] / this[kResponseSize];
|
|
1404
|
+
}
|
|
1405
|
+
else if (this[kResponseSize] === this[kDownloadedSize]) {
|
|
1406
|
+
percent = 1;
|
|
1407
|
+
}
|
|
1408
|
+
else {
|
|
1409
|
+
percent = 0;
|
|
1410
|
+
}
|
|
1411
|
+
return {
|
|
1412
|
+
percent,
|
|
1413
|
+
transferred: this[kDownloadedSize],
|
|
1414
|
+
total: this[kResponseSize]
|
|
1415
|
+
};
|
|
1416
|
+
}
|
|
1417
|
+
/**
|
|
1418
|
+
Progress event for uploading (sending a request).
|
|
1419
|
+
*/
|
|
1420
|
+
get uploadProgress() {
|
|
1421
|
+
let percent;
|
|
1422
|
+
if (this[kBodySize]) {
|
|
1423
|
+
percent = this[kUploadedSize] / this[kBodySize];
|
|
1424
|
+
}
|
|
1425
|
+
else if (this[kBodySize] === this[kUploadedSize]) {
|
|
1426
|
+
percent = 1;
|
|
1427
|
+
}
|
|
1428
|
+
else {
|
|
1429
|
+
percent = 0;
|
|
1430
|
+
}
|
|
1431
|
+
return {
|
|
1432
|
+
percent,
|
|
1433
|
+
transferred: this[kUploadedSize],
|
|
1434
|
+
total: this[kBodySize]
|
|
1435
|
+
};
|
|
1436
|
+
}
|
|
1437
|
+
/**
|
|
1438
|
+
The object contains the following properties:
|
|
1439
|
+
|
|
1440
|
+
- `start` - Time when the request started.
|
|
1441
|
+
- `socket` - Time when a socket was assigned to the request.
|
|
1442
|
+
- `lookup` - Time when the DNS lookup finished.
|
|
1443
|
+
- `connect` - Time when the socket successfully connected.
|
|
1444
|
+
- `secureConnect` - Time when the socket securely connected.
|
|
1445
|
+
- `upload` - Time when the request finished uploading.
|
|
1446
|
+
- `response` - Time when the request fired `response` event.
|
|
1447
|
+
- `end` - Time when the response fired `end` event.
|
|
1448
|
+
- `error` - Time when the request fired `error` event.
|
|
1449
|
+
- `abort` - Time when the request fired `abort` event.
|
|
1450
|
+
- `phases`
|
|
1451
|
+
- `wait` - `timings.socket - timings.start`
|
|
1452
|
+
- `dns` - `timings.lookup - timings.socket`
|
|
1453
|
+
- `tcp` - `timings.connect - timings.lookup`
|
|
1454
|
+
- `tls` - `timings.secureConnect - timings.connect`
|
|
1455
|
+
- `request` - `timings.upload - (timings.secureConnect || timings.connect)`
|
|
1456
|
+
- `firstByte` - `timings.response - timings.upload`
|
|
1457
|
+
- `download` - `timings.end - timings.response`
|
|
1458
|
+
- `total` - `(timings.end || timings.error || timings.abort) - timings.start`
|
|
1459
|
+
|
|
1460
|
+
If something has not been measured yet, it will be `undefined`.
|
|
1461
|
+
|
|
1462
|
+
__Note__: The time is a `number` representing the milliseconds elapsed since the UNIX epoch.
|
|
1463
|
+
*/
|
|
1464
|
+
get timings() {
|
|
1465
|
+
var _a;
|
|
1466
|
+
return (_a = this[kRequest]) === null || _a === void 0 ? void 0 : _a.timings;
|
|
1467
|
+
}
|
|
1468
|
+
/**
|
|
1469
|
+
Whether the response was retrieved from the cache.
|
|
1470
|
+
*/
|
|
1471
|
+
get isFromCache() {
|
|
1472
|
+
return this[kIsFromCache];
|
|
1473
|
+
}
|
|
1474
|
+
pipe(destination, options) {
|
|
1475
|
+
if (this[kStartedReading]) {
|
|
1476
|
+
throw new Error('Failed to pipe. The response has been emitted already.');
|
|
1477
|
+
}
|
|
1478
|
+
if (destination instanceof http_1.ServerResponse) {
|
|
1479
|
+
this[kServerResponsesPiped].add(destination);
|
|
1480
|
+
}
|
|
1481
|
+
return super.pipe(destination, options);
|
|
1482
|
+
}
|
|
1483
|
+
unpipe(destination) {
|
|
1484
|
+
if (destination instanceof http_1.ServerResponse) {
|
|
1485
|
+
this[kServerResponsesPiped].delete(destination);
|
|
1486
|
+
}
|
|
1487
|
+
super.unpipe(destination);
|
|
1488
|
+
return this;
|
|
1489
|
+
}
|
|
1490
|
+
}
|
|
1491
|
+
exports.default = Request;
|