@luckylillia-dev/luckylillia 0.0.0-stage → 9.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/chunks/preload-helper-D5R8FHQt.js +342 -0
- package/chunks/preload-helper-D5R8FHQt.js.map +1 -0
- package/default_config.json +83 -0
- package/llbot-core.js +35013 -0
- package/llbot-core.js.map +1 -0
- package/llbot.js +138 -0
- package/llbot.js.map +1 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/commands.d.ts +86 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/commands.js +1 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/config.d.ts +14 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/config.js +1 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/ffmpeg.d.ts +41 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/ffmpeg.js +1 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/http.d.ts +88 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/http.js +1 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/index.d.ts +17 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/index.js +6 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/internal.d.ts +430 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/internal.js +7 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/manifest.d.ts +68 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/manifest.js +1 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/server.d.ts +23 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/server.js +1 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/storage.d.ts +21 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/storage.js +1 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/testing.d.ts +71 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/testing.js +1123 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/universal.d.ts +299 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/universal.js +1 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/webui.d.ts +762 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/webui.js +9 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/package.json +63 -0
- package/node_modules/@satorijs/element/jsx-dev-runtime.d.ts +3 -0
- package/node_modules/@satorijs/element/jsx-runtime.d.ts +3 -0
- package/node_modules/@satorijs/element/lib/index.cjs +447 -0
- package/node_modules/@satorijs/element/lib/index.d.ts +116 -0
- package/node_modules/@satorijs/element/lib/index.mjs +455 -0
- package/node_modules/@satorijs/element/package.json +60 -0
- package/node_modules/@satorijs/element/src/index.ts +559 -0
- package/node_modules/@satorijs/protocol/lib/index.cjs +187 -0
- package/node_modules/@satorijs/protocol/lib/index.d.ts +328 -0
- package/node_modules/@satorijs/protocol/lib/index.mjs +148 -0
- package/node_modules/@satorijs/protocol/package.json +44 -0
- package/node_modules/@satorijs/protocol/src/index.ts +513 -0
- package/node_modules/@standard-schema/spec/LICENSE +21 -0
- package/node_modules/@standard-schema/spec/README.md +198 -0
- package/node_modules/@standard-schema/spec/dist/index.cjs +18 -0
- package/node_modules/@standard-schema/spec/dist/index.d.cts +119 -0
- package/node_modules/@standard-schema/spec/dist/index.d.ts +119 -0
- package/node_modules/@standard-schema/spec/dist/index.js +0 -0
- package/node_modules/@standard-schema/spec/package.json +52 -0
- package/node_modules/cordis/README.md +10 -0
- package/node_modules/cordis/bin.js +16 -0
- package/node_modules/cordis/lib/context.d.ts +32 -0
- package/node_modules/cordis/lib/events.d.ts +62 -0
- package/node_modules/cordis/lib/fiber.d.ts +85 -0
- package/node_modules/cordis/lib/index.d.ts +7 -0
- package/node_modules/cordis/lib/index.js +1577 -0
- package/node_modules/cordis/lib/logger.d.ts +74 -0
- package/node_modules/cordis/lib/reflect.d.ts +54 -0
- package/node_modules/cordis/lib/registry.d.ts +78 -0
- package/node_modules/cordis/lib/service.d.ts +19 -0
- package/node_modules/cordis/lib/utils.d.ts +50 -0
- package/node_modules/cordis/package.json +49 -0
- package/node_modules/cosmokit/LICENSE +21 -0
- package/node_modules/cosmokit/README.md +24 -0
- package/node_modules/cosmokit/lib/index.cjs +419 -0
- package/node_modules/cosmokit/lib/index.cjs.map +6 -0
- package/node_modules/cosmokit/lib/index.d.ts +142 -0
- package/node_modules/cosmokit/lib/index.mjs +357 -0
- package/node_modules/cosmokit/lib/index.mjs.map +6 -0
- package/node_modules/cosmokit/package.json +57 -0
- package/node_modules/cosmokit/src/array.ts +35 -0
- package/node_modules/cosmokit/src/index.ts +5 -0
- package/node_modules/cosmokit/src/misc.ts +57 -0
- package/node_modules/cosmokit/src/string.ts +101 -0
- package/node_modules/cosmokit/src/time.ts +91 -0
- package/node_modules/cosmokit/src/types.ts +131 -0
- package/node_modules/schemastery/README.md +342 -0
- package/node_modules/schemastery/lib/index.cjs +648 -0
- package/node_modules/schemastery/lib/index.cjs.map +6 -0
- package/node_modules/schemastery/lib/index.d.ts +138 -0
- package/node_modules/schemastery/lib/index.mjs +656 -0
- package/node_modules/schemastery/lib/index.mjs.map +6 -0
- package/node_modules/schemastery/package.json +32 -0
- package/node_modules/schemastery/src/index.ts +841 -0
- package/node_modules/undici/LICENSE +21 -0
- package/node_modules/undici/README.md +741 -0
- package/node_modules/undici/docs/docs/api/Agent.md +84 -0
- package/node_modules/undici/docs/docs/api/BalancedPool.md +99 -0
- package/node_modules/undici/docs/docs/api/CacheStorage.md +30 -0
- package/node_modules/undici/docs/docs/api/CacheStore.md +164 -0
- package/node_modules/undici/docs/docs/api/Client.md +290 -0
- package/node_modules/undici/docs/docs/api/ClientStats.md +27 -0
- package/node_modules/undici/docs/docs/api/Connector.md +115 -0
- package/node_modules/undici/docs/docs/api/ContentType.md +57 -0
- package/node_modules/undici/docs/docs/api/Cookies.md +128 -0
- package/node_modules/undici/docs/docs/api/Debug.md +62 -0
- package/node_modules/undici/docs/docs/api/DiagnosticsChannel.md +317 -0
- package/node_modules/undici/docs/docs/api/Dispatcher.md +1393 -0
- package/node_modules/undici/docs/docs/api/EnvHttpProxyAgent.md +159 -0
- package/node_modules/undici/docs/docs/api/Errors.md +49 -0
- package/node_modules/undici/docs/docs/api/EventSource.md +45 -0
- package/node_modules/undici/docs/docs/api/Fetch.md +60 -0
- package/node_modules/undici/docs/docs/api/GlobalInstallation.md +139 -0
- package/node_modules/undici/docs/docs/api/H2CClient.md +263 -0
- package/node_modules/undici/docs/docs/api/MockAgent.md +603 -0
- package/node_modules/undici/docs/docs/api/MockCallHistory.md +197 -0
- package/node_modules/undici/docs/docs/api/MockCallHistoryLog.md +43 -0
- package/node_modules/undici/docs/docs/api/MockClient.md +81 -0
- package/node_modules/undici/docs/docs/api/MockErrors.md +12 -0
- package/node_modules/undici/docs/docs/api/MockPool.md +555 -0
- package/node_modules/undici/docs/docs/api/Pool.md +84 -0
- package/node_modules/undici/docs/docs/api/PoolStats.md +35 -0
- package/node_modules/undici/docs/docs/api/ProxyAgent.md +229 -0
- package/node_modules/undici/docs/docs/api/RedirectHandler.md +93 -0
- package/node_modules/undici/docs/docs/api/RetryAgent.md +50 -0
- package/node_modules/undici/docs/docs/api/RetryHandler.md +118 -0
- package/node_modules/undici/docs/docs/api/RoundRobinPool.md +145 -0
- package/node_modules/undici/docs/docs/api/SnapshotAgent.md +616 -0
- package/node_modules/undici/docs/docs/api/Socks5ProxyAgent.md +275 -0
- package/node_modules/undici/docs/docs/api/Util.md +25 -0
- package/node_modules/undici/docs/docs/api/WebSocket.md +141 -0
- package/node_modules/undici/docs/docs/api/api-lifecycle.md +91 -0
- package/node_modules/undici/docs/docs/best-practices/client-certificate.md +64 -0
- package/node_modules/undici/docs/docs/best-practices/crawling.md +58 -0
- package/node_modules/undici/docs/docs/best-practices/mocking-request.md +190 -0
- package/node_modules/undici/docs/docs/best-practices/proxy.md +127 -0
- package/node_modules/undici/docs/docs/best-practices/undici-vs-builtin-fetch.md +224 -0
- package/node_modules/undici/docs/docs/best-practices/writing-tests.md +63 -0
- package/node_modules/undici/index-fetch.js +65 -0
- package/node_modules/undici/index.d.ts +3 -0
- package/node_modules/undici/index.js +234 -0
- package/node_modules/undici/lib/api/abort-signal.js +59 -0
- package/node_modules/undici/lib/api/api-connect.js +110 -0
- package/node_modules/undici/lib/api/api-pipeline.js +252 -0
- package/node_modules/undici/lib/api/api-request.js +214 -0
- package/node_modules/undici/lib/api/api-stream.js +209 -0
- package/node_modules/undici/lib/api/api-upgrade.js +111 -0
- package/node_modules/undici/lib/api/index.js +7 -0
- package/node_modules/undici/lib/api/readable.js +580 -0
- package/node_modules/undici/lib/cache/memory-cache-store.js +279 -0
- package/node_modules/undici/lib/cache/sqlite-cache-store.js +467 -0
- package/node_modules/undici/lib/core/connect.js +159 -0
- package/node_modules/undici/lib/core/constants.js +143 -0
- package/node_modules/undici/lib/core/diagnostics.js +227 -0
- package/node_modules/undici/lib/core/errors.js +477 -0
- package/node_modules/undici/lib/core/request.js +485 -0
- package/node_modules/undici/lib/core/socks5-client.js +422 -0
- package/node_modules/undici/lib/core/socks5-utils.js +212 -0
- package/node_modules/undici/lib/core/symbols.js +76 -0
- package/node_modules/undici/lib/core/tree.js +160 -0
- package/node_modules/undici/lib/core/util.js +992 -0
- package/node_modules/undici/lib/dispatcher/agent.js +162 -0
- package/node_modules/undici/lib/dispatcher/balanced-pool.js +221 -0
- package/node_modules/undici/lib/dispatcher/client-h1.js +1744 -0
- package/node_modules/undici/lib/dispatcher/client-h2.js +1056 -0
- package/node_modules/undici/lib/dispatcher/client.js +669 -0
- package/node_modules/undici/lib/dispatcher/dispatcher-base.js +196 -0
- package/node_modules/undici/lib/dispatcher/dispatcher.js +48 -0
- package/node_modules/undici/lib/dispatcher/env-http-proxy-agent.js +146 -0
- package/node_modules/undici/lib/dispatcher/fixed-queue.js +135 -0
- package/node_modules/undici/lib/dispatcher/h2c-client.js +51 -0
- package/node_modules/undici/lib/dispatcher/pool-base.js +214 -0
- package/node_modules/undici/lib/dispatcher/pool.js +118 -0
- package/node_modules/undici/lib/dispatcher/proxy-agent.js +319 -0
- package/node_modules/undici/lib/dispatcher/retry-agent.js +35 -0
- package/node_modules/undici/lib/dispatcher/round-robin-pool.js +137 -0
- package/node_modules/undici/lib/dispatcher/socks5-proxy-agent.js +260 -0
- package/node_modules/undici/lib/encoding/index.js +33 -0
- package/node_modules/undici/lib/global.js +59 -0
- package/node_modules/undici/lib/handler/cache-handler.js +824 -0
- package/node_modules/undici/lib/handler/cache-revalidation-handler.js +124 -0
- package/node_modules/undici/lib/handler/decorator-handler.js +67 -0
- package/node_modules/undici/lib/handler/deduplication-handler.js +504 -0
- package/node_modules/undici/lib/handler/redirect-handler.js +245 -0
- package/node_modules/undici/lib/handler/retry-handler.js +504 -0
- package/node_modules/undici/lib/handler/unwrap-handler.js +106 -0
- package/node_modules/undici/lib/handler/wrap-handler.js +105 -0
- package/node_modules/undici/lib/interceptor/cache.js +621 -0
- package/node_modules/undici/lib/interceptor/decompress.js +561 -0
- package/node_modules/undici/lib/interceptor/deduplicate.js +117 -0
- package/node_modules/undici/lib/interceptor/dns.js +571 -0
- package/node_modules/undici/lib/interceptor/dump.js +99 -0
- package/node_modules/undici/lib/interceptor/redirect.js +21 -0
- package/node_modules/undici/lib/interceptor/response-error.js +95 -0
- package/node_modules/undici/lib/interceptor/retry.js +19 -0
- package/node_modules/undici/lib/llhttp/constants.d.ts +195 -0
- package/node_modules/undici/lib/llhttp/constants.js +531 -0
- package/node_modules/undici/lib/llhttp/llhttp-wasm.js +15 -0
- package/node_modules/undici/lib/llhttp/llhttp_simd-wasm.js +15 -0
- package/node_modules/undici/lib/llhttp/utils.d.ts +2 -0
- package/node_modules/undici/lib/llhttp/utils.js +12 -0
- package/node_modules/undici/lib/mock/mock-agent.js +232 -0
- package/node_modules/undici/lib/mock/mock-call-history.js +248 -0
- package/node_modules/undici/lib/mock/mock-client.js +68 -0
- package/node_modules/undici/lib/mock/mock-errors.js +29 -0
- package/node_modules/undici/lib/mock/mock-interceptor.js +209 -0
- package/node_modules/undici/lib/mock/mock-pool.js +68 -0
- package/node_modules/undici/lib/mock/mock-symbols.js +32 -0
- package/node_modules/undici/lib/mock/mock-utils.js +486 -0
- package/node_modules/undici/lib/mock/pending-interceptors-formatter.js +43 -0
- package/node_modules/undici/lib/mock/snapshot-agent.js +353 -0
- package/node_modules/undici/lib/mock/snapshot-recorder.js +588 -0
- package/node_modules/undici/lib/mock/snapshot-utils.js +158 -0
- package/node_modules/undici/lib/util/cache.js +676 -0
- package/node_modules/undici/lib/util/date.js +670 -0
- package/node_modules/undici/lib/util/promise.js +28 -0
- package/node_modules/undici/lib/util/runtime-features.js +124 -0
- package/node_modules/undici/lib/util/stats.js +32 -0
- package/node_modules/undici/lib/util/timers.js +425 -0
- package/node_modules/undici/lib/web/cache/cache.js +864 -0
- package/node_modules/undici/lib/web/cache/cachestorage.js +152 -0
- package/node_modules/undici/lib/web/cache/util.js +45 -0
- package/node_modules/undici/lib/web/cookies/constants.js +12 -0
- package/node_modules/undici/lib/web/cookies/index.js +201 -0
- package/node_modules/undici/lib/web/cookies/parse.js +315 -0
- package/node_modules/undici/lib/web/cookies/util.js +371 -0
- package/node_modules/undici/lib/web/eventsource/eventsource-stream.js +575 -0
- package/node_modules/undici/lib/web/eventsource/eventsource.js +504 -0
- package/node_modules/undici/lib/web/eventsource/util.js +29 -0
- package/node_modules/undici/lib/web/fetch/LICENSE +21 -0
- package/node_modules/undici/lib/web/fetch/body.js +509 -0
- package/node_modules/undici/lib/web/fetch/constants.js +131 -0
- package/node_modules/undici/lib/web/fetch/data-url.js +596 -0
- package/node_modules/undici/lib/web/fetch/formdata-parser.js +586 -0
- package/node_modules/undici/lib/web/fetch/formdata.js +259 -0
- package/node_modules/undici/lib/web/fetch/global.js +40 -0
- package/node_modules/undici/lib/web/fetch/headers.js +719 -0
- package/node_modules/undici/lib/web/fetch/index.js +2413 -0
- package/node_modules/undici/lib/web/fetch/request.js +1115 -0
- package/node_modules/undici/lib/web/fetch/response.js +641 -0
- package/node_modules/undici/lib/web/fetch/util.js +1522 -0
- package/node_modules/undici/lib/web/infra/index.js +243 -0
- package/node_modules/undici/lib/web/subresource-integrity/Readme.md +9 -0
- package/node_modules/undici/lib/web/subresource-integrity/subresource-integrity.js +307 -0
- package/node_modules/undici/lib/web/webidl/index.js +1006 -0
- package/node_modules/undici/lib/web/websocket/connection.js +339 -0
- package/node_modules/undici/lib/web/websocket/constants.js +126 -0
- package/node_modules/undici/lib/web/websocket/events.js +331 -0
- package/node_modules/undici/lib/web/websocket/frame.js +133 -0
- package/node_modules/undici/lib/web/websocket/permessage-deflate.js +105 -0
- package/node_modules/undici/lib/web/websocket/receiver.js +520 -0
- package/node_modules/undici/lib/web/websocket/sender.js +109 -0
- package/node_modules/undici/lib/web/websocket/stream/websocketerror.js +104 -0
- package/node_modules/undici/lib/web/websocket/stream/websocketstream.js +496 -0
- package/node_modules/undici/lib/web/websocket/util.js +347 -0
- package/node_modules/undici/lib/web/websocket/websocket.js +758 -0
- package/node_modules/undici/package.json +152 -0
- package/node_modules/undici/scripts/strip-comments.js +10 -0
- package/node_modules/undici/types/README.md +6 -0
- package/node_modules/undici/types/agent.d.ts +32 -0
- package/node_modules/undici/types/api.d.ts +43 -0
- package/node_modules/undici/types/balanced-pool.d.ts +30 -0
- package/node_modules/undici/types/cache-interceptor.d.ts +179 -0
- package/node_modules/undici/types/cache.d.ts +36 -0
- package/node_modules/undici/types/client-stats.d.ts +15 -0
- package/node_modules/undici/types/client.d.ts +153 -0
- package/node_modules/undici/types/connector.d.ts +36 -0
- package/node_modules/undici/types/content-type.d.ts +21 -0
- package/node_modules/undici/types/cookies.d.ts +30 -0
- package/node_modules/undici/types/diagnostics-channel.d.ts +74 -0
- package/node_modules/undici/types/dispatcher.d.ts +275 -0
- package/node_modules/undici/types/env-http-proxy-agent.d.ts +22 -0
- package/node_modules/undici/types/errors.d.ts +177 -0
- package/node_modules/undici/types/eventsource.d.ts +66 -0
- package/node_modules/undici/types/fetch.d.ts +231 -0
- package/node_modules/undici/types/formdata.d.ts +114 -0
- package/node_modules/undici/types/global-dispatcher.d.ts +9 -0
- package/node_modules/undici/types/global-origin.d.ts +7 -0
- package/node_modules/undici/types/h2c-client.d.ts +73 -0
- package/node_modules/undici/types/handlers.d.ts +14 -0
- package/node_modules/undici/types/header.d.ts +160 -0
- package/node_modules/undici/types/index.d.ts +91 -0
- package/node_modules/undici/types/interceptors.d.ts +82 -0
- package/node_modules/undici/types/mock-agent.d.ts +68 -0
- package/node_modules/undici/types/mock-call-history.d.ts +111 -0
- package/node_modules/undici/types/mock-client.d.ts +27 -0
- package/node_modules/undici/types/mock-errors.d.ts +12 -0
- package/node_modules/undici/types/mock-interceptor.d.ts +94 -0
- package/node_modules/undici/types/mock-pool.d.ts +27 -0
- package/node_modules/undici/types/patch.d.ts +29 -0
- package/node_modules/undici/types/pool-stats.d.ts +19 -0
- package/node_modules/undici/types/pool.d.ts +41 -0
- package/node_modules/undici/types/proxy-agent.d.ts +29 -0
- package/node_modules/undici/types/readable.d.ts +68 -0
- package/node_modules/undici/types/retry-agent.d.ts +8 -0
- package/node_modules/undici/types/retry-handler.d.ts +125 -0
- package/node_modules/undici/types/round-robin-pool.d.ts +41 -0
- package/node_modules/undici/types/snapshot-agent.d.ts +109 -0
- package/node_modules/undici/types/socks5-proxy-agent.d.ts +25 -0
- package/node_modules/undici/types/util.d.ts +18 -0
- package/node_modules/undici/types/utility.d.ts +7 -0
- package/node_modules/undici/types/webidl.d.ts +347 -0
- package/node_modules/undici/types/websocket.d.ts +188 -0
- package/node_modules/ws/LICENSE +20 -0
- package/node_modules/ws/README.md +548 -0
- package/node_modules/ws/browser.js +8 -0
- package/node_modules/ws/index.js +22 -0
- package/node_modules/ws/lib/buffer-util.js +131 -0
- package/node_modules/ws/lib/constants.js +19 -0
- package/node_modules/ws/lib/event-target.js +292 -0
- package/node_modules/ws/lib/extension.js +203 -0
- package/node_modules/ws/lib/limiter.js +55 -0
- package/node_modules/ws/lib/permessage-deflate.js +530 -0
- package/node_modules/ws/lib/receiver.js +743 -0
- package/node_modules/ws/lib/sender.js +607 -0
- package/node_modules/ws/lib/stream.js +161 -0
- package/node_modules/ws/lib/subprotocol.js +62 -0
- package/node_modules/ws/lib/validation.js +152 -0
- package/node_modules/ws/lib/websocket-server.js +562 -0
- package/node_modules/ws/lib/websocket.js +1407 -0
- package/node_modules/ws/package.json +74 -0
- package/node_modules/ws/wrapper.mjs +21 -0
- package/package.json +17 -4
- package/webui/assets/group-bot-profile-CYK81678.jpg +0 -0
- package/webui/assets/group-bot-settings-BBQBbfgh.jpg +0 -0
- package/webui/assets/index-CuH0UYYo.js +28 -0
- package/webui/assets/index-DjbPiYmB.css +2 -0
- package/webui/favicon.ico +0 -0
- package/webui/index.html +26 -0
- package/webui/logo-128.webp +0 -0
- package/webui/logo-192.webp +0 -0
- package/webui/logo-256.webp +0 -0
- package/webui/logo-64.webp +0 -0
- package/webui/logo.jpg +0 -0
- package/webui/plugin-shared/plugin-sdk-webui.js +3 -0
- package/webui/plugin-shared/react-dom.js +3 -0
- package/webui/plugin-shared/react-jsx-runtime.js +3 -0
- package/webui/plugin-shared/react.js +3 -0
- package//344/275/277/347/224/250/350/257/264/346/230/216.txt +6 -0
- package//346/233/264/346/226/260/346/227/245/345/277/227.txt +1091 -0
- package/README.md +0 -3
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const util = require('../core/util')
|
|
4
|
+
const { kBodyUsed, kRedirectCacheControl } = require('../core/symbols')
|
|
5
|
+
const assert = require('node:assert')
|
|
6
|
+
const { InvalidArgumentError } = require('../core/errors')
|
|
7
|
+
const EE = require('node:events')
|
|
8
|
+
|
|
9
|
+
const redirectableStatusCodes = [300, 301, 302, 303, 307, 308]
|
|
10
|
+
|
|
11
|
+
const kBody = Symbol('body')
|
|
12
|
+
|
|
13
|
+
const noop = () => {}
|
|
14
|
+
|
|
15
|
+
class BodyAsyncIterable {
|
|
16
|
+
constructor (body) {
|
|
17
|
+
this[kBody] = body
|
|
18
|
+
this[kBodyUsed] = false
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async * [Symbol.asyncIterator] () {
|
|
22
|
+
assert(!this[kBodyUsed], 'disturbed')
|
|
23
|
+
this[kBodyUsed] = true
|
|
24
|
+
yield * this[kBody]
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
class RedirectHandler {
|
|
29
|
+
static buildDispatch (dispatcher, maxRedirections) {
|
|
30
|
+
if (maxRedirections != null && (!Number.isInteger(maxRedirections) || maxRedirections < 0)) {
|
|
31
|
+
throw new InvalidArgumentError('maxRedirections must be a positive number')
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const dispatch = dispatcher.dispatch.bind(dispatcher)
|
|
35
|
+
return (opts, originalHandler) => dispatch(opts, new RedirectHandler(dispatch, maxRedirections, opts, originalHandler))
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
constructor (dispatch, maxRedirections, opts, handler) {
|
|
39
|
+
if (maxRedirections != null && (!Number.isInteger(maxRedirections) || maxRedirections < 0)) {
|
|
40
|
+
throw new InvalidArgumentError('maxRedirections must be a positive number')
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
this.dispatch = dispatch
|
|
44
|
+
this.location = null
|
|
45
|
+
const { maxRedirections: _, ...cleanOpts } = opts
|
|
46
|
+
this.opts = cleanOpts // opts must be a copy, exclude maxRedirections
|
|
47
|
+
this.maxRedirections = maxRedirections
|
|
48
|
+
this.handler = handler
|
|
49
|
+
this.history = []
|
|
50
|
+
// Retain cache-control from suppressed redirect hops for an outer cache.
|
|
51
|
+
Object.defineProperty(this.history, kRedirectCacheControl, {
|
|
52
|
+
value: [],
|
|
53
|
+
enumerable: false
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
if (util.isStream(this.opts.body)) {
|
|
57
|
+
// TODO (fix): Provide some way for the user to cache the file to e.g. /tmp
|
|
58
|
+
// so that it can be dispatched again?
|
|
59
|
+
// TODO (fix): Do we need 100-expect support to provide a way to do this properly?
|
|
60
|
+
if (util.bodyLength(this.opts.body) === 0) {
|
|
61
|
+
this.opts.body
|
|
62
|
+
.on('data', function () {
|
|
63
|
+
assert(false)
|
|
64
|
+
})
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (typeof this.opts.body.readableDidRead !== 'boolean') {
|
|
68
|
+
this.opts.body[kBodyUsed] = false
|
|
69
|
+
EE.prototype.on.call(this.opts.body, 'data', function () {
|
|
70
|
+
this[kBodyUsed] = true
|
|
71
|
+
})
|
|
72
|
+
}
|
|
73
|
+
} else if (this.opts.body && typeof this.opts.body.pipeTo === 'function') {
|
|
74
|
+
// TODO (fix): We can't access ReadableStream internal state
|
|
75
|
+
// to determine whether or not it has been disturbed. This is just
|
|
76
|
+
// a workaround.
|
|
77
|
+
this.opts.body = new BodyAsyncIterable(this.opts.body)
|
|
78
|
+
} else if (
|
|
79
|
+
this.opts.body &&
|
|
80
|
+
typeof this.opts.body !== 'string' &&
|
|
81
|
+
!ArrayBuffer.isView(this.opts.body) &&
|
|
82
|
+
util.isIterable(this.opts.body) &&
|
|
83
|
+
!util.isFormDataLike(this.opts.body)
|
|
84
|
+
) {
|
|
85
|
+
// TODO: Should we allow re-using iterable if !this.opts.idempotent
|
|
86
|
+
// or through some other flag?
|
|
87
|
+
this.opts.body = new BodyAsyncIterable(this.opts.body)
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
onRequestStart (controller, context) {
|
|
92
|
+
this.handler.onRequestStart?.(controller, { ...context, history: this.history })
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
onRequestUpgrade (controller, statusCode, headers, socket) {
|
|
96
|
+
this.handler.onRequestUpgrade?.(controller, statusCode, headers, socket)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
onResponseStart (controller, statusCode, headers, statusMessage) {
|
|
100
|
+
if (this.opts.throwOnMaxRedirect && this.history.length >= this.maxRedirections) {
|
|
101
|
+
throw new Error('max redirects')
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// https://tools.ietf.org/html/rfc7231#section-6.4.2
|
|
105
|
+
// https://fetch.spec.whatwg.org/#http-redirect-fetch
|
|
106
|
+
// In case of HTTP 301 or 302 with POST, change the method to GET
|
|
107
|
+
if ((statusCode === 301 || statusCode === 302) && this.opts.method === 'POST') {
|
|
108
|
+
this.opts.method = 'GET'
|
|
109
|
+
if (util.isStream(this.opts.body)) {
|
|
110
|
+
util.destroy(this.opts.body.on('error', noop))
|
|
111
|
+
}
|
|
112
|
+
this.opts.body = null
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// https://tools.ietf.org/html/rfc7231#section-6.4.4
|
|
116
|
+
// In case of HTTP 303, always replace method to be either HEAD or GET
|
|
117
|
+
if (statusCode === 303 && this.opts.method !== 'HEAD') {
|
|
118
|
+
this.opts.method = 'GET'
|
|
119
|
+
if (util.isStream(this.opts.body)) {
|
|
120
|
+
util.destroy(this.opts.body.on('error', noop))
|
|
121
|
+
}
|
|
122
|
+
this.opts.body = null
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
this.location = this.history.length >= this.maxRedirections || util.isDisturbed(this.opts.body) || redirectableStatusCodes.indexOf(statusCode) === -1
|
|
126
|
+
? null
|
|
127
|
+
: headers.location
|
|
128
|
+
|
|
129
|
+
if (this.opts.origin) {
|
|
130
|
+
this.history.push(new URL(this.opts.path, this.opts.origin))
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (!this.location) {
|
|
134
|
+
this.handler.onResponseStart?.(controller, statusCode, headers, statusMessage)
|
|
135
|
+
return
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
this.history[kRedirectCacheControl].push(headers['cache-control'])
|
|
139
|
+
|
|
140
|
+
const { origin, pathname, search } = util.parseURL(new URL(this.location, this.opts.origin && new URL(this.opts.path, this.opts.origin)))
|
|
141
|
+
const path = search ? `${pathname}${search}` : pathname
|
|
142
|
+
|
|
143
|
+
// Check for redirect loops by seeing if we've already visited this URL in our history
|
|
144
|
+
// This catches the case where Client/Pool try to handle cross-origin redirects but fail
|
|
145
|
+
// and keep redirecting to the same URL in an infinite loop
|
|
146
|
+
const redirectUrlString = `${origin}${path}`
|
|
147
|
+
for (const historyUrl of this.history) {
|
|
148
|
+
if (historyUrl.toString() === redirectUrlString) {
|
|
149
|
+
throw new InvalidArgumentError(`Redirect loop detected. Cannot redirect to ${origin}. This typically happens when using a Client or Pool with cross-origin redirects. Use an Agent for cross-origin redirects.`)
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// Remove headers referring to the original URL.
|
|
154
|
+
// By default it is Host only, unless it's a 303 (see below), which removes also all Content-* headers.
|
|
155
|
+
// https://tools.ietf.org/html/rfc7231#section-6.4
|
|
156
|
+
this.opts.headers = cleanRequestHeaders(this.opts.headers, statusCode === 303, this.opts.origin !== origin)
|
|
157
|
+
this.opts.path = path
|
|
158
|
+
this.opts.origin = origin
|
|
159
|
+
this.opts.query = null
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
onResponseData (controller, chunk) {
|
|
163
|
+
if (this.location) {
|
|
164
|
+
/*
|
|
165
|
+
https://tools.ietf.org/html/rfc7231#section-6.4
|
|
166
|
+
|
|
167
|
+
TLDR: undici always ignores 3xx response bodies.
|
|
168
|
+
|
|
169
|
+
Redirection is used to serve the requested resource from another URL, so it assumes that
|
|
170
|
+
no body is generated (and thus can be ignored). Even though generating a body is not prohibited.
|
|
171
|
+
|
|
172
|
+
For status 301, 302, 303, 307 and 308 (the latter from RFC 7238), the specs mention that the body usually
|
|
173
|
+
(which means it's optional and not mandated) contain just an hyperlink to the value of
|
|
174
|
+
the Location response header, so the body can be ignored safely.
|
|
175
|
+
|
|
176
|
+
For status 300, which is "Multiple Choices", the spec mentions both generating a Location
|
|
177
|
+
response header AND a response body with the other possible location to follow.
|
|
178
|
+
Since the spec explicitly chooses not to specify a format for such body and leave it to
|
|
179
|
+
servers and browsers implementors, we ignore the body as there is no specified way to eventually parse it.
|
|
180
|
+
*/
|
|
181
|
+
} else {
|
|
182
|
+
this.handler.onResponseData?.(controller, chunk)
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
onResponseEnd (controller, trailers) {
|
|
187
|
+
if (this.location) {
|
|
188
|
+
/*
|
|
189
|
+
https://tools.ietf.org/html/rfc7231#section-6.4
|
|
190
|
+
|
|
191
|
+
TLDR: undici always ignores 3xx response trailers as they are not expected in case of redirections
|
|
192
|
+
and neither are useful if present.
|
|
193
|
+
|
|
194
|
+
See comment on onData method above for more detailed information.
|
|
195
|
+
*/
|
|
196
|
+
this.dispatch(this.opts, this)
|
|
197
|
+
} else {
|
|
198
|
+
this.handler.onResponseEnd(controller, trailers)
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
onResponseError (controller, error) {
|
|
203
|
+
this.handler.onResponseError?.(controller, error)
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// https://tools.ietf.org/html/rfc7231#section-6.4.4
|
|
208
|
+
function shouldRemoveHeader (header, removeContent, unknownOrigin) {
|
|
209
|
+
if (header.length === 4) {
|
|
210
|
+
return util.headerNameToString(header) === 'host'
|
|
211
|
+
}
|
|
212
|
+
if (removeContent && util.headerNameToString(header).startsWith('content-')) {
|
|
213
|
+
return true
|
|
214
|
+
}
|
|
215
|
+
if (unknownOrigin && (header.length === 13 || header.length === 6 || header.length === 19)) {
|
|
216
|
+
const name = util.headerNameToString(header)
|
|
217
|
+
return name === 'authorization' || name === 'cookie' || name === 'proxy-authorization'
|
|
218
|
+
}
|
|
219
|
+
return false
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// https://tools.ietf.org/html/rfc7231#section-6.4
|
|
223
|
+
function cleanRequestHeaders (headers, removeContent, unknownOrigin) {
|
|
224
|
+
const ret = []
|
|
225
|
+
if (Array.isArray(headers)) {
|
|
226
|
+
for (let i = 0; i < headers.length; i += 2) {
|
|
227
|
+
if (!shouldRemoveHeader(headers[i], removeContent, unknownOrigin)) {
|
|
228
|
+
ret.push(headers[i], headers[i + 1])
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
} else if (headers && typeof headers === 'object') {
|
|
232
|
+
const entries = util.hasSafeIterator(headers) ? headers : Object.entries(headers)
|
|
233
|
+
|
|
234
|
+
for (const [key, value] of entries) {
|
|
235
|
+
if (!shouldRemoveHeader(key, removeContent, unknownOrigin)) {
|
|
236
|
+
ret.push(key, value)
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
} else {
|
|
240
|
+
assert(headers == null, 'headers must be an object or an array')
|
|
241
|
+
}
|
|
242
|
+
return ret
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
module.exports = RedirectHandler
|