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