@emulsify/cli 1.8.0 → 1.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -13
- package/dist/index.js +14 -6
- package/dist/node_modules/.package-lock.json +37 -24
- package/dist/node_modules/@types/node/README.md +5 -6
- package/dist/node_modules/@types/node/assert/strict.d.ts +8 -0
- package/dist/node_modules/@types/node/assert.d.ts +955 -45
- package/dist/node_modules/@types/node/async_hooks.d.ts +391 -87
- package/dist/node_modules/@types/node/buffer.d.ts +2210 -17
- package/dist/node_modules/@types/node/child_process.d.ts +1051 -189
- package/dist/node_modules/@types/node/cluster.d.ts +421 -143
- package/dist/node_modules/@types/node/console.d.ts +359 -49
- package/dist/node_modules/@types/node/constants.d.ts +3 -3
- package/dist/node_modules/@types/node/crypto.d.ts +3528 -291
- package/dist/node_modules/@types/node/dgram.d.ts +446 -30
- package/dist/node_modules/@types/node/diagnostics_channel.d.ts +554 -0
- package/dist/node_modules/@types/node/dns/promises.d.ts +476 -0
- package/dist/node_modules/@types/node/dns.d.ts +588 -240
- package/dist/node_modules/@types/node/dom-events.d.ts +124 -0
- package/dist/node_modules/@types/node/domain.d.ts +159 -16
- package/dist/node_modules/@types/node/events.d.ts +890 -41
- package/dist/node_modules/@types/node/fs/promises.d.ts +980 -369
- package/dist/node_modules/@types/node/fs.d.ts +2599 -869
- package/dist/node_modules/@types/node/globals.d.ts +374 -727
- package/dist/node_modules/@types/node/globals.global.d.ts +1 -1
- package/dist/node_modules/@types/node/http.d.ts +1459 -132
- package/dist/node_modules/@types/node/http2.d.ts +1333 -123
- package/dist/node_modules/@types/node/https.d.ts +289 -13
- package/dist/node_modules/@types/node/index.d.ts +37 -46
- package/dist/node_modules/@types/node/inspector.d.ts +367 -671
- package/dist/node_modules/@types/node/module.d.ts +273 -14
- package/dist/node_modules/@types/node/net.d.ts +741 -66
- package/dist/node_modules/@types/node/os.d.ts +275 -23
- package/dist/node_modules/@types/node/package.json +95 -110
- package/dist/node_modules/@types/node/path.d.ts +27 -4
- package/dist/node_modules/@types/node/perf_hooks.d.ts +756 -125
- package/dist/node_modules/@types/node/process.d.ts +1429 -127
- package/dist/node_modules/@types/node/punycode.d.ts +65 -26
- package/dist/node_modules/@types/node/querystring.d.ts +121 -9
- package/dist/node_modules/@types/node/readline/promises.d.ts +150 -0
- package/dist/node_modules/@types/node/readline.d.ts +405 -49
- package/dist/node_modules/@types/node/repl.d.ts +99 -73
- package/dist/node_modules/@types/node/sea.d.ts +153 -0
- package/dist/node_modules/@types/node/stream/consumers.d.ts +12 -0
- package/dist/node_modules/@types/node/stream/promises.d.ts +83 -0
- package/dist/node_modules/@types/node/stream/web.d.ts +367 -0
- package/dist/node_modules/@types/node/stream.d.ts +1462 -273
- package/dist/node_modules/@types/node/string_decoder.d.ts +59 -2
- package/dist/node_modules/@types/node/test.d.ts +1719 -0
- package/dist/node_modules/@types/node/timers/promises.d.ts +97 -0
- package/dist/node_modules/@types/node/timers.d.ts +233 -12
- package/dist/node_modules/@types/node/tls.d.ts +540 -189
- package/dist/node_modules/@types/node/trace_events.d.ts +143 -10
- package/dist/node_modules/@types/node/tty.d.ts +156 -17
- package/dist/node_modules/@types/node/url.d.ts +812 -47
- package/dist/node_modules/@types/node/util.d.ts +2159 -145
- package/dist/node_modules/@types/node/v8.d.ts +693 -74
- package/dist/node_modules/@types/node/vm.d.ts +813 -44
- package/dist/node_modules/@types/node/wasi.d.ts +121 -28
- package/dist/node_modules/@types/node/worker_threads.d.ts +514 -61
- package/dist/node_modules/@types/node/zlib.d.ts +220 -54
- package/dist/node_modules/ajv-formats/node_modules/ajv/README.md +1 -1
- package/dist/node_modules/ajv-formats/node_modules/ajv/dist/compile/codegen/code.js +1 -0
- package/dist/node_modules/ajv-formats/node_modules/ajv/dist/compile/codegen/code.js.map +1 -1
- package/dist/node_modules/ajv-formats/node_modules/ajv/dist/compile/index.js.map +1 -1
- package/dist/node_modules/ajv-formats/node_modules/ajv/dist/compile/resolve.d.ts +2 -2
- package/dist/node_modules/ajv-formats/node_modules/ajv/dist/compile/resolve.js.map +1 -1
- package/dist/node_modules/ajv-formats/node_modules/ajv/dist/runtime/uri.d.ts +1 -1
- package/dist/node_modules/ajv-formats/node_modules/ajv/dist/runtime/uri.js +1 -1
- package/dist/node_modules/ajv-formats/node_modules/ajv/dist/runtime/uri.js.map +1 -1
- package/dist/node_modules/ajv-formats/node_modules/ajv/dist/types/index.d.ts +3 -3
- package/dist/node_modules/ajv-formats/node_modules/ajv/dist/types/json-schema.d.ts +10 -10
- package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/discriminator/index.js +5 -1
- package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/discriminator/index.js.map +1 -1
- package/dist/node_modules/ajv-formats/node_modules/ajv/lib/compile/codegen/code.ts +1 -0
- package/dist/node_modules/ajv-formats/node_modules/ajv/lib/compile/index.ts +2 -2
- package/dist/node_modules/ajv-formats/node_modules/ajv/lib/compile/resolve.ts +2 -2
- package/dist/node_modules/ajv-formats/node_modules/ajv/lib/runtime/uri.ts +1 -1
- package/dist/node_modules/ajv-formats/node_modules/ajv/lib/types/index.ts +3 -3
- package/dist/node_modules/ajv-formats/node_modules/ajv/lib/types/json-schema.ts +10 -10
- package/dist/node_modules/ajv-formats/node_modules/ajv/lib/vocabularies/discriminator/index.ts +4 -1
- package/dist/node_modules/ajv-formats/node_modules/ajv/package.json +5 -5
- package/dist/node_modules/commander/Readme.md +10 -8
- package/dist/node_modules/commander/esm.mjs +1 -1
- package/dist/node_modules/commander/lib/argument.js +9 -5
- package/dist/node_modules/commander/lib/command.js +406 -196
- package/dist/node_modules/commander/lib/error.js +0 -4
- package/dist/node_modules/commander/lib/help.js +101 -38
- package/dist/node_modules/commander/lib/option.js +11 -8
- package/dist/node_modules/commander/lib/suggestSimilar.js +5 -4
- package/dist/node_modules/commander/package.json +23 -19
- package/dist/node_modules/commander/typings/index.d.ts +110 -40
- package/dist/node_modules/debug/package.json +4 -3
- package/dist/node_modules/debug/src/browser.js +3 -1
- package/dist/node_modules/debug/src/node.js +2 -2
- package/dist/node_modules/fast-uri/.gitattributes +2 -0
- package/dist/node_modules/fast-uri/.github/.stale.yml +21 -0
- package/dist/node_modules/fast-uri/.github/dependabot.yml +13 -0
- package/dist/node_modules/fast-uri/.github/tests_checker.yml +8 -0
- package/dist/node_modules/fast-uri/.github/workflows/ci.yml +23 -0
- package/dist/node_modules/fast-uri/.github/workflows/package-manager-ci.yml +20 -0
- package/dist/node_modules/fast-uri/.taprc +3 -0
- package/dist/node_modules/fast-uri/LICENSE +30 -0
- package/dist/node_modules/fast-uri/README.md +125 -0
- package/dist/node_modules/fast-uri/benchmark.js +105 -0
- package/dist/node_modules/fast-uri/index.js +309 -0
- package/dist/node_modules/fast-uri/lib/schemes.js +188 -0
- package/dist/node_modules/fast-uri/lib/scopedChars.js +30 -0
- package/dist/node_modules/fast-uri/lib/utils.js +242 -0
- package/dist/node_modules/fast-uri/package.json +39 -0
- package/dist/node_modules/fast-uri/test/.gitkeep +0 -0
- package/dist/node_modules/fast-uri/test/ajv.test.js +39 -0
- package/dist/node_modules/fast-uri/test/compatibility.test.js +130 -0
- package/dist/node_modules/fast-uri/test/equal.test.js +104 -0
- package/dist/node_modules/fast-uri/test/parse.test.js +319 -0
- package/dist/node_modules/fast-uri/test/resolve.test.js +76 -0
- package/dist/node_modules/fast-uri/test/serialize.test.js +144 -0
- package/dist/node_modules/fast-uri/test/uri-js.test.js +940 -0
- package/dist/node_modules/fast-uri/test/util.test.js +24 -0
- package/dist/node_modules/fast-uri/types/index.d.ts +53 -0
- package/dist/node_modules/fast-uri/types/index.test-d.ts +17 -0
- package/dist/node_modules/fs-extra/README.md +32 -2
- package/dist/node_modules/fs-extra/lib/copy/copy-sync.js +3 -11
- package/dist/node_modules/fs-extra/lib/copy/copy.js +120 -178
- package/dist/node_modules/fs-extra/lib/copy/index.js +1 -1
- package/dist/node_modules/fs-extra/lib/ensure/file.js +31 -34
- package/dist/node_modules/fs-extra/lib/ensure/link.js +27 -27
- package/dist/node_modules/fs-extra/lib/ensure/symlink-paths.js +57 -55
- package/dist/node_modules/fs-extra/lib/ensure/symlink-type.js +16 -13
- package/dist/node_modules/fs-extra/lib/ensure/symlink.js +29 -44
- package/dist/node_modules/fs-extra/lib/esm.mjs +68 -0
- package/dist/node_modules/fs-extra/lib/fs/index.js +29 -17
- package/dist/node_modules/fs-extra/lib/move/index.js +1 -1
- package/dist/node_modules/fs-extra/lib/move/move-sync.js +2 -1
- package/dist/node_modules/fs-extra/lib/move/move.js +38 -54
- package/dist/node_modules/fs-extra/lib/output-file/index.js +10 -19
- package/dist/node_modules/fs-extra/lib/remove/index.js +2 -7
- package/dist/node_modules/fs-extra/lib/util/stat.js +46 -42
- package/dist/node_modules/fs-extra/lib/util/utimes.js +21 -11
- package/dist/node_modules/fs-extra/package.json +11 -7
- package/dist/node_modules/simple-git/dist/cjs/index.js +4958 -0
- package/dist/node_modules/simple-git/dist/cjs/index.js.map +7 -0
- package/dist/node_modules/simple-git/dist/esm/index.js +4813 -0
- package/dist/node_modules/simple-git/dist/esm/index.js.map +7 -0
- package/dist/node_modules/simple-git/dist/esm/package.json +3 -0
- package/dist/node_modules/simple-git/{src → dist/src}/lib/api.d.ts +3 -13
- package/dist/node_modules/simple-git/dist/src/lib/args/log-format.d.ts +9 -0
- package/dist/node_modules/simple-git/dist/src/lib/args/pathspec.d.ts +3 -0
- package/dist/node_modules/simple-git/{src → dist/src}/lib/errors/git-error.d.ts +3 -2
- package/dist/node_modules/simple-git/dist/src/lib/errors/git-plugin-error.d.ts +7 -0
- package/dist/node_modules/simple-git/dist/src/lib/git-factory.d.ts +15 -0
- package/dist/node_modules/simple-git/{src → dist/src}/lib/parsers/parse-branch.d.ts +1 -1
- package/dist/node_modules/simple-git/dist/src/lib/parsers/parse-diff-summary.d.ts +3 -0
- package/dist/node_modules/simple-git/{src → dist/src}/lib/parsers/parse-list-log-summary.d.ts +2 -1
- package/dist/node_modules/simple-git/{src → dist/src}/lib/parsers/parse-pull.d.ts +2 -0
- package/dist/node_modules/simple-git/dist/src/lib/plugins/abort-plugin.d.ts +3 -0
- package/dist/node_modules/simple-git/dist/src/lib/plugins/block-unsafe-operations-plugin.d.ts +3 -0
- package/dist/node_modules/simple-git/{src → dist/src}/lib/plugins/completion-detection.plugin.d.ts +1 -1
- package/dist/node_modules/simple-git/dist/src/lib/plugins/custom-binary.plugin.d.ts +3 -0
- package/dist/node_modules/simple-git/{src → dist/src}/lib/plugins/index.d.ts +3 -0
- package/dist/node_modules/simple-git/dist/src/lib/plugins/plugin-store.d.ts +11 -0
- package/dist/node_modules/simple-git/{src → dist/src}/lib/plugins/progress-monitor-plugin.d.ts +1 -1
- package/dist/node_modules/simple-git/{src → dist/src}/lib/plugins/simple-git-plugin.d.ts +10 -0
- package/dist/node_modules/simple-git/dist/src/lib/plugins/suffix-paths.plugin.d.ts +2 -0
- package/dist/node_modules/simple-git/dist/src/lib/plugins/timout-plugin.d.ts +3 -0
- package/dist/node_modules/simple-git/dist/src/lib/responses/BranchSummary.d.ts +14 -0
- package/dist/node_modules/simple-git/{src → dist/src}/lib/responses/FileStatusSummary.d.ts +1 -1
- package/dist/node_modules/simple-git/dist/src/lib/responses/PullSummary.d.ts +25 -0
- package/dist/node_modules/simple-git/{src → dist/src}/lib/responses/StatusSummary.d.ts +2 -1
- package/dist/node_modules/simple-git/{src → dist/src}/lib/runners/git-executor-chain.d.ts +1 -1
- package/dist/node_modules/simple-git/{src → dist/src}/lib/runners/git-executor.d.ts +3 -4
- package/dist/node_modules/simple-git/dist/src/lib/tasks/checkout.d.ts +2 -0
- package/dist/node_modules/simple-git/{src → dist/src}/lib/tasks/clone.d.ts +3 -2
- package/dist/node_modules/simple-git/dist/src/lib/tasks/commit.d.ts +4 -0
- package/dist/node_modules/simple-git/{src → dist/src}/lib/tasks/config.d.ts +1 -1
- package/dist/node_modules/simple-git/dist/src/lib/tasks/count-objects.d.ts +12 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/diff-name-status.d.ts +12 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/diff.d.ts +5 -0
- package/dist/node_modules/simple-git/{src → dist/src}/lib/tasks/fetch.d.ts +2 -1
- package/dist/node_modules/simple-git/dist/src/lib/tasks/first-commit.d.ts +2 -0
- package/dist/node_modules/simple-git/{src → dist/src}/lib/tasks/log.d.ts +3 -3
- package/dist/node_modules/simple-git/{src → dist/src}/lib/tasks/remote.d.ts +3 -3
- package/dist/node_modules/simple-git/dist/src/lib/tasks/show.d.ts +2 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/stash-list.d.ts +4 -0
- package/dist/node_modules/simple-git/{src → dist/src}/lib/tasks/task.d.ts +1 -1
- package/dist/node_modules/simple-git/dist/src/lib/tasks/version.d.ts +9 -0
- package/dist/node_modules/simple-git/{src → dist/src}/lib/types/index.d.ts +64 -5
- package/dist/node_modules/simple-git/{src → dist/src}/lib/utils/exit-codes.d.ts +1 -0
- package/dist/node_modules/simple-git/{src → dist/src}/lib/utils/line-parser.d.ts +1 -1
- package/dist/node_modules/simple-git/{src → dist/src}/lib/utils/task-parser.d.ts +2 -2
- package/dist/node_modules/simple-git/{src → dist/src}/lib/utils/util.d.ts +3 -1
- package/dist/node_modules/simple-git/{typings → dist/typings}/errors.d.ts +0 -1
- package/dist/node_modules/simple-git/{typings → dist/typings}/index.d.ts +2 -1
- package/dist/node_modules/simple-git/{typings → dist/typings}/response.d.ts +68 -25
- package/dist/node_modules/simple-git/{typings → dist/typings}/simple-git.d.ts +493 -110
- package/dist/node_modules/simple-git/dist/typings/types.d.ts +23 -0
- package/dist/node_modules/simple-git/package.json +32 -35
- package/dist/node_modules/simple-git/promise.js +14 -4
- package/dist/node_modules/simple-git/readme.md +372 -389
- package/dist/node_modules/undici-types/README.md +6 -0
- package/dist/node_modules/undici-types/agent.d.ts +31 -0
- package/dist/node_modules/undici-types/api.d.ts +43 -0
- package/dist/node_modules/undici-types/balanced-pool.d.ts +18 -0
- package/dist/node_modules/undici-types/cache.d.ts +36 -0
- package/dist/node_modules/undici-types/client.d.ts +97 -0
- package/dist/node_modules/undici-types/connector.d.ts +34 -0
- package/dist/node_modules/undici-types/content-type.d.ts +21 -0
- package/dist/node_modules/undici-types/cookies.d.ts +28 -0
- package/dist/node_modules/undici-types/diagnostics-channel.d.ts +67 -0
- package/dist/node_modules/undici-types/dispatcher.d.ts +241 -0
- package/dist/node_modules/undici-types/errors.d.ts +128 -0
- package/dist/node_modules/undici-types/fetch.d.ts +209 -0
- package/dist/node_modules/undici-types/file.d.ts +39 -0
- package/dist/node_modules/undici-types/filereader.d.ts +54 -0
- package/dist/node_modules/undici-types/formdata.d.ts +108 -0
- package/dist/node_modules/undici-types/global-dispatcher.d.ts +9 -0
- package/dist/node_modules/undici-types/global-origin.d.ts +7 -0
- package/dist/node_modules/undici-types/handlers.d.ts +9 -0
- package/dist/node_modules/undici-types/header.d.ts +4 -0
- package/dist/node_modules/undici-types/index.d.ts +63 -0
- package/dist/node_modules/undici-types/interceptors.d.ts +5 -0
- package/dist/node_modules/undici-types/mock-agent.d.ts +50 -0
- package/dist/node_modules/undici-types/mock-client.d.ts +25 -0
- package/dist/node_modules/undici-types/mock-errors.d.ts +12 -0
- package/dist/node_modules/undici-types/mock-interceptor.d.ts +93 -0
- package/dist/node_modules/undici-types/mock-pool.d.ts +25 -0
- package/dist/node_modules/undici-types/package.json +55 -0
- package/dist/node_modules/undici-types/patch.d.ts +71 -0
- package/dist/node_modules/undici-types/pool-stats.d.ts +19 -0
- package/dist/node_modules/undici-types/pool.d.ts +28 -0
- package/dist/node_modules/undici-types/proxy-agent.d.ts +30 -0
- package/dist/node_modules/undici-types/readable.d.ts +61 -0
- package/dist/node_modules/undici-types/webidl.d.ts +220 -0
- package/dist/node_modules/undici-types/websocket.d.ts +131 -0
- package/dist/package-lock.json +10146 -0
- package/dist/package.json +23 -23
- package/dist/schemas/variant.json +5 -21
- package/package.json +24 -24
- package/dist/node_modules/@types/node/ts4.8/assert.d.ts +0 -130
- package/dist/node_modules/@types/node/ts4.8/async_hooks.d.ts +0 -237
- package/dist/node_modules/@types/node/ts4.8/buffer.d.ts +0 -89
- package/dist/node_modules/@types/node/ts4.8/child_process.d.ts +0 -682
- package/dist/node_modules/@types/node/ts4.8/cluster.d.ts +0 -300
- package/dist/node_modules/@types/node/ts4.8/console.d.ts +0 -142
- package/dist/node_modules/@types/node/ts4.8/constants.d.ts +0 -19
- package/dist/node_modules/@types/node/ts4.8/crypto.d.ts +0 -1287
- package/dist/node_modules/@types/node/ts4.8/dgram.d.ts +0 -180
- package/dist/node_modules/@types/node/ts4.8/dns.d.ts +0 -516
- package/dist/node_modules/@types/node/ts4.8/domain.d.ts +0 -27
- package/dist/node_modules/@types/node/ts4.8/events.d.ts +0 -82
- package/dist/node_modules/@types/node/ts4.8/fs/promises.d.ts +0 -634
- package/dist/node_modules/@types/node/ts4.8/fs.d.ts +0 -2587
- package/dist/node_modules/@types/node/ts4.8/globals.d.ts +0 -763
- package/dist/node_modules/@types/node/ts4.8/globals.global.d.ts +0 -1
- package/dist/node_modules/@types/node/ts4.8/http.d.ts +0 -580
- package/dist/node_modules/@types/node/ts4.8/http2.d.ts +0 -1208
- package/dist/node_modules/@types/node/ts4.8/https.d.ts +0 -274
- package/dist/node_modules/@types/node/ts4.8/index.d.ts +0 -53
- package/dist/node_modules/@types/node/ts4.8/inspector.d.ts +0 -3050
- package/dist/node_modules/@types/node/ts4.8/module.d.ts +0 -56
- package/dist/node_modules/@types/node/ts4.8/net.d.ts +0 -324
- package/dist/node_modules/@types/node/ts4.8/os.d.ts +0 -243
- package/dist/node_modules/@types/node/ts4.8/path.d.ts +0 -168
- package/dist/node_modules/@types/node/ts4.8/perf_hooks.d.ts +0 -274
- package/dist/node_modules/@types/node/ts4.8/process.d.ts +0 -452
- package/dist/node_modules/@types/node/ts4.8/punycode.d.ts +0 -78
- package/dist/node_modules/@types/node/ts4.8/querystring.d.ts +0 -41
- package/dist/node_modules/@types/node/ts4.8/readline.d.ts +0 -184
- package/dist/node_modules/@types/node/ts4.8/repl.d.ts +0 -404
- package/dist/node_modules/@types/node/ts4.8/stream.d.ts +0 -518
- package/dist/node_modules/@types/node/ts4.8/string_decoder.d.ts +0 -10
- package/dist/node_modules/@types/node/ts4.8/timers.d.ts +0 -19
- package/dist/node_modules/@types/node/ts4.8/tls.d.ts +0 -866
- package/dist/node_modules/@types/node/ts4.8/trace_events.d.ts +0 -64
- package/dist/node_modules/@types/node/ts4.8/tty.d.ts +0 -69
- package/dist/node_modules/@types/node/ts4.8/url.d.ts +0 -187
- package/dist/node_modules/@types/node/ts4.8/util.d.ts +0 -278
- package/dist/node_modules/@types/node/ts4.8/v8.d.ts +0 -189
- package/dist/node_modules/@types/node/ts4.8/vm.d.ts +0 -155
- package/dist/node_modules/@types/node/ts4.8/wasi.d.ts +0 -88
- package/dist/node_modules/@types/node/ts4.8/worker_threads.d.ts +0 -241
- package/dist/node_modules/@types/node/ts4.8/zlib.d.ts +0 -364
- package/dist/node_modules/fs-extra/lib/remove/rimraf.js +0 -302
- package/dist/node_modules/simple-git/CHANGELOG.md +0 -529
- package/dist/node_modules/simple-git/LICENSE +0 -20
- package/dist/node_modules/simple-git/promise.d.ts +0 -46
- package/dist/node_modules/simple-git/src/git.js +0 -700
- package/dist/node_modules/simple-git/src/index.js +0 -7
- package/dist/node_modules/simple-git/src/lib/api.js +0 -26
- package/dist/node_modules/simple-git/src/lib/api.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/errors/git-construct-error.js +0 -21
- package/dist/node_modules/simple-git/src/lib/errors/git-construct-error.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/errors/git-error.js +0 -37
- package/dist/node_modules/simple-git/src/lib/errors/git-error.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/errors/git-plugin-error.d.ts +0 -6
- package/dist/node_modules/simple-git/src/lib/errors/git-plugin-error.js +0 -14
- package/dist/node_modules/simple-git/src/lib/errors/git-plugin-error.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/errors/git-response-error.js +0 -36
- package/dist/node_modules/simple-git/src/lib/errors/git-response-error.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/errors/task-configuration-error.js +0 -19
- package/dist/node_modules/simple-git/src/lib/errors/task-configuration-error.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/git-factory.d.ts +0 -25
- package/dist/node_modules/simple-git/src/lib/git-factory.js +0 -45
- package/dist/node_modules/simple-git/src/lib/git-factory.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/git-logger.js +0 -101
- package/dist/node_modules/simple-git/src/lib/git-logger.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/parsers/parse-branch-delete.js +0 -29
- package/dist/node_modules/simple-git/src/lib/parsers/parse-branch-delete.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/parsers/parse-branch.js +0 -18
- package/dist/node_modules/simple-git/src/lib/parsers/parse-branch.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/parsers/parse-commit.js +0 -53
- package/dist/node_modules/simple-git/src/lib/parsers/parse-commit.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/parsers/parse-diff-summary.d.ts +0 -2
- package/dist/node_modules/simple-git/src/lib/parsers/parse-diff-summary.js +0 -74
- package/dist/node_modules/simple-git/src/lib/parsers/parse-diff-summary.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/parsers/parse-fetch.js +0 -32
- package/dist/node_modules/simple-git/src/lib/parsers/parse-fetch.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/parsers/parse-list-log-summary.js +0 -35
- package/dist/node_modules/simple-git/src/lib/parsers/parse-list-log-summary.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/parsers/parse-merge.js +0 -39
- package/dist/node_modules/simple-git/src/lib/parsers/parse-merge.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/parsers/parse-move.js +0 -14
- package/dist/node_modules/simple-git/src/lib/parsers/parse-move.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/parsers/parse-pull.js +0 -42
- package/dist/node_modules/simple-git/src/lib/parsers/parse-pull.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/parsers/parse-push.js +0 -58
- package/dist/node_modules/simple-git/src/lib/parsers/parse-push.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/parsers/parse-remote-messages.js +0 -33
- package/dist/node_modules/simple-git/src/lib/parsers/parse-remote-messages.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/parsers/parse-remote-objects.js +0 -41
- package/dist/node_modules/simple-git/src/lib/parsers/parse-remote-objects.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/plugins/command-config-prefixing-plugin.js +0 -15
- package/dist/node_modules/simple-git/src/lib/plugins/command-config-prefixing-plugin.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/plugins/completion-detection.plugin.js +0 -80
- package/dist/node_modules/simple-git/src/lib/plugins/completion-detection.plugin.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/plugins/error-detection.plugin.js +0 -39
- package/dist/node_modules/simple-git/src/lib/plugins/error-detection.plugin.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/plugins/index.js +0 -21
- package/dist/node_modules/simple-git/src/lib/plugins/index.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/plugins/plugin-store.d.ts +0 -6
- package/dist/node_modules/simple-git/src/lib/plugins/plugin-store.js +0 -28
- package/dist/node_modules/simple-git/src/lib/plugins/plugin-store.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/plugins/progress-monitor-plugin.js +0 -45
- package/dist/node_modules/simple-git/src/lib/plugins/progress-monitor-plugin.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/plugins/simple-git-plugin.js +0 -3
- package/dist/node_modules/simple-git/src/lib/plugins/simple-git-plugin.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/plugins/spawn-options-plugin.js +0 -15
- package/dist/node_modules/simple-git/src/lib/plugins/spawn-options-plugin.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/plugins/timout-plugin.d.ts +0 -3
- package/dist/node_modules/simple-git/src/lib/plugins/timout-plugin.js +0 -37
- package/dist/node_modules/simple-git/src/lib/plugins/timout-plugin.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/responses/BranchDeleteSummary.js +0 -31
- package/dist/node_modules/simple-git/src/lib/responses/BranchDeleteSummary.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/responses/BranchSummary.d.ts +0 -10
- package/dist/node_modules/simple-git/src/lib/responses/BranchSummary.js +0 -26
- package/dist/node_modules/simple-git/src/lib/responses/BranchSummary.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/responses/CheckIgnore.js +0 -13
- package/dist/node_modules/simple-git/src/lib/responses/CheckIgnore.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/responses/CleanSummary.js +0 -28
- package/dist/node_modules/simple-git/src/lib/responses/CleanSummary.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/responses/ConfigList.js +0 -89
- package/dist/node_modules/simple-git/src/lib/responses/ConfigList.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/responses/DiffSummary.js +0 -16
- package/dist/node_modules/simple-git/src/lib/responses/DiffSummary.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/responses/FileStatusSummary.js +0 -18
- package/dist/node_modules/simple-git/src/lib/responses/FileStatusSummary.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/responses/GetRemoteSummary.js +0 -30
- package/dist/node_modules/simple-git/src/lib/responses/GetRemoteSummary.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/responses/InitSummary.js +0 -36
- package/dist/node_modules/simple-git/src/lib/responses/InitSummary.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/responses/MergeSummary.js +0 -35
- package/dist/node_modules/simple-git/src/lib/responses/MergeSummary.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/responses/PullSummary.d.ts +0 -12
- package/dist/node_modules/simple-git/src/lib/responses/PullSummary.js +0 -22
- package/dist/node_modules/simple-git/src/lib/responses/PullSummary.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/responses/StatusSummary.js +0 -128
- package/dist/node_modules/simple-git/src/lib/responses/StatusSummary.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/responses/TagList.js +0 -56
- package/dist/node_modules/simple-git/src/lib/responses/TagList.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/runners/git-executor-chain.js +0 -173
- package/dist/node_modules/simple-git/src/lib/runners/git-executor-chain.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/runners/git-executor.js +0 -21
- package/dist/node_modules/simple-git/src/lib/runners/git-executor.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/runners/promise-wrapped.js +0 -133
- package/dist/node_modules/simple-git/src/lib/runners/promise-wrapped.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/runners/scheduler.js +0 -48
- package/dist/node_modules/simple-git/src/lib/runners/scheduler.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/runners/tasks-pending-queue.js +0 -64
- package/dist/node_modules/simple-git/src/lib/runners/tasks-pending-queue.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/simple-git-api.js +0 -80
- package/dist/node_modules/simple-git/src/lib/simple-git-api.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/task-callback.js +0 -39
- package/dist/node_modules/simple-git/src/lib/task-callback.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/tasks/apply-patch.js +0 -9
- package/dist/node_modules/simple-git/src/lib/tasks/apply-patch.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/tasks/branch.js +0 -76
- package/dist/node_modules/simple-git/src/lib/tasks/branch.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/tasks/change-working-directory.js +0 -15
- package/dist/node_modules/simple-git/src/lib/tasks/change-working-directory.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/tasks/check-ignore.js +0 -13
- package/dist/node_modules/simple-git/src/lib/tasks/check-ignore.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/tasks/check-is-repo.js +0 -61
- package/dist/node_modules/simple-git/src/lib/tasks/check-is-repo.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/tasks/clean.js +0 -85
- package/dist/node_modules/simple-git/src/lib/tasks/clean.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/tasks/clone.js +0 -22
- package/dist/node_modules/simple-git/src/lib/tasks/clone.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/tasks/commit.d.ts +0 -3
- package/dist/node_modules/simple-git/src/lib/tasks/commit.js +0 -16
- package/dist/node_modules/simple-git/src/lib/tasks/commit.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/tasks/config.js +0 -73
- package/dist/node_modules/simple-git/src/lib/tasks/config.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/tasks/diff.d.ts +0 -3
- package/dist/node_modules/simple-git/src/lib/tasks/diff.js +0 -15
- package/dist/node_modules/simple-git/src/lib/tasks/diff.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/tasks/fetch.js +0 -17
- package/dist/node_modules/simple-git/src/lib/tasks/fetch.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/tasks/grep.js +0 -76
- package/dist/node_modules/simple-git/src/lib/tasks/grep.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/tasks/hash-object.js +0 -16
- package/dist/node_modules/simple-git/src/lib/tasks/hash-object.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/tasks/init.js +0 -23
- package/dist/node_modules/simple-git/src/lib/tasks/init.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/tasks/log.js +0 -109
- package/dist/node_modules/simple-git/src/lib/tasks/log.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/tasks/merge.js +0 -24
- package/dist/node_modules/simple-git/src/lib/tasks/merge.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/tasks/move.js +0 -14
- package/dist/node_modules/simple-git/src/lib/tasks/move.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/tasks/pull.js +0 -19
- package/dist/node_modules/simple-git/src/lib/tasks/pull.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/tasks/push.js +0 -29
- package/dist/node_modules/simple-git/src/lib/tasks/push.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/tasks/remote.js +0 -42
- package/dist/node_modules/simple-git/src/lib/tasks/remote.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/tasks/reset.js +0 -38
- package/dist/node_modules/simple-git/src/lib/tasks/reset.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/tasks/stash-list.d.ts +0 -3
- package/dist/node_modules/simple-git/src/lib/tasks/stash-list.js +0 -16
- package/dist/node_modules/simple-git/src/lib/tasks/stash-list.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/tasks/status.js +0 -15
- package/dist/node_modules/simple-git/src/lib/tasks/status.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/tasks/sub-module.js +0 -25
- package/dist/node_modules/simple-git/src/lib/tasks/sub-module.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/tasks/tag.js +0 -45
- package/dist/node_modules/simple-git/src/lib/tasks/tag.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/tasks/task.js +0 -52
- package/dist/node_modules/simple-git/src/lib/tasks/task.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/types/handlers.js +0 -3
- package/dist/node_modules/simple-git/src/lib/types/handlers.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/types/index.js +0 -15
- package/dist/node_modules/simple-git/src/lib/types/index.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/types/tasks.js +0 -3
- package/dist/node_modules/simple-git/src/lib/types/tasks.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/utils/argument-filters.js +0 -47
- package/dist/node_modules/simple-git/src/lib/utils/argument-filters.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/utils/exit-codes.js +0 -14
- package/dist/node_modules/simple-git/src/lib/utils/exit-codes.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/utils/git-output-streams.js +0 -14
- package/dist/node_modules/simple-git/src/lib/utils/git-output-streams.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/utils/index.js +0 -21
- package/dist/node_modules/simple-git/src/lib/utils/index.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/utils/line-parser.js +0 -52
- package/dist/node_modules/simple-git/src/lib/utils/line-parser.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/utils/simple-git-options.js +0 -16
- package/dist/node_modules/simple-git/src/lib/utils/simple-git-options.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/utils/task-options.js +0 -58
- package/dist/node_modules/simple-git/src/lib/utils/task-options.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/utils/task-parser.js +0 -24
- package/dist/node_modules/simple-git/src/lib/utils/task-parser.js.map +0 -1
- package/dist/node_modules/simple-git/src/lib/utils/util.js +0 -146
- package/dist/node_modules/simple-git/src/lib/utils/util.js.map +0 -1
- package/dist/node_modules/simple-git/typings/types.d.ts +0 -14
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/errors/git-construct-error.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/errors/git-response-error.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/errors/task-configuration-error.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/git-logger.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/parsers/parse-branch-delete.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/parsers/parse-commit.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/parsers/parse-fetch.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/parsers/parse-merge.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/parsers/parse-move.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/parsers/parse-push.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/parsers/parse-remote-messages.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/parsers/parse-remote-objects.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/plugins/command-config-prefixing-plugin.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/plugins/error-detection.plugin.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/plugins/spawn-options-plugin.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/responses/BranchDeleteSummary.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/responses/CheckIgnore.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/responses/CleanSummary.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/responses/ConfigList.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/responses/DiffSummary.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/responses/GetRemoteSummary.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/responses/InitSummary.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/responses/MergeSummary.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/responses/TagList.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/runners/promise-wrapped.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/runners/scheduler.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/runners/tasks-pending-queue.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/simple-git-api.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/task-callback.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/tasks/apply-patch.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/tasks/branch.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/tasks/change-working-directory.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/tasks/check-ignore.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/tasks/check-is-repo.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/tasks/clean.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/tasks/grep.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/tasks/hash-object.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/tasks/init.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/tasks/merge.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/tasks/move.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/tasks/pull.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/tasks/push.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/tasks/reset.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/tasks/status.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/tasks/sub-module.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/tasks/tag.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/types/handlers.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/types/tasks.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/utils/argument-filters.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/utils/git-output-streams.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/utils/index.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/utils/simple-git-options.d.ts +0 -0
- /package/dist/node_modules/simple-git/{src → dist/src}/lib/utils/task-options.d.ts +0 -0
|
@@ -1,12 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* To use the HTTP server and client one must `require('node:http')`.
|
|
3
|
+
*
|
|
4
|
+
* The HTTP interfaces in Node.js are designed to support many features
|
|
5
|
+
* of the protocol which have been traditionally difficult to use.
|
|
6
|
+
* In particular, large, possibly chunk-encoded, messages. The interface is
|
|
7
|
+
* careful to never buffer entire requests or responses, so the
|
|
8
|
+
* user is able to stream data.
|
|
9
|
+
*
|
|
10
|
+
* HTTP message headers are represented by an object like this:
|
|
11
|
+
*
|
|
12
|
+
* ```json
|
|
13
|
+
* { "content-length": "123",
|
|
14
|
+
* "content-type": "text/plain",
|
|
15
|
+
* "connection": "keep-alive",
|
|
16
|
+
* "host": "example.com",
|
|
17
|
+
* "accept": "*" }
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* Keys are lowercased. Values are not modified.
|
|
21
|
+
*
|
|
22
|
+
* In order to support the full spectrum of possible HTTP applications, the Node.js
|
|
23
|
+
* HTTP API is very low-level. It deals with stream handling and message
|
|
24
|
+
* parsing only. It parses a message into headers and body but it does not
|
|
25
|
+
* parse the actual headers or the body.
|
|
26
|
+
*
|
|
27
|
+
* See `message.headers` for details on how duplicate headers are handled.
|
|
28
|
+
*
|
|
29
|
+
* The raw headers as they were received are retained in the `rawHeaders` property, which is an array of `[key, value, key2, value2, ...]`. For
|
|
30
|
+
* example, the previous message header object might have a `rawHeaders` list like the following:
|
|
31
|
+
*
|
|
32
|
+
* ```js
|
|
33
|
+
* [ 'ConTent-Length', '123456',
|
|
34
|
+
* 'content-LENGTH', '123',
|
|
35
|
+
* 'content-type', 'text/plain',
|
|
36
|
+
* 'CONNECTION', 'keep-alive',
|
|
37
|
+
* 'Host', 'example.com',
|
|
38
|
+
* 'accepT', '*' ]
|
|
39
|
+
* ```
|
|
40
|
+
* @see [source](https://github.com/nodejs/node/blob/v20.13.1/lib/http.js)
|
|
41
|
+
*/
|
|
1
42
|
declare module "http" {
|
|
2
|
-
import * as stream from "stream";
|
|
3
|
-
import { URL } from "url";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
43
|
+
import * as stream from "node:stream";
|
|
44
|
+
import { URL } from "node:url";
|
|
45
|
+
import { LookupOptions } from "node:dns";
|
|
46
|
+
import { EventEmitter } from "node:events";
|
|
47
|
+
import { LookupFunction, Server as NetServer, Socket, TcpSocketConnectOpts } from "node:net";
|
|
7
48
|
// incoming headers will never contain number
|
|
8
49
|
interface IncomingHttpHeaders extends NodeJS.Dict<string | string[]> {
|
|
9
|
-
|
|
50
|
+
accept?: string | undefined;
|
|
10
51
|
"accept-language"?: string | undefined;
|
|
11
52
|
"accept-patch"?: string | undefined;
|
|
12
53
|
"accept-ranges"?: string | undefined;
|
|
@@ -18,12 +59,12 @@ declare module "http" {
|
|
|
18
59
|
"access-control-max-age"?: string | undefined;
|
|
19
60
|
"access-control-request-headers"?: string | undefined;
|
|
20
61
|
"access-control-request-method"?: string | undefined;
|
|
21
|
-
|
|
22
|
-
|
|
62
|
+
age?: string | undefined;
|
|
63
|
+
allow?: string | undefined;
|
|
23
64
|
"alt-svc"?: string | undefined;
|
|
24
|
-
|
|
65
|
+
authorization?: string | undefined;
|
|
25
66
|
"cache-control"?: string | undefined;
|
|
26
|
-
|
|
67
|
+
connection?: string | undefined;
|
|
27
68
|
"content-disposition"?: string | undefined;
|
|
28
69
|
"content-encoding"?: string | undefined;
|
|
29
70
|
"content-language"?: string | undefined;
|
|
@@ -31,27 +72,27 @@ declare module "http" {
|
|
|
31
72
|
"content-location"?: string | undefined;
|
|
32
73
|
"content-range"?: string | undefined;
|
|
33
74
|
"content-type"?: string | undefined;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
75
|
+
cookie?: string | undefined;
|
|
76
|
+
date?: string | undefined;
|
|
77
|
+
etag?: string | undefined;
|
|
78
|
+
expect?: string | undefined;
|
|
79
|
+
expires?: string | undefined;
|
|
80
|
+
forwarded?: string | undefined;
|
|
81
|
+
from?: string | undefined;
|
|
82
|
+
host?: string | undefined;
|
|
42
83
|
"if-match"?: string | undefined;
|
|
43
84
|
"if-modified-since"?: string | undefined;
|
|
44
85
|
"if-none-match"?: string | undefined;
|
|
45
86
|
"if-unmodified-since"?: string | undefined;
|
|
46
87
|
"last-modified"?: string | undefined;
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
88
|
+
location?: string | undefined;
|
|
89
|
+
origin?: string | undefined;
|
|
90
|
+
pragma?: string | undefined;
|
|
50
91
|
"proxy-authenticate"?: string | undefined;
|
|
51
92
|
"proxy-authorization"?: string | undefined;
|
|
52
93
|
"public-key-pins"?: string | undefined;
|
|
53
|
-
|
|
54
|
-
|
|
94
|
+
range?: string | undefined;
|
|
95
|
+
referer?: string | undefined;
|
|
55
96
|
"retry-after"?: string | undefined;
|
|
56
97
|
"sec-websocket-accept"?: string | undefined;
|
|
57
98
|
"sec-websocket-extensions"?: string | undefined;
|
|
@@ -60,105 +101,328 @@ declare module "http" {
|
|
|
60
101
|
"sec-websocket-version"?: string | undefined;
|
|
61
102
|
"set-cookie"?: string[] | undefined;
|
|
62
103
|
"strict-transport-security"?: string | undefined;
|
|
63
|
-
|
|
64
|
-
|
|
104
|
+
tk?: string | undefined;
|
|
105
|
+
trailer?: string | undefined;
|
|
65
106
|
"transfer-encoding"?: string | undefined;
|
|
66
|
-
|
|
107
|
+
upgrade?: string | undefined;
|
|
67
108
|
"user-agent"?: string | undefined;
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
109
|
+
vary?: string | undefined;
|
|
110
|
+
via?: string | undefined;
|
|
111
|
+
warning?: string | undefined;
|
|
71
112
|
"www-authenticate"?: string | undefined;
|
|
72
113
|
}
|
|
73
|
-
|
|
74
114
|
// outgoing headers allows numbers (as they are converted internally to strings)
|
|
75
115
|
type OutgoingHttpHeader = number | string | string[];
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
116
|
+
interface OutgoingHttpHeaders extends NodeJS.Dict<OutgoingHttpHeader> {
|
|
117
|
+
accept?: string | string[] | undefined;
|
|
118
|
+
"accept-charset"?: string | string[] | undefined;
|
|
119
|
+
"accept-encoding"?: string | string[] | undefined;
|
|
120
|
+
"accept-language"?: string | string[] | undefined;
|
|
121
|
+
"accept-ranges"?: string | undefined;
|
|
122
|
+
"access-control-allow-credentials"?: string | undefined;
|
|
123
|
+
"access-control-allow-headers"?: string | undefined;
|
|
124
|
+
"access-control-allow-methods"?: string | undefined;
|
|
125
|
+
"access-control-allow-origin"?: string | undefined;
|
|
126
|
+
"access-control-expose-headers"?: string | undefined;
|
|
127
|
+
"access-control-max-age"?: string | undefined;
|
|
128
|
+
"access-control-request-headers"?: string | undefined;
|
|
129
|
+
"access-control-request-method"?: string | undefined;
|
|
130
|
+
age?: string | undefined;
|
|
131
|
+
allow?: string | undefined;
|
|
132
|
+
authorization?: string | undefined;
|
|
133
|
+
"cache-control"?: string | undefined;
|
|
134
|
+
"cdn-cache-control"?: string | undefined;
|
|
135
|
+
connection?: string | string[] | undefined;
|
|
136
|
+
"content-disposition"?: string | undefined;
|
|
137
|
+
"content-encoding"?: string | undefined;
|
|
138
|
+
"content-language"?: string | undefined;
|
|
139
|
+
"content-length"?: string | number | undefined;
|
|
140
|
+
"content-location"?: string | undefined;
|
|
141
|
+
"content-range"?: string | undefined;
|
|
142
|
+
"content-security-policy"?: string | undefined;
|
|
143
|
+
"content-security-policy-report-only"?: string | undefined;
|
|
144
|
+
cookie?: string | string[] | undefined;
|
|
145
|
+
dav?: string | string[] | undefined;
|
|
146
|
+
dnt?: string | undefined;
|
|
147
|
+
date?: string | undefined;
|
|
148
|
+
etag?: string | undefined;
|
|
149
|
+
expect?: string | undefined;
|
|
150
|
+
expires?: string | undefined;
|
|
151
|
+
forwarded?: string | undefined;
|
|
152
|
+
from?: string | undefined;
|
|
153
|
+
host?: string | undefined;
|
|
154
|
+
"if-match"?: string | undefined;
|
|
155
|
+
"if-modified-since"?: string | undefined;
|
|
156
|
+
"if-none-match"?: string | undefined;
|
|
157
|
+
"if-range"?: string | undefined;
|
|
158
|
+
"if-unmodified-since"?: string | undefined;
|
|
159
|
+
"last-modified"?: string | undefined;
|
|
160
|
+
link?: string | string[] | undefined;
|
|
161
|
+
location?: string | undefined;
|
|
162
|
+
"max-forwards"?: string | undefined;
|
|
163
|
+
origin?: string | undefined;
|
|
164
|
+
prgama?: string | string[] | undefined;
|
|
165
|
+
"proxy-authenticate"?: string | string[] | undefined;
|
|
166
|
+
"proxy-authorization"?: string | undefined;
|
|
167
|
+
"public-key-pins"?: string | undefined;
|
|
168
|
+
"public-key-pins-report-only"?: string | undefined;
|
|
169
|
+
range?: string | undefined;
|
|
170
|
+
referer?: string | undefined;
|
|
171
|
+
"referrer-policy"?: string | undefined;
|
|
172
|
+
refresh?: string | undefined;
|
|
173
|
+
"retry-after"?: string | undefined;
|
|
174
|
+
"sec-websocket-accept"?: string | undefined;
|
|
175
|
+
"sec-websocket-extensions"?: string | string[] | undefined;
|
|
176
|
+
"sec-websocket-key"?: string | undefined;
|
|
177
|
+
"sec-websocket-protocol"?: string | string[] | undefined;
|
|
178
|
+
"sec-websocket-version"?: string | undefined;
|
|
179
|
+
server?: string | undefined;
|
|
180
|
+
"set-cookie"?: string | string[] | undefined;
|
|
181
|
+
"strict-transport-security"?: string | undefined;
|
|
182
|
+
te?: string | undefined;
|
|
183
|
+
trailer?: string | undefined;
|
|
184
|
+
"transfer-encoding"?: string | undefined;
|
|
185
|
+
"user-agent"?: string | undefined;
|
|
186
|
+
upgrade?: string | undefined;
|
|
187
|
+
"upgrade-insecure-requests"?: string | undefined;
|
|
188
|
+
vary?: string | undefined;
|
|
189
|
+
via?: string | string[] | undefined;
|
|
190
|
+
warning?: string | undefined;
|
|
191
|
+
"www-authenticate"?: string | string[] | undefined;
|
|
192
|
+
"x-content-type-options"?: string | undefined;
|
|
193
|
+
"x-dns-prefetch-control"?: string | undefined;
|
|
194
|
+
"x-frame-options"?: string | undefined;
|
|
195
|
+
"x-xss-protection"?: string | undefined;
|
|
196
|
+
}
|
|
79
197
|
interface ClientRequestArgs {
|
|
80
|
-
|
|
198
|
+
_defaultAgent?: Agent | undefined;
|
|
199
|
+
agent?: Agent | boolean | undefined;
|
|
200
|
+
auth?: string | null | undefined;
|
|
201
|
+
createConnection?:
|
|
202
|
+
| ((
|
|
203
|
+
options: ClientRequestArgs,
|
|
204
|
+
oncreate: (err: Error | null, socket: stream.Duplex) => void,
|
|
205
|
+
) => stream.Duplex | null | undefined)
|
|
206
|
+
| undefined;
|
|
207
|
+
defaultPort?: number | string | undefined;
|
|
208
|
+
family?: number | undefined;
|
|
209
|
+
headers?: OutgoingHttpHeaders | undefined;
|
|
210
|
+
hints?: LookupOptions["hints"];
|
|
81
211
|
host?: string | null | undefined;
|
|
82
212
|
hostname?: string | null | undefined;
|
|
83
|
-
|
|
84
|
-
port?: number | string | null | undefined;
|
|
85
|
-
defaultPort?: number | string | undefined;
|
|
213
|
+
insecureHTTPParser?: boolean | undefined;
|
|
86
214
|
localAddress?: string | undefined;
|
|
87
|
-
|
|
215
|
+
localPort?: number | undefined;
|
|
216
|
+
lookup?: LookupFunction | undefined;
|
|
88
217
|
/**
|
|
89
|
-
* @default
|
|
218
|
+
* @default 16384
|
|
90
219
|
*/
|
|
91
220
|
maxHeaderSize?: number | undefined;
|
|
92
221
|
method?: string | undefined;
|
|
93
222
|
path?: string | null | undefined;
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
agent?: Agent | boolean | undefined;
|
|
97
|
-
_defaultAgent?: Agent | undefined;
|
|
98
|
-
timeout?: number | undefined;
|
|
223
|
+
port?: number | string | null | undefined;
|
|
224
|
+
protocol?: string | null | undefined;
|
|
99
225
|
setHost?: boolean | undefined;
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
226
|
+
signal?: AbortSignal | undefined;
|
|
227
|
+
socketPath?: string | undefined;
|
|
228
|
+
timeout?: number | undefined;
|
|
229
|
+
uniqueHeaders?: Array<string | string[]> | undefined;
|
|
230
|
+
joinDuplicateHeaders?: boolean;
|
|
105
231
|
}
|
|
106
|
-
|
|
107
232
|
interface ServerOptions<
|
|
108
233
|
Request extends typeof IncomingMessage = typeof IncomingMessage,
|
|
109
234
|
Response extends typeof ServerResponse = typeof ServerResponse,
|
|
110
235
|
> {
|
|
236
|
+
/**
|
|
237
|
+
* Specifies the `IncomingMessage` class to be used. Useful for extending the original `IncomingMessage`.
|
|
238
|
+
*/
|
|
111
239
|
IncomingMessage?: Request | undefined;
|
|
240
|
+
/**
|
|
241
|
+
* Specifies the `ServerResponse` class to be used. Useful for extending the original `ServerResponse`.
|
|
242
|
+
*/
|
|
112
243
|
ServerResponse?: Response | undefined;
|
|
113
244
|
/**
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
* @
|
|
245
|
+
* Sets the timeout value in milliseconds for receiving the entire request from the client.
|
|
246
|
+
* @see Server.requestTimeout for more information.
|
|
247
|
+
* @default 300000
|
|
248
|
+
* @since v18.0.0
|
|
118
249
|
*/
|
|
119
|
-
|
|
250
|
+
requestTimeout?: number | undefined;
|
|
251
|
+
/**
|
|
252
|
+
* It joins the field line values of multiple headers in a request with `, ` instead of discarding the duplicates.
|
|
253
|
+
* @default false
|
|
254
|
+
* @since v18.14.0
|
|
255
|
+
*/
|
|
256
|
+
joinDuplicateHeaders?: boolean;
|
|
257
|
+
/**
|
|
258
|
+
* The number of milliseconds of inactivity a server needs to wait for additional incoming data,
|
|
259
|
+
* after it has finished writing the last response, before a socket will be destroyed.
|
|
260
|
+
* @see Server.keepAliveTimeout for more information.
|
|
261
|
+
* @default 5000
|
|
262
|
+
* @since v18.0.0
|
|
263
|
+
*/
|
|
264
|
+
keepAliveTimeout?: number | undefined;
|
|
120
265
|
/**
|
|
121
|
-
*
|
|
266
|
+
* Sets the interval value in milliseconds to check for request and headers timeout in incomplete requests.
|
|
267
|
+
* @default 30000
|
|
268
|
+
*/
|
|
269
|
+
connectionsCheckingInterval?: number | undefined;
|
|
270
|
+
/**
|
|
271
|
+
* Optionally overrides all `socket`s' `readableHighWaterMark` and `writableHighWaterMark`.
|
|
272
|
+
* This affects `highWaterMark` property of both `IncomingMessage` and `ServerResponse`.
|
|
273
|
+
* Default: @see stream.getDefaultHighWaterMark().
|
|
274
|
+
* @since v20.1.0
|
|
275
|
+
*/
|
|
276
|
+
highWaterMark?: number | undefined;
|
|
277
|
+
/**
|
|
278
|
+
* Use an insecure HTTP parser that accepts invalid HTTP headers when `true`.
|
|
122
279
|
* Using the insecure parser should be avoided.
|
|
123
280
|
* See --insecure-http-parser for more information.
|
|
124
281
|
* @default false
|
|
125
282
|
*/
|
|
126
283
|
insecureHTTPParser?: boolean | undefined;
|
|
284
|
+
/**
|
|
285
|
+
* Optionally overrides the value of `--max-http-header-size` for requests received by
|
|
286
|
+
* this server, i.e. the maximum length of request headers in bytes.
|
|
287
|
+
* @default 16384
|
|
288
|
+
* @since v13.3.0
|
|
289
|
+
*/
|
|
290
|
+
maxHeaderSize?: number | undefined;
|
|
291
|
+
/**
|
|
292
|
+
* If set to `true`, it disables the use of Nagle's algorithm immediately after a new incoming connection is received.
|
|
293
|
+
* @default true
|
|
294
|
+
* @since v16.5.0
|
|
295
|
+
*/
|
|
296
|
+
noDelay?: boolean | undefined;
|
|
297
|
+
/**
|
|
298
|
+
* If set to `true`, it enables keep-alive functionality on the socket immediately after a new incoming connection is received,
|
|
299
|
+
* similarly on what is done in `socket.setKeepAlive([enable][, initialDelay])`.
|
|
300
|
+
* @default false
|
|
301
|
+
* @since v16.5.0
|
|
302
|
+
*/
|
|
303
|
+
keepAlive?: boolean | undefined;
|
|
304
|
+
/**
|
|
305
|
+
* If set to a positive number, it sets the initial delay before the first keepalive probe is sent on an idle socket.
|
|
306
|
+
* @default 0
|
|
307
|
+
* @since v16.5.0
|
|
308
|
+
*/
|
|
309
|
+
keepAliveInitialDelay?: number | undefined;
|
|
310
|
+
/**
|
|
311
|
+
* A list of response headers that should be sent only once.
|
|
312
|
+
* If the header's value is an array, the items will be joined using `; `.
|
|
313
|
+
*/
|
|
314
|
+
uniqueHeaders?: Array<string | string[]> | undefined;
|
|
127
315
|
}
|
|
128
|
-
|
|
129
316
|
type RequestListener<
|
|
130
317
|
Request extends typeof IncomingMessage = typeof IncomingMessage,
|
|
131
318
|
Response extends typeof ServerResponse = typeof ServerResponse,
|
|
132
|
-
> = (req: InstanceType<Request>, res: InstanceType<Response>) => void;
|
|
133
|
-
|
|
319
|
+
> = (req: InstanceType<Request>, res: InstanceType<Response> & { req: InstanceType<Request> }) => void;
|
|
320
|
+
/**
|
|
321
|
+
* @since v0.1.17
|
|
322
|
+
*/
|
|
134
323
|
class Server<
|
|
135
324
|
Request extends typeof IncomingMessage = typeof IncomingMessage,
|
|
136
325
|
Response extends typeof ServerResponse = typeof ServerResponse,
|
|
137
326
|
> extends NetServer {
|
|
138
327
|
constructor(requestListener?: RequestListener<Request, Response>);
|
|
139
328
|
constructor(options: ServerOptions<Request, Response>, requestListener?: RequestListener<Request, Response>);
|
|
329
|
+
/**
|
|
330
|
+
* Sets the timeout value for sockets, and emits a `'timeout'` event on
|
|
331
|
+
* the Server object, passing the socket as an argument, if a timeout
|
|
332
|
+
* occurs.
|
|
333
|
+
*
|
|
334
|
+
* If there is a `'timeout'` event listener on the Server object, then it
|
|
335
|
+
* will be called with the timed-out socket as an argument.
|
|
336
|
+
*
|
|
337
|
+
* By default, the Server does not timeout sockets. However, if a callback
|
|
338
|
+
* is assigned to the Server's `'timeout'` event, timeouts must be handled
|
|
339
|
+
* explicitly.
|
|
340
|
+
* @since v0.9.12
|
|
341
|
+
* @param [msecs=0 (no timeout)]
|
|
342
|
+
*/
|
|
140
343
|
setTimeout(msecs?: number, callback?: () => void): this;
|
|
141
344
|
setTimeout(callback: () => void): this;
|
|
142
345
|
/**
|
|
143
346
|
* Limits maximum incoming headers count. If set to 0, no limit will be applied.
|
|
144
|
-
* @
|
|
145
|
-
* {@link https://nodejs.org/api/http.html#http_server_maxheaderscount}
|
|
347
|
+
* @since v0.7.0
|
|
146
348
|
*/
|
|
147
349
|
maxHeadersCount: number | null;
|
|
350
|
+
/**
|
|
351
|
+
* The maximum number of requests socket can handle
|
|
352
|
+
* before closing keep alive connection.
|
|
353
|
+
*
|
|
354
|
+
* A value of `0` will disable the limit.
|
|
355
|
+
*
|
|
356
|
+
* When the limit is reached it will set the `Connection` header value to `close`,
|
|
357
|
+
* but will not actually close the connection, subsequent requests sent
|
|
358
|
+
* after the limit is reached will get `503 Service Unavailable` as a response.
|
|
359
|
+
* @since v16.10.0
|
|
360
|
+
*/
|
|
361
|
+
maxRequestsPerSocket: number | null;
|
|
362
|
+
/**
|
|
363
|
+
* The number of milliseconds of inactivity before a socket is presumed
|
|
364
|
+
* to have timed out.
|
|
365
|
+
*
|
|
366
|
+
* A value of `0` will disable the timeout behavior on incoming connections.
|
|
367
|
+
*
|
|
368
|
+
* The socket timeout logic is set up on connection, so changing this
|
|
369
|
+
* value only affects new connections to the server, not any existing connections.
|
|
370
|
+
* @since v0.9.12
|
|
371
|
+
*/
|
|
148
372
|
timeout: number;
|
|
149
373
|
/**
|
|
150
|
-
* Limit the amount of time the parser will wait to receive the complete HTTP
|
|
151
|
-
*
|
|
152
|
-
*
|
|
374
|
+
* Limit the amount of time the parser will wait to receive the complete HTTP
|
|
375
|
+
* headers.
|
|
376
|
+
*
|
|
377
|
+
* If the timeout expires, the server responds with status 408 without
|
|
378
|
+
* forwarding the request to the request listener and then closes the connection.
|
|
379
|
+
*
|
|
380
|
+
* It must be set to a non-zero value (e.g. 120 seconds) to protect against
|
|
381
|
+
* potential Denial-of-Service attacks in case the server is deployed without a
|
|
382
|
+
* reverse proxy in front.
|
|
383
|
+
* @since v11.3.0, v10.14.0
|
|
153
384
|
*/
|
|
154
385
|
headersTimeout: number;
|
|
386
|
+
/**
|
|
387
|
+
* The number of milliseconds of inactivity a server needs to wait for additional
|
|
388
|
+
* incoming data, after it has finished writing the last response, before a socket
|
|
389
|
+
* will be destroyed. If the server receives new data before the keep-alive
|
|
390
|
+
* timeout has fired, it will reset the regular inactivity timeout, i.e., `server.timeout`.
|
|
391
|
+
*
|
|
392
|
+
* A value of `0` will disable the keep-alive timeout behavior on incoming
|
|
393
|
+
* connections.
|
|
394
|
+
* A value of `0` makes the http server behave similarly to Node.js versions prior
|
|
395
|
+
* to 8.0.0, which did not have a keep-alive timeout.
|
|
396
|
+
*
|
|
397
|
+
* The socket timeout logic is set up on connection, so changing this value only
|
|
398
|
+
* affects new connections to the server, not any existing connections.
|
|
399
|
+
* @since v8.0.0
|
|
400
|
+
*/
|
|
155
401
|
keepAliveTimeout: number;
|
|
156
402
|
/**
|
|
157
|
-
* Sets the timeout value in milliseconds for receiving the entire request from
|
|
158
|
-
*
|
|
159
|
-
*
|
|
403
|
+
* Sets the timeout value in milliseconds for receiving the entire request from
|
|
404
|
+
* the client.
|
|
405
|
+
*
|
|
406
|
+
* If the timeout expires, the server responds with status 408 without
|
|
407
|
+
* forwarding the request to the request listener and then closes the connection.
|
|
408
|
+
*
|
|
409
|
+
* It must be set to a non-zero value (e.g. 120 seconds) to protect against
|
|
410
|
+
* potential Denial-of-Service attacks in case the server is deployed without a
|
|
411
|
+
* reverse proxy in front.
|
|
412
|
+
* @since v14.11.0
|
|
160
413
|
*/
|
|
161
414
|
requestTimeout: number;
|
|
415
|
+
/**
|
|
416
|
+
* Closes all connections connected to this server.
|
|
417
|
+
* @since v18.2.0
|
|
418
|
+
*/
|
|
419
|
+
closeAllConnections(): void;
|
|
420
|
+
/**
|
|
421
|
+
* Closes all connections connected to this server which are not sending a request
|
|
422
|
+
* or waiting for a response.
|
|
423
|
+
* @since v18.2.0
|
|
424
|
+
*/
|
|
425
|
+
closeIdleConnections(): void;
|
|
162
426
|
addListener(event: string, listener: (...args: any[]) => void): this;
|
|
163
427
|
addListener(event: "close", listener: () => void): this;
|
|
164
428
|
addListener(event: "connection", listener: (socket: Socket) => void): this;
|
|
@@ -171,6 +435,7 @@ declare module "http" {
|
|
|
171
435
|
event: "connect",
|
|
172
436
|
listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void,
|
|
173
437
|
): this;
|
|
438
|
+
addListener(event: "dropRequest", listener: (req: InstanceType<Request>, socket: stream.Duplex) => void): this;
|
|
174
439
|
addListener(event: "request", listener: RequestListener<Request, Response>): this;
|
|
175
440
|
addListener(
|
|
176
441
|
event: "upgrade",
|
|
@@ -181,11 +446,24 @@ declare module "http" {
|
|
|
181
446
|
emit(event: "connection", socket: Socket): boolean;
|
|
182
447
|
emit(event: "error", err: Error): boolean;
|
|
183
448
|
emit(event: "listening"): boolean;
|
|
184
|
-
emit(
|
|
185
|
-
|
|
449
|
+
emit(
|
|
450
|
+
event: "checkContinue",
|
|
451
|
+
req: InstanceType<Request>,
|
|
452
|
+
res: InstanceType<Response> & { req: InstanceType<Request> },
|
|
453
|
+
): boolean;
|
|
454
|
+
emit(
|
|
455
|
+
event: "checkExpectation",
|
|
456
|
+
req: InstanceType<Request>,
|
|
457
|
+
res: InstanceType<Response> & { req: InstanceType<Request> },
|
|
458
|
+
): boolean;
|
|
186
459
|
emit(event: "clientError", err: Error, socket: stream.Duplex): boolean;
|
|
187
460
|
emit(event: "connect", req: InstanceType<Request>, socket: stream.Duplex, head: Buffer): boolean;
|
|
188
|
-
emit(event: "
|
|
461
|
+
emit(event: "dropRequest", req: InstanceType<Request>, socket: stream.Duplex): boolean;
|
|
462
|
+
emit(
|
|
463
|
+
event: "request",
|
|
464
|
+
req: InstanceType<Request>,
|
|
465
|
+
res: InstanceType<Response> & { req: InstanceType<Request> },
|
|
466
|
+
): boolean;
|
|
189
467
|
emit(event: "upgrade", req: InstanceType<Request>, socket: stream.Duplex, head: Buffer): boolean;
|
|
190
468
|
on(event: string, listener: (...args: any[]) => void): this;
|
|
191
469
|
on(event: "close", listener: () => void): this;
|
|
@@ -196,6 +474,7 @@ declare module "http" {
|
|
|
196
474
|
on(event: "checkExpectation", listener: RequestListener<Request, Response>): this;
|
|
197
475
|
on(event: "clientError", listener: (err: Error, socket: stream.Duplex) => void): this;
|
|
198
476
|
on(event: "connect", listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void): this;
|
|
477
|
+
on(event: "dropRequest", listener: (req: InstanceType<Request>, socket: stream.Duplex) => void): this;
|
|
199
478
|
on(event: "request", listener: RequestListener<Request, Response>): this;
|
|
200
479
|
on(event: "upgrade", listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void): this;
|
|
201
480
|
once(event: string, listener: (...args: any[]) => void): this;
|
|
@@ -210,6 +489,7 @@ declare module "http" {
|
|
|
210
489
|
event: "connect",
|
|
211
490
|
listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void,
|
|
212
491
|
): this;
|
|
492
|
+
once(event: "dropRequest", listener: (req: InstanceType<Request>, socket: stream.Duplex) => void): this;
|
|
213
493
|
once(event: "request", listener: RequestListener<Request, Response>): this;
|
|
214
494
|
once(
|
|
215
495
|
event: "upgrade",
|
|
@@ -227,6 +507,10 @@ declare module "http" {
|
|
|
227
507
|
event: "connect",
|
|
228
508
|
listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void,
|
|
229
509
|
): this;
|
|
510
|
+
prependListener(
|
|
511
|
+
event: "dropRequest",
|
|
512
|
+
listener: (req: InstanceType<Request>, socket: stream.Duplex) => void,
|
|
513
|
+
): this;
|
|
230
514
|
prependListener(event: "request", listener: RequestListener<Request, Response>): this;
|
|
231
515
|
prependListener(
|
|
232
516
|
event: "upgrade",
|
|
@@ -244,16 +528,23 @@ declare module "http" {
|
|
|
244
528
|
event: "connect",
|
|
245
529
|
listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void,
|
|
246
530
|
): this;
|
|
531
|
+
prependOnceListener(
|
|
532
|
+
event: "dropRequest",
|
|
533
|
+
listener: (req: InstanceType<Request>, socket: stream.Duplex) => void,
|
|
534
|
+
): this;
|
|
247
535
|
prependOnceListener(event: "request", listener: RequestListener<Request, Response>): this;
|
|
248
536
|
prependOnceListener(
|
|
249
537
|
event: "upgrade",
|
|
250
538
|
listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void,
|
|
251
539
|
): this;
|
|
252
540
|
}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
541
|
+
/**
|
|
542
|
+
* This class serves as the parent class of {@link ClientRequest} and {@link ServerResponse}. It is an abstract outgoing message from
|
|
543
|
+
* the perspective of the participants of an HTTP transaction.
|
|
544
|
+
* @since v0.1.17
|
|
545
|
+
*/
|
|
546
|
+
class OutgoingMessage<Request extends IncomingMessage = IncomingMessage> extends stream.Writable {
|
|
547
|
+
readonly req: Request;
|
|
257
548
|
chunkedEncoding: boolean;
|
|
258
549
|
shouldKeepAlive: boolean;
|
|
259
550
|
useChunkedEncodingByDefault: boolean;
|
|
@@ -262,47 +553,303 @@ declare module "http" {
|
|
|
262
553
|
* @deprecated Use `writableEnded` instead.
|
|
263
554
|
*/
|
|
264
555
|
finished: boolean;
|
|
265
|
-
headersSent: boolean;
|
|
266
556
|
/**
|
|
267
|
-
*
|
|
557
|
+
* Read-only. `true` if the headers were sent, otherwise `false`.
|
|
558
|
+
* @since v0.9.3
|
|
559
|
+
*/
|
|
560
|
+
readonly headersSent: boolean;
|
|
561
|
+
/**
|
|
562
|
+
* Alias of `outgoingMessage.socket`.
|
|
563
|
+
* @since v0.3.0
|
|
564
|
+
* @deprecated Since v15.12.0,v14.17.1 - Use `socket` instead.
|
|
565
|
+
*/
|
|
566
|
+
readonly connection: Socket | null;
|
|
567
|
+
/**
|
|
568
|
+
* Reference to the underlying socket. Usually, users will not want to access
|
|
569
|
+
* this property.
|
|
570
|
+
*
|
|
571
|
+
* After calling `outgoingMessage.end()`, this property will be nulled.
|
|
572
|
+
* @since v0.3.0
|
|
268
573
|
*/
|
|
269
|
-
|
|
270
|
-
socket: Socket | null;
|
|
271
|
-
|
|
574
|
+
readonly socket: Socket | null;
|
|
272
575
|
constructor();
|
|
273
|
-
|
|
576
|
+
/**
|
|
577
|
+
* Once a socket is associated with the message and is connected, `socket.setTimeout()` will be called with `msecs` as the first parameter.
|
|
578
|
+
* @since v0.9.12
|
|
579
|
+
* @param callback Optional function to be called when a timeout occurs. Same as binding to the `timeout` event.
|
|
580
|
+
*/
|
|
274
581
|
setTimeout(msecs: number, callback?: () => void): this;
|
|
275
|
-
|
|
582
|
+
/**
|
|
583
|
+
* Sets a single header value. If the header already exists in the to-be-sent
|
|
584
|
+
* headers, its value will be replaced. Use an array of strings to send multiple
|
|
585
|
+
* headers with the same name.
|
|
586
|
+
* @since v0.4.0
|
|
587
|
+
* @param name Header name
|
|
588
|
+
* @param value Header value
|
|
589
|
+
*/
|
|
590
|
+
setHeader(name: string, value: number | string | readonly string[]): this;
|
|
591
|
+
/**
|
|
592
|
+
* Append a single header value to the header object.
|
|
593
|
+
*
|
|
594
|
+
* If the value is an array, this is equivalent to calling this method multiple
|
|
595
|
+
* times.
|
|
596
|
+
*
|
|
597
|
+
* If there were no previous values for the header, this is equivalent to calling `outgoingMessage.setHeader(name, value)`.
|
|
598
|
+
*
|
|
599
|
+
* Depending of the value of `options.uniqueHeaders` when the client request or the
|
|
600
|
+
* server were created, this will end up in the header being sent multiple times or
|
|
601
|
+
* a single time with values joined using `; `.
|
|
602
|
+
* @since v18.3.0, v16.17.0
|
|
603
|
+
* @param name Header name
|
|
604
|
+
* @param value Header value
|
|
605
|
+
*/
|
|
606
|
+
appendHeader(name: string, value: string | readonly string[]): this;
|
|
607
|
+
/**
|
|
608
|
+
* Gets the value of the HTTP header with the given name. If that header is not
|
|
609
|
+
* set, the returned value will be `undefined`.
|
|
610
|
+
* @since v0.4.0
|
|
611
|
+
* @param name Name of header
|
|
612
|
+
*/
|
|
276
613
|
getHeader(name: string): number | string | string[] | undefined;
|
|
614
|
+
/**
|
|
615
|
+
* Returns a shallow copy of the current outgoing headers. Since a shallow
|
|
616
|
+
* copy is used, array values may be mutated without additional calls to
|
|
617
|
+
* various header-related HTTP module methods. The keys of the returned
|
|
618
|
+
* object are the header names and the values are the respective header
|
|
619
|
+
* values. All header names are lowercase.
|
|
620
|
+
*
|
|
621
|
+
* The object returned by the `outgoingMessage.getHeaders()` method does
|
|
622
|
+
* not prototypically inherit from the JavaScript `Object`. This means that
|
|
623
|
+
* typical `Object` methods such as `obj.toString()`, `obj.hasOwnProperty()`,
|
|
624
|
+
* and others are not defined and will not work.
|
|
625
|
+
*
|
|
626
|
+
* ```js
|
|
627
|
+
* outgoingMessage.setHeader('Foo', 'bar');
|
|
628
|
+
* outgoingMessage.setHeader('Set-Cookie', ['foo=bar', 'bar=baz']);
|
|
629
|
+
*
|
|
630
|
+
* const headers = outgoingMessage.getHeaders();
|
|
631
|
+
* // headers === { foo: 'bar', 'set-cookie': ['foo=bar', 'bar=baz'] }
|
|
632
|
+
* ```
|
|
633
|
+
* @since v7.7.0
|
|
634
|
+
*/
|
|
277
635
|
getHeaders(): OutgoingHttpHeaders;
|
|
636
|
+
/**
|
|
637
|
+
* Returns an array containing the unique names of the current outgoing headers.
|
|
638
|
+
* All names are lowercase.
|
|
639
|
+
* @since v7.7.0
|
|
640
|
+
*/
|
|
278
641
|
getHeaderNames(): string[];
|
|
642
|
+
/**
|
|
643
|
+
* Returns `true` if the header identified by `name` is currently set in the
|
|
644
|
+
* outgoing headers. The header name is case-insensitive.
|
|
645
|
+
*
|
|
646
|
+
* ```js
|
|
647
|
+
* const hasContentType = outgoingMessage.hasHeader('content-type');
|
|
648
|
+
* ```
|
|
649
|
+
* @since v7.7.0
|
|
650
|
+
*/
|
|
279
651
|
hasHeader(name: string): boolean;
|
|
652
|
+
/**
|
|
653
|
+
* Removes a header that is queued for implicit sending.
|
|
654
|
+
*
|
|
655
|
+
* ```js
|
|
656
|
+
* outgoingMessage.removeHeader('Content-Encoding');
|
|
657
|
+
* ```
|
|
658
|
+
* @since v0.4.0
|
|
659
|
+
* @param name Header name
|
|
660
|
+
*/
|
|
280
661
|
removeHeader(name: string): void;
|
|
662
|
+
/**
|
|
663
|
+
* Adds HTTP trailers (headers but at the end of the message) to the message.
|
|
664
|
+
*
|
|
665
|
+
* Trailers will **only** be emitted if the message is chunked encoded. If not,
|
|
666
|
+
* the trailers will be silently discarded.
|
|
667
|
+
*
|
|
668
|
+
* HTTP requires the `Trailer` header to be sent to emit trailers,
|
|
669
|
+
* with a list of header field names in its value, e.g.
|
|
670
|
+
*
|
|
671
|
+
* ```js
|
|
672
|
+
* message.writeHead(200, { 'Content-Type': 'text/plain',
|
|
673
|
+
* 'Trailer': 'Content-MD5' });
|
|
674
|
+
* message.write(fileData);
|
|
675
|
+
* message.addTrailers({ 'Content-MD5': '7895bf4b8828b55ceaf47747b4bca667' });
|
|
676
|
+
* message.end();
|
|
677
|
+
* ```
|
|
678
|
+
*
|
|
679
|
+
* Attempting to set a header field name or value that contains invalid characters
|
|
680
|
+
* will result in a `TypeError` being thrown.
|
|
681
|
+
* @since v0.3.0
|
|
682
|
+
*/
|
|
281
683
|
addTrailers(headers: OutgoingHttpHeaders | ReadonlyArray<[string, string]>): void;
|
|
684
|
+
/**
|
|
685
|
+
* Flushes the message headers.
|
|
686
|
+
*
|
|
687
|
+
* For efficiency reason, Node.js normally buffers the message headers
|
|
688
|
+
* until `outgoingMessage.end()` is called or the first chunk of message data
|
|
689
|
+
* is written. It then tries to pack the headers and data into a single TCP
|
|
690
|
+
* packet.
|
|
691
|
+
*
|
|
692
|
+
* It is usually desired (it saves a TCP round-trip), but not when the first
|
|
693
|
+
* data is not sent until possibly much later. `outgoingMessage.flushHeaders()` bypasses the optimization and kickstarts the message.
|
|
694
|
+
* @since v1.6.0
|
|
695
|
+
*/
|
|
282
696
|
flushHeaders(): void;
|
|
283
697
|
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
698
|
+
/**
|
|
699
|
+
* This object is created internally by an HTTP server, not by the user. It is
|
|
700
|
+
* passed as the second parameter to the `'request'` event.
|
|
701
|
+
* @since v0.1.17
|
|
702
|
+
*/
|
|
703
|
+
class ServerResponse<Request extends IncomingMessage = IncomingMessage> extends OutgoingMessage<Request> {
|
|
704
|
+
/**
|
|
705
|
+
* When using implicit headers (not calling `response.writeHead()` explicitly),
|
|
706
|
+
* this property controls the status code that will be sent to the client when
|
|
707
|
+
* the headers get flushed.
|
|
708
|
+
*
|
|
709
|
+
* ```js
|
|
710
|
+
* response.statusCode = 404;
|
|
711
|
+
* ```
|
|
712
|
+
*
|
|
713
|
+
* After response header was sent to the client, this property indicates the
|
|
714
|
+
* status code which was sent out.
|
|
715
|
+
* @since v0.4.0
|
|
716
|
+
*/
|
|
287
717
|
statusCode: number;
|
|
718
|
+
/**
|
|
719
|
+
* When using implicit headers (not calling `response.writeHead()` explicitly),
|
|
720
|
+
* this property controls the status message that will be sent to the client when
|
|
721
|
+
* the headers get flushed. If this is left as `undefined` then the standard
|
|
722
|
+
* message for the status code will be used.
|
|
723
|
+
*
|
|
724
|
+
* ```js
|
|
725
|
+
* response.statusMessage = 'Not found';
|
|
726
|
+
* ```
|
|
727
|
+
*
|
|
728
|
+
* After response header was sent to the client, this property indicates the
|
|
729
|
+
* status message which was sent out.
|
|
730
|
+
* @since v0.11.8
|
|
731
|
+
*/
|
|
288
732
|
statusMessage: string;
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
733
|
+
/**
|
|
734
|
+
* If set to `true`, Node.js will check whether the `Content-Length` header value and the size of the body, in bytes, are equal.
|
|
735
|
+
* Mismatching the `Content-Length` header value will result
|
|
736
|
+
* in an `Error` being thrown, identified by `code:``'ERR_HTTP_CONTENT_LENGTH_MISMATCH'`.
|
|
737
|
+
* @since v18.10.0, v16.18.0
|
|
738
|
+
*/
|
|
739
|
+
strictContentLength: boolean;
|
|
740
|
+
constructor(req: Request);
|
|
292
741
|
assignSocket(socket: Socket): void;
|
|
293
742
|
detachSocket(socket: Socket): void;
|
|
294
|
-
|
|
295
|
-
|
|
743
|
+
/**
|
|
744
|
+
* Sends an HTTP/1.1 100 Continue message to the client, indicating that
|
|
745
|
+
* the request body should be sent. See the `'checkContinue'` event on `Server`.
|
|
746
|
+
* @since v0.3.0
|
|
747
|
+
*/
|
|
296
748
|
writeContinue(callback?: () => void): void;
|
|
749
|
+
/**
|
|
750
|
+
* Sends an HTTP/1.1 103 Early Hints message to the client with a Link header,
|
|
751
|
+
* indicating that the user agent can preload/preconnect the linked resources.
|
|
752
|
+
* The `hints` is an object containing the values of headers to be sent with
|
|
753
|
+
* early hints message. The optional `callback` argument will be called when
|
|
754
|
+
* the response message has been written.
|
|
755
|
+
*
|
|
756
|
+
* **Example**
|
|
757
|
+
*
|
|
758
|
+
* ```js
|
|
759
|
+
* const earlyHintsLink = '</styles.css>; rel=preload; as=style';
|
|
760
|
+
* response.writeEarlyHints({
|
|
761
|
+
* 'link': earlyHintsLink,
|
|
762
|
+
* });
|
|
763
|
+
*
|
|
764
|
+
* const earlyHintsLinks = [
|
|
765
|
+
* '</styles.css>; rel=preload; as=style',
|
|
766
|
+
* '</scripts.js>; rel=preload; as=script',
|
|
767
|
+
* ];
|
|
768
|
+
* response.writeEarlyHints({
|
|
769
|
+
* 'link': earlyHintsLinks,
|
|
770
|
+
* 'x-trace-id': 'id for diagnostics',
|
|
771
|
+
* });
|
|
772
|
+
*
|
|
773
|
+
* const earlyHintsCallback = () => console.log('early hints message sent');
|
|
774
|
+
* response.writeEarlyHints({
|
|
775
|
+
* 'link': earlyHintsLinks,
|
|
776
|
+
* }, earlyHintsCallback);
|
|
777
|
+
* ```
|
|
778
|
+
* @since v18.11.0
|
|
779
|
+
* @param hints An object containing the values of headers
|
|
780
|
+
* @param callback Will be called when the response message has been written
|
|
781
|
+
*/
|
|
782
|
+
writeEarlyHints(hints: Record<string, string | string[]>, callback?: () => void): void;
|
|
783
|
+
/**
|
|
784
|
+
* Sends a response header to the request. The status code is a 3-digit HTTP
|
|
785
|
+
* status code, like `404`. The last argument, `headers`, are the response headers.
|
|
786
|
+
* Optionally one can give a human-readable `statusMessage` as the second
|
|
787
|
+
* argument.
|
|
788
|
+
*
|
|
789
|
+
* `headers` may be an `Array` where the keys and values are in the same list.
|
|
790
|
+
* It is _not_ a list of tuples. So, the even-numbered offsets are key values,
|
|
791
|
+
* and the odd-numbered offsets are the associated values. The array is in the same
|
|
792
|
+
* format as `request.rawHeaders`.
|
|
793
|
+
*
|
|
794
|
+
* Returns a reference to the `ServerResponse`, so that calls can be chained.
|
|
795
|
+
*
|
|
796
|
+
* ```js
|
|
797
|
+
* const body = 'hello world';
|
|
798
|
+
* response
|
|
799
|
+
* .writeHead(200, {
|
|
800
|
+
* 'Content-Length': Buffer.byteLength(body),
|
|
801
|
+
* 'Content-Type': 'text/plain',
|
|
802
|
+
* })
|
|
803
|
+
* .end(body);
|
|
804
|
+
* ```
|
|
805
|
+
*
|
|
806
|
+
* This method must only be called once on a message and it must
|
|
807
|
+
* be called before `response.end()` is called.
|
|
808
|
+
*
|
|
809
|
+
* If `response.write()` or `response.end()` are called before calling
|
|
810
|
+
* this, the implicit/mutable headers will be calculated and call this function.
|
|
811
|
+
*
|
|
812
|
+
* When headers have been set with `response.setHeader()`, they will be merged
|
|
813
|
+
* with any headers passed to `response.writeHead()`, with the headers passed
|
|
814
|
+
* to `response.writeHead()` given precedence.
|
|
815
|
+
*
|
|
816
|
+
* If this method is called and `response.setHeader()` has not been called,
|
|
817
|
+
* it will directly write the supplied header values onto the network channel
|
|
818
|
+
* without caching internally, and the `response.getHeader()` on the header
|
|
819
|
+
* will not yield the expected result. If progressive population of headers is
|
|
820
|
+
* desired with potential future retrieval and modification, use `response.setHeader()` instead.
|
|
821
|
+
*
|
|
822
|
+
* ```js
|
|
823
|
+
* // Returns content-type = text/plain
|
|
824
|
+
* const server = http.createServer((req, res) => {
|
|
825
|
+
* res.setHeader('Content-Type', 'text/html');
|
|
826
|
+
* res.setHeader('X-Foo', 'bar');
|
|
827
|
+
* res.writeHead(200, { 'Content-Type': 'text/plain' });
|
|
828
|
+
* res.end('ok');
|
|
829
|
+
* });
|
|
830
|
+
* ```
|
|
831
|
+
*
|
|
832
|
+
* `Content-Length` is read in bytes, not characters. Use `Buffer.byteLength()` to determine the length of the body in bytes. Node.js
|
|
833
|
+
* will check whether `Content-Length` and the length of the body which has
|
|
834
|
+
* been transmitted are equal or not.
|
|
835
|
+
*
|
|
836
|
+
* Attempting to set a header field name or value that contains invalid characters
|
|
837
|
+
* will result in a \[`Error`\]\[\] being thrown.
|
|
838
|
+
* @since v0.1.30
|
|
839
|
+
*/
|
|
297
840
|
writeHead(
|
|
298
841
|
statusCode: number,
|
|
299
842
|
statusMessage?: string,
|
|
300
843
|
headers?: OutgoingHttpHeaders | OutgoingHttpHeader[],
|
|
301
844
|
): this;
|
|
302
845
|
writeHead(statusCode: number, headers?: OutgoingHttpHeaders | OutgoingHttpHeader[]): this;
|
|
846
|
+
/**
|
|
847
|
+
* Sends a HTTP/1.1 102 Processing message to the client, indicating that
|
|
848
|
+
* the request body should be sent.
|
|
849
|
+
* @since v10.0.0
|
|
850
|
+
*/
|
|
303
851
|
writeProcessing(): void;
|
|
304
852
|
}
|
|
305
|
-
|
|
306
853
|
interface InformationEvent {
|
|
307
854
|
statusCode: number;
|
|
308
855
|
statusMessage: string;
|
|
@@ -312,26 +859,163 @@ declare module "http" {
|
|
|
312
859
|
headers: IncomingHttpHeaders;
|
|
313
860
|
rawHeaders: string[];
|
|
314
861
|
}
|
|
315
|
-
|
|
316
|
-
|
|
862
|
+
/**
|
|
863
|
+
* This object is created internally and returned from {@link request}. It
|
|
864
|
+
* represents an _in-progress_ request whose header has already been queued. The
|
|
865
|
+
* header is still mutable using the `setHeader(name, value)`, `getHeader(name)`, `removeHeader(name)` API. The actual header will
|
|
866
|
+
* be sent along with the first data chunk or when calling `request.end()`.
|
|
867
|
+
*
|
|
868
|
+
* To get the response, add a listener for `'response'` to the request object. `'response'` will be emitted from the request object when the response
|
|
869
|
+
* headers have been received. The `'response'` event is executed with one
|
|
870
|
+
* argument which is an instance of {@link IncomingMessage}.
|
|
871
|
+
*
|
|
872
|
+
* During the `'response'` event, one can add listeners to the
|
|
873
|
+
* response object; particularly to listen for the `'data'` event.
|
|
874
|
+
*
|
|
875
|
+
* If no `'response'` handler is added, then the response will be
|
|
876
|
+
* entirely discarded. However, if a `'response'` event handler is added,
|
|
877
|
+
* then the data from the response object **must** be consumed, either by
|
|
878
|
+
* calling `response.read()` whenever there is a `'readable'` event, or
|
|
879
|
+
* by adding a `'data'` handler, or by calling the `.resume()` method.
|
|
880
|
+
* Until the data is consumed, the `'end'` event will not fire. Also, until
|
|
881
|
+
* the data is read it will consume memory that can eventually lead to a
|
|
882
|
+
* 'process out of memory' error.
|
|
883
|
+
*
|
|
884
|
+
* For backward compatibility, `res` will only emit `'error'` if there is an `'error'` listener registered.
|
|
885
|
+
*
|
|
886
|
+
* Set `Content-Length` header to limit the response body size.
|
|
887
|
+
* If `response.strictContentLength` is set to `true`, mismatching the `Content-Length` header value will result in an `Error` being thrown,
|
|
888
|
+
* identified by `code:``'ERR_HTTP_CONTENT_LENGTH_MISMATCH'`.
|
|
889
|
+
*
|
|
890
|
+
* `Content-Length` value should be in bytes, not characters. Use `Buffer.byteLength()` to determine the length of the body in bytes.
|
|
891
|
+
* @since v0.1.17
|
|
892
|
+
*/
|
|
317
893
|
class ClientRequest extends OutgoingMessage {
|
|
894
|
+
/**
|
|
895
|
+
* The `request.aborted` property will be `true` if the request has
|
|
896
|
+
* been aborted.
|
|
897
|
+
* @since v0.11.14
|
|
898
|
+
* @deprecated Since v17.0.0, v16.12.0 - Check `destroyed` instead.
|
|
899
|
+
*/
|
|
318
900
|
aborted: boolean;
|
|
901
|
+
/**
|
|
902
|
+
* The request host.
|
|
903
|
+
* @since v14.5.0, v12.19.0
|
|
904
|
+
*/
|
|
319
905
|
host: string;
|
|
906
|
+
/**
|
|
907
|
+
* The request protocol.
|
|
908
|
+
* @since v14.5.0, v12.19.0
|
|
909
|
+
*/
|
|
320
910
|
protocol: string;
|
|
911
|
+
/**
|
|
912
|
+
* When sending request through a keep-alive enabled agent, the underlying socket
|
|
913
|
+
* might be reused. But if server closes connection at unfortunate time, client
|
|
914
|
+
* may run into a 'ECONNRESET' error.
|
|
915
|
+
*
|
|
916
|
+
* ```js
|
|
917
|
+
* import http from 'node:http';
|
|
918
|
+
*
|
|
919
|
+
* // Server has a 5 seconds keep-alive timeout by default
|
|
920
|
+
* http
|
|
921
|
+
* .createServer((req, res) => {
|
|
922
|
+
* res.write('hello\n');
|
|
923
|
+
* res.end();
|
|
924
|
+
* })
|
|
925
|
+
* .listen(3000);
|
|
926
|
+
*
|
|
927
|
+
* setInterval(() => {
|
|
928
|
+
* // Adapting a keep-alive agent
|
|
929
|
+
* http.get('http://localhost:3000', { agent }, (res) => {
|
|
930
|
+
* res.on('data', (data) => {
|
|
931
|
+
* // Do nothing
|
|
932
|
+
* });
|
|
933
|
+
* });
|
|
934
|
+
* }, 5000); // Sending request on 5s interval so it's easy to hit idle timeout
|
|
935
|
+
* ```
|
|
936
|
+
*
|
|
937
|
+
* By marking a request whether it reused socket or not, we can do
|
|
938
|
+
* automatic error retry base on it.
|
|
939
|
+
*
|
|
940
|
+
* ```js
|
|
941
|
+
* import http from 'node:http';
|
|
942
|
+
* const agent = new http.Agent({ keepAlive: true });
|
|
943
|
+
*
|
|
944
|
+
* function retriableRequest() {
|
|
945
|
+
* const req = http
|
|
946
|
+
* .get('http://localhost:3000', { agent }, (res) => {
|
|
947
|
+
* // ...
|
|
948
|
+
* })
|
|
949
|
+
* .on('error', (err) => {
|
|
950
|
+
* // Check if retry is needed
|
|
951
|
+
* if (req.reusedSocket && err.code === 'ECONNRESET') {
|
|
952
|
+
* retriableRequest();
|
|
953
|
+
* }
|
|
954
|
+
* });
|
|
955
|
+
* }
|
|
956
|
+
*
|
|
957
|
+
* retriableRequest();
|
|
958
|
+
* ```
|
|
959
|
+
* @since v13.0.0, v12.16.0
|
|
960
|
+
*/
|
|
321
961
|
reusedSocket: boolean;
|
|
962
|
+
/**
|
|
963
|
+
* Limits maximum response headers count. If set to 0, no limit will be applied.
|
|
964
|
+
*/
|
|
322
965
|
maxHeadersCount: number;
|
|
323
|
-
|
|
324
966
|
constructor(url: string | URL | ClientRequestArgs, cb?: (res: IncomingMessage) => void);
|
|
325
|
-
|
|
967
|
+
/**
|
|
968
|
+
* The request method.
|
|
969
|
+
* @since v0.1.97
|
|
970
|
+
*/
|
|
326
971
|
method: string;
|
|
972
|
+
/**
|
|
973
|
+
* The request path.
|
|
974
|
+
* @since v0.4.0
|
|
975
|
+
*/
|
|
327
976
|
path: string;
|
|
328
|
-
/**
|
|
977
|
+
/**
|
|
978
|
+
* Marks the request as aborting. Calling this will cause remaining data
|
|
979
|
+
* in the response to be dropped and the socket to be destroyed.
|
|
980
|
+
* @since v0.3.8
|
|
981
|
+
* @deprecated Since v14.1.0,v13.14.0 - Use `destroy` instead.
|
|
982
|
+
*/
|
|
329
983
|
abort(): void;
|
|
330
984
|
onSocket(socket: Socket): void;
|
|
985
|
+
/**
|
|
986
|
+
* Once a socket is assigned to this request and is connected `socket.setTimeout()` will be called.
|
|
987
|
+
* @since v0.5.9
|
|
988
|
+
* @param timeout Milliseconds before a request times out.
|
|
989
|
+
* @param callback Optional function to be called when a timeout occurs. Same as binding to the `'timeout'` event.
|
|
990
|
+
*/
|
|
331
991
|
setTimeout(timeout: number, callback?: () => void): this;
|
|
992
|
+
/**
|
|
993
|
+
* Once a socket is assigned to this request and is connected `socket.setNoDelay()` will be called.
|
|
994
|
+
* @since v0.5.9
|
|
995
|
+
*/
|
|
332
996
|
setNoDelay(noDelay?: boolean): void;
|
|
997
|
+
/**
|
|
998
|
+
* Once a socket is assigned to this request and is connected `socket.setKeepAlive()` will be called.
|
|
999
|
+
* @since v0.5.9
|
|
1000
|
+
*/
|
|
333
1001
|
setSocketKeepAlive(enable?: boolean, initialDelay?: number): void;
|
|
334
|
-
|
|
1002
|
+
/**
|
|
1003
|
+
* Returns an array containing the unique names of the current outgoing raw
|
|
1004
|
+
* headers. Header names are returned with their exact casing being set.
|
|
1005
|
+
*
|
|
1006
|
+
* ```js
|
|
1007
|
+
* request.setHeader('Foo', 'bar');
|
|
1008
|
+
* request.setHeader('Set-Cookie', ['foo=bar', 'bar=baz']);
|
|
1009
|
+
*
|
|
1010
|
+
* const headerNames = request.getRawHeaderNames();
|
|
1011
|
+
* // headerNames === ['Foo', 'Set-Cookie']
|
|
1012
|
+
* ```
|
|
1013
|
+
* @since v15.13.0, v14.17.0
|
|
1014
|
+
*/
|
|
1015
|
+
getRawHeaderNames(): string[];
|
|
1016
|
+
/**
|
|
1017
|
+
* @deprecated
|
|
1018
|
+
*/
|
|
335
1019
|
addListener(event: "abort", listener: () => void): this;
|
|
336
1020
|
addListener(
|
|
337
1021
|
event: "connect",
|
|
@@ -353,7 +1037,9 @@ declare module "http" {
|
|
|
353
1037
|
addListener(event: "pipe", listener: (src: stream.Readable) => void): this;
|
|
354
1038
|
addListener(event: "unpipe", listener: (src: stream.Readable) => void): this;
|
|
355
1039
|
addListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
356
|
-
|
|
1040
|
+
/**
|
|
1041
|
+
* @deprecated
|
|
1042
|
+
*/
|
|
357
1043
|
on(event: "abort", listener: () => void): this;
|
|
358
1044
|
on(event: "connect", listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this;
|
|
359
1045
|
on(event: "continue", listener: () => void): this;
|
|
@@ -369,7 +1055,9 @@ declare module "http" {
|
|
|
369
1055
|
on(event: "pipe", listener: (src: stream.Readable) => void): this;
|
|
370
1056
|
on(event: "unpipe", listener: (src: stream.Readable) => void): this;
|
|
371
1057
|
on(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
372
|
-
|
|
1058
|
+
/**
|
|
1059
|
+
* @deprecated
|
|
1060
|
+
*/
|
|
373
1061
|
once(event: "abort", listener: () => void): this;
|
|
374
1062
|
once(event: "connect", listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this;
|
|
375
1063
|
once(event: "continue", listener: () => void): this;
|
|
@@ -385,7 +1073,9 @@ declare module "http" {
|
|
|
385
1073
|
once(event: "pipe", listener: (src: stream.Readable) => void): this;
|
|
386
1074
|
once(event: "unpipe", listener: (src: stream.Readable) => void): this;
|
|
387
1075
|
once(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
388
|
-
|
|
1076
|
+
/**
|
|
1077
|
+
* @deprecated
|
|
1078
|
+
*/
|
|
389
1079
|
prependListener(event: "abort", listener: () => void): this;
|
|
390
1080
|
prependListener(
|
|
391
1081
|
event: "connect",
|
|
@@ -407,7 +1097,9 @@ declare module "http" {
|
|
|
407
1097
|
prependListener(event: "pipe", listener: (src: stream.Readable) => void): this;
|
|
408
1098
|
prependListener(event: "unpipe", listener: (src: stream.Readable) => void): this;
|
|
409
1099
|
prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
410
|
-
|
|
1100
|
+
/**
|
|
1101
|
+
* @deprecated
|
|
1102
|
+
*/
|
|
411
1103
|
prependOnceListener(event: "abort", listener: () => void): this;
|
|
412
1104
|
prependOnceListener(
|
|
413
1105
|
event: "connect",
|
|
@@ -430,45 +1122,241 @@ declare module "http" {
|
|
|
430
1122
|
prependOnceListener(event: "unpipe", listener: (src: stream.Readable) => void): this;
|
|
431
1123
|
prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
432
1124
|
}
|
|
433
|
-
|
|
1125
|
+
/**
|
|
1126
|
+
* An `IncomingMessage` object is created by {@link Server} or {@link ClientRequest} and passed as the first argument to the `'request'` and `'response'` event respectively. It may be used to
|
|
1127
|
+
* access response
|
|
1128
|
+
* status, headers, and data.
|
|
1129
|
+
*
|
|
1130
|
+
* Different from its `socket` value which is a subclass of `stream.Duplex`, the `IncomingMessage` itself extends `stream.Readable` and is created separately to
|
|
1131
|
+
* parse and emit the incoming HTTP headers and payload, as the underlying socket
|
|
1132
|
+
* may be reused multiple times in case of keep-alive.
|
|
1133
|
+
* @since v0.1.17
|
|
1134
|
+
*/
|
|
434
1135
|
class IncomingMessage extends stream.Readable {
|
|
435
1136
|
constructor(socket: Socket);
|
|
436
|
-
|
|
1137
|
+
/**
|
|
1138
|
+
* The `message.aborted` property will be `true` if the request has
|
|
1139
|
+
* been aborted.
|
|
1140
|
+
* @since v10.1.0
|
|
1141
|
+
* @deprecated Since v17.0.0,v16.12.0 - Check `message.destroyed` from <a href="stream.html#class-streamreadable" class="type">stream.Readable</a>.
|
|
1142
|
+
*/
|
|
437
1143
|
aborted: boolean;
|
|
1144
|
+
/**
|
|
1145
|
+
* In case of server request, the HTTP version sent by the client. In the case of
|
|
1146
|
+
* client response, the HTTP version of the connected-to server.
|
|
1147
|
+
* Probably either `'1.1'` or `'1.0'`.
|
|
1148
|
+
*
|
|
1149
|
+
* Also `message.httpVersionMajor` is the first integer and `message.httpVersionMinor` is the second.
|
|
1150
|
+
* @since v0.1.1
|
|
1151
|
+
*/
|
|
438
1152
|
httpVersion: string;
|
|
439
1153
|
httpVersionMajor: number;
|
|
440
1154
|
httpVersionMinor: number;
|
|
1155
|
+
/**
|
|
1156
|
+
* The `message.complete` property will be `true` if a complete HTTP message has
|
|
1157
|
+
* been received and successfully parsed.
|
|
1158
|
+
*
|
|
1159
|
+
* This property is particularly useful as a means of determining if a client or
|
|
1160
|
+
* server fully transmitted a message before a connection was terminated:
|
|
1161
|
+
*
|
|
1162
|
+
* ```js
|
|
1163
|
+
* const req = http.request({
|
|
1164
|
+
* host: '127.0.0.1',
|
|
1165
|
+
* port: 8080,
|
|
1166
|
+
* method: 'POST',
|
|
1167
|
+
* }, (res) => {
|
|
1168
|
+
* res.resume();
|
|
1169
|
+
* res.on('end', () => {
|
|
1170
|
+
* if (!res.complete)
|
|
1171
|
+
* console.error(
|
|
1172
|
+
* 'The connection was terminated while the message was still being sent');
|
|
1173
|
+
* });
|
|
1174
|
+
* });
|
|
1175
|
+
* ```
|
|
1176
|
+
* @since v0.3.0
|
|
1177
|
+
*/
|
|
441
1178
|
complete: boolean;
|
|
442
1179
|
/**
|
|
443
|
-
*
|
|
1180
|
+
* Alias for `message.socket`.
|
|
1181
|
+
* @since v0.1.90
|
|
1182
|
+
* @deprecated Since v16.0.0 - Use `socket`.
|
|
444
1183
|
*/
|
|
445
1184
|
connection: Socket;
|
|
1185
|
+
/**
|
|
1186
|
+
* The `net.Socket` object associated with the connection.
|
|
1187
|
+
*
|
|
1188
|
+
* With HTTPS support, use `request.socket.getPeerCertificate()` to obtain the
|
|
1189
|
+
* client's authentication details.
|
|
1190
|
+
*
|
|
1191
|
+
* This property is guaranteed to be an instance of the `net.Socket` class,
|
|
1192
|
+
* a subclass of `stream.Duplex`, unless the user specified a socket
|
|
1193
|
+
* type other than `net.Socket` or internally nulled.
|
|
1194
|
+
* @since v0.3.0
|
|
1195
|
+
*/
|
|
446
1196
|
socket: Socket;
|
|
1197
|
+
/**
|
|
1198
|
+
* The request/response headers object.
|
|
1199
|
+
*
|
|
1200
|
+
* Key-value pairs of header names and values. Header names are lower-cased.
|
|
1201
|
+
*
|
|
1202
|
+
* ```js
|
|
1203
|
+
* // Prints something like:
|
|
1204
|
+
* //
|
|
1205
|
+
* // { 'user-agent': 'curl/7.22.0',
|
|
1206
|
+
* // host: '127.0.0.1:8000',
|
|
1207
|
+
* // accept: '*' }
|
|
1208
|
+
* console.log(request.headers);
|
|
1209
|
+
* ```
|
|
1210
|
+
*
|
|
1211
|
+
* Duplicates in raw headers are handled in the following ways, depending on the
|
|
1212
|
+
* header name:
|
|
1213
|
+
*
|
|
1214
|
+
* * Duplicates of `age`, `authorization`, `content-length`, `content-type`, `etag`, `expires`, `from`, `host`, `if-modified-since`, `if-unmodified-since`, `last-modified`, `location`,
|
|
1215
|
+
* `max-forwards`, `proxy-authorization`, `referer`, `retry-after`, `server`, or `user-agent` are discarded.
|
|
1216
|
+
* To allow duplicate values of the headers listed above to be joined,
|
|
1217
|
+
* use the option `joinDuplicateHeaders` in {@link request} and {@link createServer}. See RFC 9110 Section 5.3 for more
|
|
1218
|
+
* information.
|
|
1219
|
+
* * `set-cookie` is always an array. Duplicates are added to the array.
|
|
1220
|
+
* * For duplicate `cookie` headers, the values are joined together with `; `.
|
|
1221
|
+
* * For all other headers, the values are joined together with `, `.
|
|
1222
|
+
* @since v0.1.5
|
|
1223
|
+
*/
|
|
447
1224
|
headers: IncomingHttpHeaders;
|
|
1225
|
+
/**
|
|
1226
|
+
* Similar to `message.headers`, but there is no join logic and the values are
|
|
1227
|
+
* always arrays of strings, even for headers received just once.
|
|
1228
|
+
*
|
|
1229
|
+
* ```js
|
|
1230
|
+
* // Prints something like:
|
|
1231
|
+
* //
|
|
1232
|
+
* // { 'user-agent': ['curl/7.22.0'],
|
|
1233
|
+
* // host: ['127.0.0.1:8000'],
|
|
1234
|
+
* // accept: ['*'] }
|
|
1235
|
+
* console.log(request.headersDistinct);
|
|
1236
|
+
* ```
|
|
1237
|
+
* @since v18.3.0, v16.17.0
|
|
1238
|
+
*/
|
|
1239
|
+
headersDistinct: NodeJS.Dict<string[]>;
|
|
1240
|
+
/**
|
|
1241
|
+
* The raw request/response headers list exactly as they were received.
|
|
1242
|
+
*
|
|
1243
|
+
* The keys and values are in the same list. It is _not_ a
|
|
1244
|
+
* list of tuples. So, the even-numbered offsets are key values, and the
|
|
1245
|
+
* odd-numbered offsets are the associated values.
|
|
1246
|
+
*
|
|
1247
|
+
* Header names are not lowercased, and duplicates are not merged.
|
|
1248
|
+
*
|
|
1249
|
+
* ```js
|
|
1250
|
+
* // Prints something like:
|
|
1251
|
+
* //
|
|
1252
|
+
* // [ 'user-agent',
|
|
1253
|
+
* // 'this is invalid because there can be only one',
|
|
1254
|
+
* // 'User-Agent',
|
|
1255
|
+
* // 'curl/7.22.0',
|
|
1256
|
+
* // 'Host',
|
|
1257
|
+
* // '127.0.0.1:8000',
|
|
1258
|
+
* // 'ACCEPT',
|
|
1259
|
+
* // '*' ]
|
|
1260
|
+
* console.log(request.rawHeaders);
|
|
1261
|
+
* ```
|
|
1262
|
+
* @since v0.11.6
|
|
1263
|
+
*/
|
|
448
1264
|
rawHeaders: string[];
|
|
1265
|
+
/**
|
|
1266
|
+
* The request/response trailers object. Only populated at the `'end'` event.
|
|
1267
|
+
* @since v0.3.0
|
|
1268
|
+
*/
|
|
449
1269
|
trailers: NodeJS.Dict<string>;
|
|
1270
|
+
/**
|
|
1271
|
+
* Similar to `message.trailers`, but there is no join logic and the values are
|
|
1272
|
+
* always arrays of strings, even for headers received just once.
|
|
1273
|
+
* Only populated at the `'end'` event.
|
|
1274
|
+
* @since v18.3.0, v16.17.0
|
|
1275
|
+
*/
|
|
1276
|
+
trailersDistinct: NodeJS.Dict<string[]>;
|
|
1277
|
+
/**
|
|
1278
|
+
* The raw request/response trailer keys and values exactly as they were
|
|
1279
|
+
* received. Only populated at the `'end'` event.
|
|
1280
|
+
* @since v0.11.6
|
|
1281
|
+
*/
|
|
450
1282
|
rawTrailers: string[];
|
|
1283
|
+
/**
|
|
1284
|
+
* Calls `message.socket.setTimeout(msecs, callback)`.
|
|
1285
|
+
* @since v0.5.9
|
|
1286
|
+
*/
|
|
451
1287
|
setTimeout(msecs: number, callback?: () => void): this;
|
|
452
1288
|
/**
|
|
453
|
-
* Only valid for request obtained from
|
|
1289
|
+
* **Only valid for request obtained from {@link Server}.**
|
|
1290
|
+
*
|
|
1291
|
+
* The request method as a string. Read only. Examples: `'GET'`, `'DELETE'`.
|
|
1292
|
+
* @since v0.1.1
|
|
454
1293
|
*/
|
|
455
1294
|
method?: string | undefined;
|
|
456
1295
|
/**
|
|
457
|
-
* Only valid for request obtained from
|
|
1296
|
+
* **Only valid for request obtained from {@link Server}.**
|
|
1297
|
+
*
|
|
1298
|
+
* Request URL string. This contains only the URL that is present in the actual
|
|
1299
|
+
* HTTP request. Take the following request:
|
|
1300
|
+
*
|
|
1301
|
+
* ```http
|
|
1302
|
+
* GET /status?name=ryan HTTP/1.1
|
|
1303
|
+
* Accept: text/plain
|
|
1304
|
+
* ```
|
|
1305
|
+
*
|
|
1306
|
+
* To parse the URL into its parts:
|
|
1307
|
+
*
|
|
1308
|
+
* ```js
|
|
1309
|
+
* new URL(`http://${process.env.HOST ?? 'localhost'}${request.url}`);
|
|
1310
|
+
* ```
|
|
1311
|
+
*
|
|
1312
|
+
* When `request.url` is `'/status?name=ryan'` and `process.env.HOST` is undefined:
|
|
1313
|
+
*
|
|
1314
|
+
* ```console
|
|
1315
|
+
* $ node
|
|
1316
|
+
* > new URL(`http://${process.env.HOST ?? 'localhost'}${request.url}`);
|
|
1317
|
+
* URL {
|
|
1318
|
+
* href: 'http://localhost/status?name=ryan',
|
|
1319
|
+
* origin: 'http://localhost',
|
|
1320
|
+
* protocol: 'http:',
|
|
1321
|
+
* username: '',
|
|
1322
|
+
* password: '',
|
|
1323
|
+
* host: 'localhost',
|
|
1324
|
+
* hostname: 'localhost',
|
|
1325
|
+
* port: '',
|
|
1326
|
+
* pathname: '/status',
|
|
1327
|
+
* search: '?name=ryan',
|
|
1328
|
+
* searchParams: URLSearchParams { 'name' => 'ryan' },
|
|
1329
|
+
* hash: ''
|
|
1330
|
+
* }
|
|
1331
|
+
* ```
|
|
1332
|
+
*
|
|
1333
|
+
* Ensure that you set `process.env.HOST` to the server's host name, or consider replacing this part entirely. If using `req.headers.host`, ensure proper
|
|
1334
|
+
* validation is used, as clients may specify a custom `Host` header.
|
|
1335
|
+
* @since v0.1.90
|
|
458
1336
|
*/
|
|
459
1337
|
url?: string | undefined;
|
|
460
1338
|
/**
|
|
461
|
-
* Only valid for response obtained from
|
|
1339
|
+
* **Only valid for response obtained from {@link ClientRequest}.**
|
|
1340
|
+
*
|
|
1341
|
+
* The 3-digit HTTP response status code. E.G. `404`.
|
|
1342
|
+
* @since v0.1.1
|
|
462
1343
|
*/
|
|
463
1344
|
statusCode?: number | undefined;
|
|
464
1345
|
/**
|
|
465
|
-
* Only valid for response obtained from
|
|
1346
|
+
* **Only valid for response obtained from {@link ClientRequest}.**
|
|
1347
|
+
*
|
|
1348
|
+
* The HTTP response status message (reason phrase). E.G. `OK` or `Internal Server Error`.
|
|
1349
|
+
* @since v0.11.10
|
|
466
1350
|
*/
|
|
467
1351
|
statusMessage?: string | undefined;
|
|
1352
|
+
/**
|
|
1353
|
+
* Calls `destroy()` on the socket that received the `IncomingMessage`. If `error` is provided, an `'error'` event is emitted on the socket and `error` is passed
|
|
1354
|
+
* as an argument to any listeners on the event.
|
|
1355
|
+
* @since v0.3.0
|
|
1356
|
+
*/
|
|
468
1357
|
destroy(error?: Error): this;
|
|
469
1358
|
}
|
|
470
|
-
|
|
471
|
-
interface AgentOptions {
|
|
1359
|
+
interface AgentOptions extends Partial<TcpSocketConnectOpts> {
|
|
472
1360
|
/**
|
|
473
1361
|
* Keep sockets around in a pool to be used by other requests in the future. Default = false
|
|
474
1362
|
*/
|
|
@@ -495,37 +1383,174 @@ declare module "http" {
|
|
|
495
1383
|
*/
|
|
496
1384
|
timeout?: number | undefined;
|
|
497
1385
|
/**
|
|
498
|
-
* Scheduling strategy to apply when picking the next free socket to use.
|
|
1386
|
+
* Scheduling strategy to apply when picking the next free socket to use.
|
|
1387
|
+
* @default `lifo`
|
|
499
1388
|
*/
|
|
500
1389
|
scheduling?: "fifo" | "lifo" | undefined;
|
|
501
1390
|
}
|
|
502
|
-
|
|
1391
|
+
/**
|
|
1392
|
+
* An `Agent` is responsible for managing connection persistence
|
|
1393
|
+
* and reuse for HTTP clients. It maintains a queue of pending requests
|
|
1394
|
+
* for a given host and port, reusing a single socket connection for each
|
|
1395
|
+
* until the queue is empty, at which time the socket is either destroyed
|
|
1396
|
+
* or put into a pool where it is kept to be used again for requests to the
|
|
1397
|
+
* same host and port. Whether it is destroyed or pooled depends on the `keepAlive` `option`.
|
|
1398
|
+
*
|
|
1399
|
+
* Pooled connections have TCP Keep-Alive enabled for them, but servers may
|
|
1400
|
+
* still close idle connections, in which case they will be removed from the
|
|
1401
|
+
* pool and a new connection will be made when a new HTTP request is made for
|
|
1402
|
+
* that host and port. Servers may also refuse to allow multiple requests
|
|
1403
|
+
* over the same connection, in which case the connection will have to be
|
|
1404
|
+
* remade for every request and cannot be pooled. The `Agent` will still make
|
|
1405
|
+
* the requests to that server, but each one will occur over a new connection.
|
|
1406
|
+
*
|
|
1407
|
+
* When a connection is closed by the client or the server, it is removed
|
|
1408
|
+
* from the pool. Any unused sockets in the pool will be unrefed so as not
|
|
1409
|
+
* to keep the Node.js process running when there are no outstanding requests.
|
|
1410
|
+
* (see `socket.unref()`).
|
|
1411
|
+
*
|
|
1412
|
+
* It is good practice, to `destroy()` an `Agent` instance when it is no
|
|
1413
|
+
* longer in use, because unused sockets consume OS resources.
|
|
1414
|
+
*
|
|
1415
|
+
* Sockets are removed from an agent when the socket emits either
|
|
1416
|
+
* a `'close'` event or an `'agentRemove'` event. When intending to keep one
|
|
1417
|
+
* HTTP request open for a long time without keeping it in the agent, something
|
|
1418
|
+
* like the following may be done:
|
|
1419
|
+
*
|
|
1420
|
+
* ```js
|
|
1421
|
+
* http.get(options, (res) => {
|
|
1422
|
+
* // Do stuff
|
|
1423
|
+
* }).on('socket', (socket) => {
|
|
1424
|
+
* socket.emit('agentRemove');
|
|
1425
|
+
* });
|
|
1426
|
+
* ```
|
|
1427
|
+
*
|
|
1428
|
+
* An agent may also be used for an individual request. By providing `{agent: false}` as an option to the `http.get()` or `http.request()` functions, a one-time use `Agent` with default options
|
|
1429
|
+
* will be used
|
|
1430
|
+
* for the client connection.
|
|
1431
|
+
*
|
|
1432
|
+
* `agent:false`:
|
|
1433
|
+
*
|
|
1434
|
+
* ```js
|
|
1435
|
+
* http.get({
|
|
1436
|
+
* hostname: 'localhost',
|
|
1437
|
+
* port: 80,
|
|
1438
|
+
* path: '/',
|
|
1439
|
+
* agent: false, // Create a new agent just for this one request
|
|
1440
|
+
* }, (res) => {
|
|
1441
|
+
* // Do stuff with response
|
|
1442
|
+
* });
|
|
1443
|
+
* ```
|
|
1444
|
+
*
|
|
1445
|
+
* `options` in [`socket.connect()`](https://nodejs.org/docs/latest-v20.x/api/net.html#socketconnectoptions-connectlistener) are also supported.
|
|
1446
|
+
*
|
|
1447
|
+
* To configure any of them, a custom {@link Agent} instance must be created.
|
|
1448
|
+
*
|
|
1449
|
+
* ```js
|
|
1450
|
+
* const http = require('node:http');
|
|
1451
|
+
* const keepAliveAgent = new http.Agent({ keepAlive: true });
|
|
1452
|
+
* options.agent = keepAliveAgent;
|
|
1453
|
+
* http.request(options, onResponseCallback)
|
|
1454
|
+
* ```
|
|
1455
|
+
* @since v0.3.4
|
|
1456
|
+
*/
|
|
503
1457
|
class Agent extends EventEmitter {
|
|
1458
|
+
/**
|
|
1459
|
+
* By default set to 256. For agents with `keepAlive` enabled, this
|
|
1460
|
+
* sets the maximum number of sockets that will be left open in the free
|
|
1461
|
+
* state.
|
|
1462
|
+
* @since v0.11.7
|
|
1463
|
+
*/
|
|
504
1464
|
maxFreeSockets: number;
|
|
1465
|
+
/**
|
|
1466
|
+
* By default set to `Infinity`. Determines how many concurrent sockets the agent
|
|
1467
|
+
* can have open per origin. Origin is the returned value of `agent.getName()`.
|
|
1468
|
+
* @since v0.3.6
|
|
1469
|
+
*/
|
|
505
1470
|
maxSockets: number;
|
|
1471
|
+
/**
|
|
1472
|
+
* By default set to `Infinity`. Determines how many concurrent sockets the agent
|
|
1473
|
+
* can have open. Unlike `maxSockets`, this parameter applies across all origins.
|
|
1474
|
+
* @since v14.5.0, v12.19.0
|
|
1475
|
+
*/
|
|
506
1476
|
maxTotalSockets: number;
|
|
1477
|
+
/**
|
|
1478
|
+
* An object which contains arrays of sockets currently awaiting use by
|
|
1479
|
+
* the agent when `keepAlive` is enabled. Do not modify.
|
|
1480
|
+
*
|
|
1481
|
+
* Sockets in the `freeSockets` list will be automatically destroyed and
|
|
1482
|
+
* removed from the array on `'timeout'`.
|
|
1483
|
+
* @since v0.11.4
|
|
1484
|
+
*/
|
|
507
1485
|
readonly freeSockets: NodeJS.ReadOnlyDict<Socket[]>;
|
|
1486
|
+
/**
|
|
1487
|
+
* An object which contains arrays of sockets currently in use by the
|
|
1488
|
+
* agent. Do not modify.
|
|
1489
|
+
* @since v0.3.6
|
|
1490
|
+
*/
|
|
508
1491
|
readonly sockets: NodeJS.ReadOnlyDict<Socket[]>;
|
|
1492
|
+
/**
|
|
1493
|
+
* An object which contains queues of requests that have not yet been assigned to
|
|
1494
|
+
* sockets. Do not modify.
|
|
1495
|
+
* @since v0.5.9
|
|
1496
|
+
*/
|
|
509
1497
|
readonly requests: NodeJS.ReadOnlyDict<IncomingMessage[]>;
|
|
510
|
-
|
|
511
1498
|
constructor(opts?: AgentOptions);
|
|
512
|
-
|
|
513
1499
|
/**
|
|
514
1500
|
* Destroy any sockets that are currently in use by the agent.
|
|
515
|
-
*
|
|
516
|
-
*
|
|
517
|
-
*
|
|
1501
|
+
*
|
|
1502
|
+
* It is usually not necessary to do this. However, if using an
|
|
1503
|
+
* agent with `keepAlive` enabled, then it is best to explicitly shut down
|
|
1504
|
+
* the agent when it is no longer needed. Otherwise,
|
|
1505
|
+
* sockets might stay open for quite a long time before the server
|
|
1506
|
+
* terminates them.
|
|
1507
|
+
* @since v0.11.4
|
|
518
1508
|
*/
|
|
519
1509
|
destroy(): void;
|
|
520
1510
|
}
|
|
521
|
-
|
|
522
1511
|
const METHODS: string[];
|
|
523
|
-
|
|
524
1512
|
const STATUS_CODES: {
|
|
525
1513
|
[errorCode: number]: string | undefined;
|
|
526
1514
|
[errorCode: string]: string | undefined;
|
|
527
1515
|
};
|
|
528
|
-
|
|
1516
|
+
/**
|
|
1517
|
+
* Returns a new instance of {@link Server}.
|
|
1518
|
+
*
|
|
1519
|
+
* The `requestListener` is a function which is automatically
|
|
1520
|
+
* added to the `'request'` event.
|
|
1521
|
+
*
|
|
1522
|
+
* ```js
|
|
1523
|
+
* import http from 'node:http';
|
|
1524
|
+
*
|
|
1525
|
+
* // Create a local server to receive data from
|
|
1526
|
+
* const server = http.createServer((req, res) => {
|
|
1527
|
+
* res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
1528
|
+
* res.end(JSON.stringify({
|
|
1529
|
+
* data: 'Hello World!',
|
|
1530
|
+
* }));
|
|
1531
|
+
* });
|
|
1532
|
+
*
|
|
1533
|
+
* server.listen(8000);
|
|
1534
|
+
* ```
|
|
1535
|
+
*
|
|
1536
|
+
* ```js
|
|
1537
|
+
* import http from 'node:http';
|
|
1538
|
+
*
|
|
1539
|
+
* // Create a local server to receive data from
|
|
1540
|
+
* const server = http.createServer();
|
|
1541
|
+
*
|
|
1542
|
+
* // Listen to the request event
|
|
1543
|
+
* server.on('request', (request, res) => {
|
|
1544
|
+
* res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
1545
|
+
* res.end(JSON.stringify({
|
|
1546
|
+
* data: 'Hello World!',
|
|
1547
|
+
* }));
|
|
1548
|
+
* });
|
|
1549
|
+
*
|
|
1550
|
+
* server.listen(8000);
|
|
1551
|
+
* ```
|
|
1552
|
+
* @since v0.1.13
|
|
1553
|
+
*/
|
|
529
1554
|
function createServer<
|
|
530
1555
|
Request extends typeof IncomingMessage = typeof IncomingMessage,
|
|
531
1556
|
Response extends typeof ServerResponse = typeof ServerResponse,
|
|
@@ -537,42 +1562,344 @@ declare module "http" {
|
|
|
537
1562
|
options: ServerOptions<Request, Response>,
|
|
538
1563
|
requestListener?: RequestListener<Request, Response>,
|
|
539
1564
|
): Server<Request, Response>;
|
|
540
|
-
|
|
541
1565
|
// although RequestOptions are passed as ClientRequestArgs to ClientRequest directly,
|
|
542
1566
|
// create interface RequestOptions would make the naming more clear to developers
|
|
543
1567
|
interface RequestOptions extends ClientRequestArgs {}
|
|
1568
|
+
/**
|
|
1569
|
+
* `options` in `socket.connect()` are also supported.
|
|
1570
|
+
*
|
|
1571
|
+
* Node.js maintains several connections per server to make HTTP requests.
|
|
1572
|
+
* This function allows one to transparently issue requests.
|
|
1573
|
+
*
|
|
1574
|
+
* `url` can be a string or a `URL` object. If `url` is a
|
|
1575
|
+
* string, it is automatically parsed with `new URL()`. If it is a `URL` object, it will be automatically converted to an ordinary `options` object.
|
|
1576
|
+
*
|
|
1577
|
+
* If both `url` and `options` are specified, the objects are merged, with the `options` properties taking precedence.
|
|
1578
|
+
*
|
|
1579
|
+
* The optional `callback` parameter will be added as a one-time listener for
|
|
1580
|
+
* the `'response'` event.
|
|
1581
|
+
*
|
|
1582
|
+
* `http.request()` returns an instance of the {@link ClientRequest} class. The `ClientRequest` instance is a writable stream. If one needs to
|
|
1583
|
+
* upload a file with a POST request, then write to the `ClientRequest` object.
|
|
1584
|
+
*
|
|
1585
|
+
* ```js
|
|
1586
|
+
* import http from 'node:http';
|
|
1587
|
+
* import { Buffer } from 'node:buffer';
|
|
1588
|
+
*
|
|
1589
|
+
* const postData = JSON.stringify({
|
|
1590
|
+
* 'msg': 'Hello World!',
|
|
1591
|
+
* });
|
|
1592
|
+
*
|
|
1593
|
+
* const options = {
|
|
1594
|
+
* hostname: 'www.google.com',
|
|
1595
|
+
* port: 80,
|
|
1596
|
+
* path: '/upload',
|
|
1597
|
+
* method: 'POST',
|
|
1598
|
+
* headers: {
|
|
1599
|
+
* 'Content-Type': 'application/json',
|
|
1600
|
+
* 'Content-Length': Buffer.byteLength(postData),
|
|
1601
|
+
* },
|
|
1602
|
+
* };
|
|
1603
|
+
*
|
|
1604
|
+
* const req = http.request(options, (res) => {
|
|
1605
|
+
* console.log(`STATUS: ${res.statusCode}`);
|
|
1606
|
+
* console.log(`HEADERS: ${JSON.stringify(res.headers)}`);
|
|
1607
|
+
* res.setEncoding('utf8');
|
|
1608
|
+
* res.on('data', (chunk) => {
|
|
1609
|
+
* console.log(`BODY: ${chunk}`);
|
|
1610
|
+
* });
|
|
1611
|
+
* res.on('end', () => {
|
|
1612
|
+
* console.log('No more data in response.');
|
|
1613
|
+
* });
|
|
1614
|
+
* });
|
|
1615
|
+
*
|
|
1616
|
+
* req.on('error', (e) => {
|
|
1617
|
+
* console.error(`problem with request: ${e.message}`);
|
|
1618
|
+
* });
|
|
1619
|
+
*
|
|
1620
|
+
* // Write data to request body
|
|
1621
|
+
* req.write(postData);
|
|
1622
|
+
* req.end();
|
|
1623
|
+
* ```
|
|
1624
|
+
*
|
|
1625
|
+
* In the example `req.end()` was called. With `http.request()` one
|
|
1626
|
+
* must always call `req.end()` to signify the end of the request -
|
|
1627
|
+
* even if there is no data being written to the request body.
|
|
1628
|
+
*
|
|
1629
|
+
* If any error is encountered during the request (be that with DNS resolution,
|
|
1630
|
+
* TCP level errors, or actual HTTP parse errors) an `'error'` event is emitted
|
|
1631
|
+
* on the returned request object. As with all `'error'` events, if no listeners
|
|
1632
|
+
* are registered the error will be thrown.
|
|
1633
|
+
*
|
|
1634
|
+
* There are a few special headers that should be noted.
|
|
1635
|
+
*
|
|
1636
|
+
* * Sending a 'Connection: keep-alive' will notify Node.js that the connection to
|
|
1637
|
+
* the server should be persisted until the next request.
|
|
1638
|
+
* * Sending a 'Content-Length' header will disable the default chunked encoding.
|
|
1639
|
+
* * Sending an 'Expect' header will immediately send the request headers.
|
|
1640
|
+
* Usually, when sending 'Expect: 100-continue', both a timeout and a listener
|
|
1641
|
+
* for the `'continue'` event should be set. See RFC 2616 Section 8.2.3 for more
|
|
1642
|
+
* information.
|
|
1643
|
+
* * Sending an Authorization header will override using the `auth` option
|
|
1644
|
+
* to compute basic authentication.
|
|
1645
|
+
*
|
|
1646
|
+
* Example using a `URL` as `options`:
|
|
1647
|
+
*
|
|
1648
|
+
* ```js
|
|
1649
|
+
* const options = new URL('http://abc:xyz@example.com');
|
|
1650
|
+
*
|
|
1651
|
+
* const req = http.request(options, (res) => {
|
|
1652
|
+
* // ...
|
|
1653
|
+
* });
|
|
1654
|
+
* ```
|
|
1655
|
+
*
|
|
1656
|
+
* In a successful request, the following events will be emitted in the following
|
|
1657
|
+
* order:
|
|
1658
|
+
*
|
|
1659
|
+
* * `'socket'`
|
|
1660
|
+
* * `'response'`
|
|
1661
|
+
* * `'data'` any number of times, on the `res` object
|
|
1662
|
+
* (`'data'` will not be emitted at all if the response body is empty, for
|
|
1663
|
+
* instance, in most redirects)
|
|
1664
|
+
* * `'end'` on the `res` object
|
|
1665
|
+
* * `'close'`
|
|
1666
|
+
*
|
|
1667
|
+
* In the case of a connection error, the following events will be emitted:
|
|
1668
|
+
*
|
|
1669
|
+
* * `'socket'`
|
|
1670
|
+
* * `'error'`
|
|
1671
|
+
* * `'close'`
|
|
1672
|
+
*
|
|
1673
|
+
* In the case of a premature connection close before the response is received,
|
|
1674
|
+
* the following events will be emitted in the following order:
|
|
1675
|
+
*
|
|
1676
|
+
* * `'socket'`
|
|
1677
|
+
* * `'error'` with an error with message `'Error: socket hang up'` and code `'ECONNRESET'`
|
|
1678
|
+
* * `'close'`
|
|
1679
|
+
*
|
|
1680
|
+
* In the case of a premature connection close after the response is received,
|
|
1681
|
+
* the following events will be emitted in the following order:
|
|
1682
|
+
*
|
|
1683
|
+
* * `'socket'`
|
|
1684
|
+
* * `'response'`
|
|
1685
|
+
* * `'data'` any number of times, on the `res` object
|
|
1686
|
+
* * (connection closed here)
|
|
1687
|
+
* * `'aborted'` on the `res` object
|
|
1688
|
+
* * `'close'`
|
|
1689
|
+
* * `'error'` on the `res` object with an error with message `'Error: aborted'` and code `'ECONNRESET'`
|
|
1690
|
+
* * `'close'` on the `res` object
|
|
1691
|
+
*
|
|
1692
|
+
* If `req.destroy()` is called before a socket is assigned, the following
|
|
1693
|
+
* events will be emitted in the following order:
|
|
1694
|
+
*
|
|
1695
|
+
* * (`req.destroy()` called here)
|
|
1696
|
+
* * `'error'` with an error with message `'Error: socket hang up'` and code `'ECONNRESET'`, or the error with which `req.destroy()` was called
|
|
1697
|
+
* * `'close'`
|
|
1698
|
+
*
|
|
1699
|
+
* If `req.destroy()` is called before the connection succeeds, the following
|
|
1700
|
+
* events will be emitted in the following order:
|
|
1701
|
+
*
|
|
1702
|
+
* * `'socket'`
|
|
1703
|
+
* * (`req.destroy()` called here)
|
|
1704
|
+
* * `'error'` with an error with message `'Error: socket hang up'` and code `'ECONNRESET'`, or the error with which `req.destroy()` was called
|
|
1705
|
+
* * `'close'`
|
|
1706
|
+
*
|
|
1707
|
+
* If `req.destroy()` is called after the response is received, the following
|
|
1708
|
+
* events will be emitted in the following order:
|
|
1709
|
+
*
|
|
1710
|
+
* * `'socket'`
|
|
1711
|
+
* * `'response'`
|
|
1712
|
+
* * `'data'` any number of times, on the `res` object
|
|
1713
|
+
* * (`req.destroy()` called here)
|
|
1714
|
+
* * `'aborted'` on the `res` object
|
|
1715
|
+
* * `'close'`
|
|
1716
|
+
* * `'error'` on the `res` object with an error with message `'Error: aborted'` and code `'ECONNRESET'`, or the error with which `req.destroy()` was called
|
|
1717
|
+
* * `'close'` on the `res` object
|
|
1718
|
+
*
|
|
1719
|
+
* If `req.abort()` is called before a socket is assigned, the following
|
|
1720
|
+
* events will be emitted in the following order:
|
|
1721
|
+
*
|
|
1722
|
+
* * (`req.abort()` called here)
|
|
1723
|
+
* * `'abort'`
|
|
1724
|
+
* * `'close'`
|
|
1725
|
+
*
|
|
1726
|
+
* If `req.abort()` is called before the connection succeeds, the following
|
|
1727
|
+
* events will be emitted in the following order:
|
|
1728
|
+
*
|
|
1729
|
+
* * `'socket'`
|
|
1730
|
+
* * (`req.abort()` called here)
|
|
1731
|
+
* * `'abort'`
|
|
1732
|
+
* * `'error'` with an error with message `'Error: socket hang up'` and code `'ECONNRESET'`
|
|
1733
|
+
* * `'close'`
|
|
1734
|
+
*
|
|
1735
|
+
* If `req.abort()` is called after the response is received, the following
|
|
1736
|
+
* events will be emitted in the following order:
|
|
1737
|
+
*
|
|
1738
|
+
* * `'socket'`
|
|
1739
|
+
* * `'response'`
|
|
1740
|
+
* * `'data'` any number of times, on the `res` object
|
|
1741
|
+
* * (`req.abort()` called here)
|
|
1742
|
+
* * `'abort'`
|
|
1743
|
+
* * `'aborted'` on the `res` object
|
|
1744
|
+
* * `'error'` on the `res` object with an error with message `'Error: aborted'` and code `'ECONNRESET'`.
|
|
1745
|
+
* * `'close'`
|
|
1746
|
+
* * `'close'` on the `res` object
|
|
1747
|
+
*
|
|
1748
|
+
* Setting the `timeout` option or using the `setTimeout()` function will
|
|
1749
|
+
* not abort the request or do anything besides add a `'timeout'` event.
|
|
1750
|
+
*
|
|
1751
|
+
* Passing an `AbortSignal` and then calling `abort()` on the corresponding `AbortController` will behave the same way as calling `.destroy()` on the
|
|
1752
|
+
* request. Specifically, the `'error'` event will be emitted with an error with
|
|
1753
|
+
* the message `'AbortError: The operation was aborted'`, the code `'ABORT_ERR'` and the `cause`, if one was provided.
|
|
1754
|
+
* @since v0.3.6
|
|
1755
|
+
*/
|
|
544
1756
|
function request(options: RequestOptions | string | URL, callback?: (res: IncomingMessage) => void): ClientRequest;
|
|
545
1757
|
function request(
|
|
546
1758
|
url: string | URL,
|
|
547
1759
|
options: RequestOptions,
|
|
548
1760
|
callback?: (res: IncomingMessage) => void,
|
|
549
1761
|
): ClientRequest;
|
|
1762
|
+
/**
|
|
1763
|
+
* Since most requests are GET requests without bodies, Node.js provides this
|
|
1764
|
+
* convenience method. The only difference between this method and {@link request} is that it sets the method to GET by default and calls `req.end()` automatically. The callback must take care to
|
|
1765
|
+
* consume the response
|
|
1766
|
+
* data for reasons stated in {@link ClientRequest} section.
|
|
1767
|
+
*
|
|
1768
|
+
* The `callback` is invoked with a single argument that is an instance of {@link IncomingMessage}.
|
|
1769
|
+
*
|
|
1770
|
+
* JSON fetching example:
|
|
1771
|
+
*
|
|
1772
|
+
* ```js
|
|
1773
|
+
* http.get('http://localhost:8000/', (res) => {
|
|
1774
|
+
* const { statusCode } = res;
|
|
1775
|
+
* const contentType = res.headers['content-type'];
|
|
1776
|
+
*
|
|
1777
|
+
* let error;
|
|
1778
|
+
* // Any 2xx status code signals a successful response but
|
|
1779
|
+
* // here we're only checking for 200.
|
|
1780
|
+
* if (statusCode !== 200) {
|
|
1781
|
+
* error = new Error('Request Failed.\n' +
|
|
1782
|
+
* `Status Code: ${statusCode}`);
|
|
1783
|
+
* } else if (!/^application\/json/.test(contentType)) {
|
|
1784
|
+
* error = new Error('Invalid content-type.\n' +
|
|
1785
|
+
* `Expected application/json but received ${contentType}`);
|
|
1786
|
+
* }
|
|
1787
|
+
* if (error) {
|
|
1788
|
+
* console.error(error.message);
|
|
1789
|
+
* // Consume response data to free up memory
|
|
1790
|
+
* res.resume();
|
|
1791
|
+
* return;
|
|
1792
|
+
* }
|
|
1793
|
+
*
|
|
1794
|
+
* res.setEncoding('utf8');
|
|
1795
|
+
* let rawData = '';
|
|
1796
|
+
* res.on('data', (chunk) => { rawData += chunk; });
|
|
1797
|
+
* res.on('end', () => {
|
|
1798
|
+
* try {
|
|
1799
|
+
* const parsedData = JSON.parse(rawData);
|
|
1800
|
+
* console.log(parsedData);
|
|
1801
|
+
* } catch (e) {
|
|
1802
|
+
* console.error(e.message);
|
|
1803
|
+
* }
|
|
1804
|
+
* });
|
|
1805
|
+
* }).on('error', (e) => {
|
|
1806
|
+
* console.error(`Got error: ${e.message}`);
|
|
1807
|
+
* });
|
|
1808
|
+
*
|
|
1809
|
+
* // Create a local server to receive data from
|
|
1810
|
+
* const server = http.createServer((req, res) => {
|
|
1811
|
+
* res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
1812
|
+
* res.end(JSON.stringify({
|
|
1813
|
+
* data: 'Hello World!',
|
|
1814
|
+
* }));
|
|
1815
|
+
* });
|
|
1816
|
+
*
|
|
1817
|
+
* server.listen(8000);
|
|
1818
|
+
* ```
|
|
1819
|
+
* @since v0.3.6
|
|
1820
|
+
* @param options Accepts the same `options` as {@link request}, with the method set to GET by default.
|
|
1821
|
+
*/
|
|
550
1822
|
function get(options: RequestOptions | string | URL, callback?: (res: IncomingMessage) => void): ClientRequest;
|
|
551
1823
|
function get(url: string | URL, options: RequestOptions, callback?: (res: IncomingMessage) => void): ClientRequest;
|
|
552
|
-
|
|
553
1824
|
/**
|
|
554
|
-
* Performs the low-level validations on the provided name that are done when `res.setHeader(name, value)` is called.
|
|
555
|
-
*
|
|
556
|
-
*
|
|
1825
|
+
* Performs the low-level validations on the provided `name` that are done when `res.setHeader(name, value)` is called.
|
|
1826
|
+
*
|
|
1827
|
+
* Passing illegal value as `name` will result in a `TypeError` being thrown,
|
|
1828
|
+
* identified by `code: 'ERR_INVALID_HTTP_TOKEN'`.
|
|
1829
|
+
*
|
|
1830
|
+
* It is not necessary to use this method before passing headers to an HTTP request
|
|
1831
|
+
* or response. The HTTP module will automatically validate such headers.
|
|
1832
|
+
*
|
|
1833
|
+
* Example:
|
|
1834
|
+
*
|
|
1835
|
+
* ```js
|
|
1836
|
+
* import { validateHeaderName } from 'node:http';
|
|
1837
|
+
*
|
|
1838
|
+
* try {
|
|
1839
|
+
* validateHeaderName('');
|
|
1840
|
+
* } catch (err) {
|
|
1841
|
+
* console.error(err instanceof TypeError); // --> true
|
|
1842
|
+
* console.error(err.code); // --> 'ERR_INVALID_HTTP_TOKEN'
|
|
1843
|
+
* console.error(err.message); // --> 'Header name must be a valid HTTP token [""]'
|
|
1844
|
+
* }
|
|
1845
|
+
* ```
|
|
557
1846
|
* @since v14.3.0
|
|
1847
|
+
* @param [label='Header name'] Label for error message.
|
|
558
1848
|
*/
|
|
559
1849
|
function validateHeaderName(name: string): void;
|
|
560
1850
|
/**
|
|
561
|
-
* Performs the low-level validations on the provided value that are done when `res.setHeader(name, value)` is called.
|
|
562
|
-
*
|
|
563
|
-
*
|
|
564
|
-
*
|
|
1851
|
+
* Performs the low-level validations on the provided `value` that are done when `res.setHeader(name, value)` is called.
|
|
1852
|
+
*
|
|
1853
|
+
* Passing illegal value as `value` will result in a `TypeError` being thrown.
|
|
1854
|
+
*
|
|
1855
|
+
* * Undefined value error is identified by `code: 'ERR_HTTP_INVALID_HEADER_VALUE'`.
|
|
1856
|
+
* * Invalid value character error is identified by `code: 'ERR_INVALID_CHAR'`.
|
|
1857
|
+
*
|
|
1858
|
+
* It is not necessary to use this method before passing headers to an HTTP request
|
|
1859
|
+
* or response. The HTTP module will automatically validate such headers.
|
|
1860
|
+
*
|
|
1861
|
+
* Examples:
|
|
1862
|
+
*
|
|
1863
|
+
* ```js
|
|
1864
|
+
* import { validateHeaderValue } from 'node:http';
|
|
1865
|
+
*
|
|
1866
|
+
* try {
|
|
1867
|
+
* validateHeaderValue('x-my-header', undefined);
|
|
1868
|
+
* } catch (err) {
|
|
1869
|
+
* console.error(err instanceof TypeError); // --> true
|
|
1870
|
+
* console.error(err.code === 'ERR_HTTP_INVALID_HEADER_VALUE'); // --> true
|
|
1871
|
+
* console.error(err.message); // --> 'Invalid value "undefined" for header "x-my-header"'
|
|
1872
|
+
* }
|
|
1873
|
+
*
|
|
1874
|
+
* try {
|
|
1875
|
+
* validateHeaderValue('x-my-header', 'oʊmɪɡə');
|
|
1876
|
+
* } catch (err) {
|
|
1877
|
+
* console.error(err instanceof TypeError); // --> true
|
|
1878
|
+
* console.error(err.code === 'ERR_INVALID_CHAR'); // --> true
|
|
1879
|
+
* console.error(err.message); // --> 'Invalid character in header content ["x-my-header"]'
|
|
1880
|
+
* }
|
|
1881
|
+
* ```
|
|
1882
|
+
* @since v14.3.0
|
|
565
1883
|
* @param name Header name
|
|
566
1884
|
* @param value Header value
|
|
567
|
-
* @since v14.3.0
|
|
568
1885
|
*/
|
|
569
1886
|
function validateHeaderValue(name: string, value: string): void;
|
|
570
|
-
|
|
1887
|
+
/**
|
|
1888
|
+
* Set the maximum number of idle HTTP parsers.
|
|
1889
|
+
* @since v18.8.0, v16.18.0
|
|
1890
|
+
* @param [max=1000]
|
|
1891
|
+
*/
|
|
1892
|
+
function setMaxIdleHTTPParsers(max: number): void;
|
|
1893
|
+
/**
|
|
1894
|
+
* Global instance of `Agent` which is used as the default for all HTTP client
|
|
1895
|
+
* requests. Diverges from a default `Agent` configuration by having `keepAlive`
|
|
1896
|
+
* enabled and a `timeout` of 5 seconds.
|
|
1897
|
+
* @since v0.5.9
|
|
1898
|
+
*/
|
|
571
1899
|
let globalAgent: Agent;
|
|
572
|
-
|
|
573
1900
|
/**
|
|
574
1901
|
* Read-only property specifying the maximum allowed size of HTTP headers in bytes.
|
|
575
|
-
* Defaults to 16KB. Configurable using the
|
|
1902
|
+
* Defaults to 16KB. Configurable using the `--max-http-header-size` CLI option.
|
|
576
1903
|
*/
|
|
577
1904
|
const maxHeaderSize: number;
|
|
578
1905
|
}
|