@xrkseek/harness 0.2.4 → 0.2.6
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/node_modules/@xrkseek/core-tools/dist/index.d.ts +1 -0
- package/node_modules/@xrkseek/core-tools/dist/index.d.ts.map +1 -1
- package/node_modules/@xrkseek/core-tools/dist/index.js +1 -0
- package/node_modules/@xrkseek/core-tools/dist/index.js.map +1 -1
- package/node_modules/@xrkseek/core-tools/dist/settings-tools.d.ts +37 -0
- package/node_modules/@xrkseek/core-tools/dist/settings-tools.d.ts.map +1 -0
- package/node_modules/@xrkseek/core-tools/dist/settings-tools.js +161 -0
- package/node_modules/@xrkseek/core-tools/dist/settings-tools.js.map +1 -0
- package/node_modules/@xrkseek/core-tools/dist/std-tools.d.ts +4 -1
- package/node_modules/@xrkseek/core-tools/dist/std-tools.d.ts.map +1 -1
- package/node_modules/@xrkseek/core-tools/dist/std-tools.js +6 -1
- package/node_modules/@xrkseek/core-tools/dist/std-tools.js.map +1 -1
- package/node_modules/@xrkseek/exec-fs/dist/read-image.d.ts.map +1 -1
- package/node_modules/@xrkseek/exec-fs/dist/read-image.js +20 -2
- package/node_modules/@xrkseek/exec-fs/dist/read-image.js.map +1 -1
- package/node_modules/@xrkseek/preset-harness/dist/tsconfig.tsbuildinfo +1 -1
- package/node_modules/@xrkseek/preset-minimal/dist/tsconfig.tsbuildinfo +1 -1
- package/node_modules/@xrkseek/preset-server/dist/tsconfig.tsbuildinfo +1 -1
- package/node_modules/@xrkseek/server-config/dist/index.d.ts +2 -2
- package/node_modules/@xrkseek/server-config/dist/index.d.ts.map +1 -1
- package/node_modules/@xrkseek/server-config/dist/index.js +3 -2
- package/node_modules/@xrkseek/server-config/dist/index.js.map +1 -1
- package/node_modules/@xrkseek/server-config/dist/mcp-servers.d.ts +12 -1
- package/node_modules/@xrkseek/server-config/dist/mcp-servers.d.ts.map +1 -1
- package/node_modules/@xrkseek/server-config/dist/mcp-servers.js +56 -1
- package/node_modules/@xrkseek/server-config/dist/mcp-servers.js.map +1 -1
- package/node_modules/@xrkseek/server-face/dist/adapt/wire-event.d.ts.map +1 -1
- package/node_modules/@xrkseek/server-face/dist/adapt/wire-event.js +17 -1
- package/node_modules/@xrkseek/server-face/dist/adapt/wire-event.js.map +1 -1
- package/node_modules/@xrkseek/server-face/dist/context.d.ts +16 -0
- package/node_modules/@xrkseek/server-face/dist/context.d.ts.map +1 -1
- package/node_modules/@xrkseek/server-face/dist/dispatch.d.ts.map +1 -1
- package/node_modules/@xrkseek/server-face/dist/dispatch.js +5 -1
- package/node_modules/@xrkseek/server-face/dist/dispatch.js.map +1 -1
- package/node_modules/@xrkseek/server-face/dist/face-schema.d.ts.map +1 -1
- package/node_modules/@xrkseek/server-face/dist/face-schema.js +2 -0
- package/node_modules/@xrkseek/server-face/dist/face-schema.js.map +1 -1
- package/node_modules/@xrkseek/server-face/dist/handlers/host.d.ts.map +1 -1
- package/node_modules/@xrkseek/server-face/dist/handlers/host.js +2 -0
- package/node_modules/@xrkseek/server-face/dist/handlers/host.js.map +1 -1
- package/node_modules/@xrkseek/server-face/dist/handlers/remotes.d.ts +8 -0
- package/node_modules/@xrkseek/server-face/dist/handlers/remotes.d.ts.map +1 -1
- package/node_modules/@xrkseek/server-face/dist/handlers/remotes.js +155 -1
- package/node_modules/@xrkseek/server-face/dist/handlers/remotes.js.map +1 -1
- package/node_modules/@xrkseek/server-face/dist/handlers/session.d.ts.map +1 -1
- package/node_modules/@xrkseek/server-face/dist/handlers/session.js +11 -112
- package/node_modules/@xrkseek/server-face/dist/handlers/session.js.map +1 -1
- package/node_modules/@xrkseek/server-face/dist/index.d.ts +3 -2
- package/node_modules/@xrkseek/server-face/dist/index.d.ts.map +1 -1
- package/node_modules/@xrkseek/server-face/dist/index.js +3 -2
- package/node_modules/@xrkseek/server-face/dist/index.js.map +1 -1
- package/node_modules/@xrkseek/server-face/dist/plugin-inventory.d.ts +29 -3
- package/node_modules/@xrkseek/server-face/dist/plugin-inventory.d.ts.map +1 -1
- package/node_modules/@xrkseek/server-face/dist/plugin-inventory.js +169 -6
- package/node_modules/@xrkseek/server-face/dist/plugin-inventory.js.map +1 -1
- package/node_modules/@xrkseek/server-face/dist/presets-catalog.d.ts +9 -7
- package/node_modules/@xrkseek/server-face/dist/presets-catalog.d.ts.map +1 -1
- package/node_modules/@xrkseek/server-face/dist/presets-catalog.js +7 -17
- package/node_modules/@xrkseek/server-face/dist/presets-catalog.js.map +1 -1
- package/node_modules/@xrkseek/server-face/dist/runtime.d.ts +10 -0
- package/node_modules/@xrkseek/server-face/dist/runtime.d.ts.map +1 -1
- package/node_modules/@xrkseek/server-face/dist/runtime.js +8 -0
- package/node_modules/@xrkseek/server-face/dist/runtime.js.map +1 -1
- package/node_modules/@xrkseek/server-face/dist/select-session-model.d.ts +15 -0
- package/node_modules/@xrkseek/server-face/dist/select-session-model.d.ts.map +1 -0
- package/node_modules/@xrkseek/server-face/dist/select-session-model.js +117 -0
- package/node_modules/@xrkseek/server-face/dist/select-session-model.js.map +1 -0
- package/node_modules/@xrkseek/server-face/dist/settings-agent-tools.d.ts +7 -0
- package/node_modules/@xrkseek/server-face/dist/settings-agent-tools.d.ts.map +1 -0
- package/node_modules/@xrkseek/server-face/dist/settings-agent-tools.js +91 -0
- package/node_modules/@xrkseek/server-face/dist/settings-agent-tools.js.map +1 -0
- package/node_modules/@xrkseek/server-face/dist/settings-credentials.d.ts +7 -1
- package/node_modules/@xrkseek/server-face/dist/settings-credentials.d.ts.map +1 -1
- package/node_modules/@xrkseek/server-face/dist/settings-credentials.js +85 -26
- package/node_modules/@xrkseek/server-face/dist/settings-credentials.js.map +1 -1
- package/node_modules/@xrkseek/server-face/dist/slash.d.ts +4 -3
- package/node_modules/@xrkseek/server-face/dist/slash.d.ts.map +1 -1
- package/node_modules/@xrkseek/server-face/dist/slash.js +191 -20
- package/node_modules/@xrkseek/server-face/dist/slash.js.map +1 -1
- package/node_modules/@xrkseek/server-host/dist/http-proxy.d.ts +11 -0
- package/node_modules/@xrkseek/server-host/dist/http-proxy.d.ts.map +1 -0
- package/node_modules/@xrkseek/server-host/dist/http-proxy.js +42 -0
- package/node_modules/@xrkseek/server-host/dist/http-proxy.js.map +1 -0
- package/node_modules/@xrkseek/server-host/dist/index.d.ts.map +1 -1
- package/node_modules/@xrkseek/server-host/dist/index.js +43 -3
- package/node_modules/@xrkseek/server-host/dist/index.js.map +1 -1
- package/node_modules/@xrkseek/server-host/dist/mcp-wire.d.ts +4 -3
- package/node_modules/@xrkseek/server-host/dist/mcp-wire.d.ts.map +1 -1
- package/node_modules/@xrkseek/server-host/dist/mcp-wire.js +14 -10
- package/node_modules/@xrkseek/server-host/dist/mcp-wire.js.map +1 -1
- package/node_modules/@xrkseek/server-host/package.json +57 -56
- package/node_modules/@xrkseek/server-http/dist/index.d.ts +1 -0
- package/node_modules/@xrkseek/server-http/dist/index.d.ts.map +1 -1
- package/node_modules/@xrkseek/server-http/dist/index.js +1 -0
- package/node_modules/@xrkseek/server-http/dist/index.js.map +1 -1
- package/node_modules/@xrkseek/server-http/dist/xrk/plugin-mutate.d.ts.map +1 -1
- package/node_modules/@xrkseek/server-http/dist/xrk/plugin-mutate.js +6 -1
- package/node_modules/@xrkseek/server-http/dist/xrk/plugin-mutate.js.map +1 -1
- 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 +288 -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 +315 -0
- package/node_modules/undici/docs/docs/api/Dispatcher.md +1392 -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 +153 -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 +464 -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 +75 -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 +158 -0
- package/node_modules/undici/lib/dispatcher/balanced-pool.js +221 -0
- package/node_modules/undici/lib/dispatcher/client-h1.js +1739 -0
- package/node_modules/undici/lib/dispatcher/client-h2.js +1051 -0
- package/node_modules/undici/lib/dispatcher/client.js +668 -0
- package/node_modules/undici/lib/dispatcher/dispatcher-base.js +184 -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 +776 -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 +460 -0
- package/node_modules/undici/lib/handler/redirect-handler.js +238 -0
- package/node_modules/undici/lib/handler/retry-handler.js +453 -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 +391 -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/.gitkeep +0 -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 +199 -0
- package/node_modules/undici/lib/web/cookies/parse.js +314 -0
- package/node_modules/undici/lib/web/cookies/util.js +352 -0
- package/node_modules/undici/lib/web/eventsource/eventsource-stream.js +494 -0
- package/node_modules/undici/lib/web/eventsource/eventsource.js +501 -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 +229 -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 +329 -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 +507 -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 +139 -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/package.json +3 -1
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { createInflate, createGunzip, createBrotliDecompress, createZstdDecompress } = require('node:zlib')
|
|
4
|
+
const { pipeline, Transform: TransformStream } = require('node:stream')
|
|
5
|
+
const { InvalidArgumentError, ResponseExceededMaxSizeError } = require('../core/errors')
|
|
6
|
+
const DecoratorHandler = require('../handler/decorator-handler')
|
|
7
|
+
const { runtimeFeatures } = require('../util/runtime-features')
|
|
8
|
+
|
|
9
|
+
/** @typedef {import('node:stream').Transform} Transform */
|
|
10
|
+
/** @typedef {import('node:stream').Transform} Controller */
|
|
11
|
+
/** @typedef {Transform&import('node:zlib').Zlib} DecompressorStream */
|
|
12
|
+
|
|
13
|
+
/** @type {Record<string, () => DecompressorStream>} */
|
|
14
|
+
const supportedEncodings = {
|
|
15
|
+
gzip: createGunzip,
|
|
16
|
+
'x-gzip': createGunzip,
|
|
17
|
+
br: createBrotliDecompress,
|
|
18
|
+
deflate: createInflate,
|
|
19
|
+
compress: createInflate,
|
|
20
|
+
'x-compress': createInflate,
|
|
21
|
+
...(runtimeFeatures.has('zstd') ? { zstd: createZstdDecompress } : {})
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const defaultSkipStatusCodes = /** @type {const} */ ([204, 304])
|
|
25
|
+
const defaultMaxSize = 64 * 1024 * 1024
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Limits the output of one stage in a decompression chain.
|
|
29
|
+
* @param {number} maxSize - Maximum output size in bytes
|
|
30
|
+
* @returns {Transform}
|
|
31
|
+
*/
|
|
32
|
+
function createMaxSizeLimiter (maxSize) {
|
|
33
|
+
let size = 0
|
|
34
|
+
|
|
35
|
+
return new TransformStream({
|
|
36
|
+
transform (chunk, _encoding, callback) {
|
|
37
|
+
const decompressedSize = size + chunk.length
|
|
38
|
+
if (decompressedSize > maxSize) {
|
|
39
|
+
callback(new ResponseExceededMaxSizeError(
|
|
40
|
+
`Decompressed response size (${decompressedSize}) exceeded maxSize (${maxSize})`
|
|
41
|
+
))
|
|
42
|
+
return
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
size = decompressedSize
|
|
46
|
+
callback(null, chunk)
|
|
47
|
+
}
|
|
48
|
+
})
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
let warningEmitted = /** @type {boolean} */ (false)
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* @typedef {Object} DecompressHandlerOptions
|
|
55
|
+
* @property {number[]|Readonly<number[]>} [skipStatusCodes=[204, 304]] - List of status codes to skip decompression for
|
|
56
|
+
* @property {boolean} [skipErrorResponses] - Whether to skip decompression for error responses (status codes >= 400)
|
|
57
|
+
* @property {number} [maxSize=67108864] - Maximum decompressed response size in bytes
|
|
58
|
+
*/
|
|
59
|
+
|
|
60
|
+
class DecompressHandler extends DecoratorHandler {
|
|
61
|
+
/** @type {Transform[]} */
|
|
62
|
+
#decompressors = []
|
|
63
|
+
/** @type {Record<string, string | string[]> | undefined} */
|
|
64
|
+
#trailers
|
|
65
|
+
/** @type {Readonly<number[]>} */
|
|
66
|
+
#skipStatusCodes
|
|
67
|
+
/** @type {boolean} */
|
|
68
|
+
#skipErrorResponses
|
|
69
|
+
/** @type {number} */
|
|
70
|
+
#maxSize
|
|
71
|
+
/** @type {number} */
|
|
72
|
+
#decompressedSize = 0
|
|
73
|
+
/** @type {boolean} */
|
|
74
|
+
#terminated = false
|
|
75
|
+
/** @type {boolean} */
|
|
76
|
+
#inputEnded = false
|
|
77
|
+
|
|
78
|
+
constructor (handler, { skipStatusCodes = defaultSkipStatusCodes, skipErrorResponses = true, maxSize = defaultMaxSize } = {}) {
|
|
79
|
+
if (!Number.isSafeInteger(maxSize) || maxSize < 1) {
|
|
80
|
+
throw new InvalidArgumentError('maxSize must be a positive integer')
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
super(handler)
|
|
84
|
+
this.#skipStatusCodes = skipStatusCodes
|
|
85
|
+
this.#skipErrorResponses = skipErrorResponses
|
|
86
|
+
this.#maxSize = maxSize
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Determines if decompression should be skipped based on encoding and status code
|
|
91
|
+
* @param {string} contentEncoding - Content-Encoding header value
|
|
92
|
+
* @param {number} statusCode - HTTP status code of the response
|
|
93
|
+
* @returns {boolean} - True if decompression should be skipped
|
|
94
|
+
*/
|
|
95
|
+
#shouldSkipDecompression (contentEncoding, statusCode) {
|
|
96
|
+
if (!contentEncoding || statusCode < 200) return true
|
|
97
|
+
if (this.#skipStatusCodes.includes(statusCode)) return true
|
|
98
|
+
if (this.#skipErrorResponses && statusCode >= 400) return true
|
|
99
|
+
return false
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Creates a chain of decompressors for multiple content encodings
|
|
104
|
+
*
|
|
105
|
+
* @param {string} encodings - Comma-separated list of content encodings
|
|
106
|
+
* @returns {Array<Transform>} - Array of decompressor and limiting streams
|
|
107
|
+
* @throws {Error} - If the number of content-encodings exceeds the maximum allowed
|
|
108
|
+
*/
|
|
109
|
+
#createDecompressionChain (encodings) {
|
|
110
|
+
const parts = encodings.split(',')
|
|
111
|
+
|
|
112
|
+
// Limit the number of content-encodings to prevent resource exhaustion.
|
|
113
|
+
// CVE fix similar to urllib3 (GHSA-gm62-xv2j-4w53) and curl (CVE-2022-32206).
|
|
114
|
+
const maxContentEncodings = 5
|
|
115
|
+
if (parts.length > maxContentEncodings) {
|
|
116
|
+
throw new Error(`too many content-encodings in response: ${parts.length}, maximum allowed is ${maxContentEncodings}`)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** @type {DecompressorStream[]} */
|
|
120
|
+
const decompressors = []
|
|
121
|
+
|
|
122
|
+
for (let i = parts.length - 1; i >= 0; i--) {
|
|
123
|
+
const encoding = parts[i].trim()
|
|
124
|
+
if (!encoding) continue
|
|
125
|
+
|
|
126
|
+
if (!supportedEncodings[encoding]) {
|
|
127
|
+
decompressors.length = 0 // Clear if unsupported encoding
|
|
128
|
+
return decompressors // Unsupported encoding
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
decompressors.push(supportedEncodings[encoding]())
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (decompressors.length < 2) {
|
|
135
|
+
return decompressors
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** @type {Transform[]} */
|
|
139
|
+
const streams = []
|
|
140
|
+
for (let i = 0; i < decompressors.length; i++) {
|
|
141
|
+
streams.push(decompressors[i])
|
|
142
|
+
if (i < decompressors.length - 1) {
|
|
143
|
+
streams.push(createMaxSizeLimiter(this.#maxSize))
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return streams
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Stops decompression and reports an error.
|
|
152
|
+
* @param {Controller} controller - The controller to coordinate with
|
|
153
|
+
* @param {Error} error - The decompression error
|
|
154
|
+
* @returns {void}
|
|
155
|
+
*/
|
|
156
|
+
#fail (controller, error) {
|
|
157
|
+
if (this.#terminated) {
|
|
158
|
+
return
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (this.#inputEnded) {
|
|
162
|
+
// The request is already marked complete once the compressed input ends,
|
|
163
|
+
// so controller.abort() can no longer propagate decoder flush errors.
|
|
164
|
+
this.onResponseError(controller, error)
|
|
165
|
+
} else {
|
|
166
|
+
controller.abort(error)
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Sets up event handlers for a decompressor stream using readable events
|
|
172
|
+
* @param {DecompressorStream} decompressor - The decompressor stream
|
|
173
|
+
* @param {Controller} controller - The controller to coordinate with
|
|
174
|
+
* @returns {void}
|
|
175
|
+
*/
|
|
176
|
+
#setupDecompressorEvents (decompressor, controller) {
|
|
177
|
+
decompressor.on('readable', () => {
|
|
178
|
+
if (this.#terminated) {
|
|
179
|
+
return
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
let chunk
|
|
183
|
+
while ((chunk = decompressor.read()) !== null) {
|
|
184
|
+
const decompressedSize = this.#decompressedSize + chunk.length
|
|
185
|
+
if (decompressedSize > this.#maxSize) {
|
|
186
|
+
this.#fail(controller, new ResponseExceededMaxSizeError(
|
|
187
|
+
`Decompressed response size (${decompressedSize}) exceeded maxSize (${this.#maxSize})`
|
|
188
|
+
))
|
|
189
|
+
return
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
this.#decompressedSize = decompressedSize
|
|
193
|
+
const result = super.onResponseData(controller, chunk)
|
|
194
|
+
if (result === false) {
|
|
195
|
+
break
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
})
|
|
199
|
+
|
|
200
|
+
decompressor.on('error', (error) => {
|
|
201
|
+
this.#fail(controller, error)
|
|
202
|
+
})
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Sets up event handling for a single decompressor
|
|
207
|
+
* @param {Controller} controller - The controller to handle events
|
|
208
|
+
* @returns {void}
|
|
209
|
+
*/
|
|
210
|
+
#setupSingleDecompressor (controller) {
|
|
211
|
+
const decompressor = this.#decompressors[0]
|
|
212
|
+
this.#setupDecompressorEvents(decompressor, controller)
|
|
213
|
+
|
|
214
|
+
decompressor.on('end', () => {
|
|
215
|
+
if (this.#terminated) {
|
|
216
|
+
return
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
this.#terminated = true
|
|
220
|
+
this.#cleanupDecompressors()
|
|
221
|
+
super.onResponseEnd(controller, this.#trailers)
|
|
222
|
+
})
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Sets up event handling for multiple chained decompressors using pipeline
|
|
227
|
+
* @param {Controller} controller - The controller to handle events
|
|
228
|
+
* @returns {void}
|
|
229
|
+
*/
|
|
230
|
+
#setupMultipleDecompressors (controller) {
|
|
231
|
+
const lastDecompressor = this.#decompressors[this.#decompressors.length - 1]
|
|
232
|
+
this.#setupDecompressorEvents(lastDecompressor, controller)
|
|
233
|
+
|
|
234
|
+
pipeline(this.#decompressors, (err) => {
|
|
235
|
+
if (this.#terminated) {
|
|
236
|
+
return
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
if (err) {
|
|
240
|
+
this.#fail(controller, err)
|
|
241
|
+
return
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
this.#terminated = true
|
|
245
|
+
this.#cleanupDecompressors()
|
|
246
|
+
super.onResponseEnd(controller, this.#trailers)
|
|
247
|
+
})
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Cleans up decompressor references to prevent memory leaks
|
|
252
|
+
* @returns {void}
|
|
253
|
+
*/
|
|
254
|
+
#cleanupDecompressors () {
|
|
255
|
+
this.#decompressors.length = 0
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* @param {Controller} controller
|
|
260
|
+
* @param {number} statusCode
|
|
261
|
+
* @param {Record<string, string | string[] | undefined>} headers
|
|
262
|
+
* @param {string} statusMessage
|
|
263
|
+
* @returns {void}
|
|
264
|
+
*/
|
|
265
|
+
onResponseStart (controller, statusCode, headers, statusMessage) {
|
|
266
|
+
const contentEncoding = headers['content-encoding']
|
|
267
|
+
|
|
268
|
+
// If content encoding is not supported or status code is in skip list
|
|
269
|
+
if (this.#shouldSkipDecompression(contentEncoding, statusCode)) {
|
|
270
|
+
return super.onResponseStart(controller, statusCode, headers, statusMessage)
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
const decompressors = this.#createDecompressionChain(contentEncoding.toLowerCase())
|
|
274
|
+
|
|
275
|
+
if (decompressors.length === 0) {
|
|
276
|
+
this.#cleanupDecompressors()
|
|
277
|
+
return super.onResponseStart(controller, statusCode, headers, statusMessage)
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
this.#decompressors = decompressors
|
|
281
|
+
|
|
282
|
+
// Remove compression headers since we're decompressing
|
|
283
|
+
const { 'content-encoding': _, 'content-length': __, ...newHeaders } = headers
|
|
284
|
+
|
|
285
|
+
if (controller?.rawHeaders) {
|
|
286
|
+
const rawHeaders = controller.rawHeaders
|
|
287
|
+
|
|
288
|
+
if (Array.isArray(rawHeaders)) {
|
|
289
|
+
const filteredHeaders = []
|
|
290
|
+
for (let i = 0; i < rawHeaders.length; i += 2) {
|
|
291
|
+
const headerName = rawHeaders[i]
|
|
292
|
+
const name = Buffer.isBuffer(headerName) ? headerName.toString('latin1') : `${headerName}`
|
|
293
|
+
const lowerName = name.toLowerCase()
|
|
294
|
+
|
|
295
|
+
if (lowerName === 'content-encoding' || lowerName === 'content-length') {
|
|
296
|
+
continue
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
filteredHeaders.push(rawHeaders[i], rawHeaders[i + 1])
|
|
300
|
+
}
|
|
301
|
+
rawHeaders.splice(0, rawHeaders.length, ...filteredHeaders)
|
|
302
|
+
} else if (typeof rawHeaders === 'object') {
|
|
303
|
+
for (const name of Object.keys(rawHeaders)) {
|
|
304
|
+
const lowerName = name.toLowerCase()
|
|
305
|
+
if (lowerName === 'content-encoding' || lowerName === 'content-length') {
|
|
306
|
+
delete rawHeaders[name]
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
if (this.#decompressors.length === 1) {
|
|
313
|
+
this.#setupSingleDecompressor(controller)
|
|
314
|
+
} else {
|
|
315
|
+
this.#setupMultipleDecompressors(controller)
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
return super.onResponseStart(controller, statusCode, newHeaders, statusMessage)
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* @param {Controller} controller
|
|
323
|
+
* @param {Buffer} chunk
|
|
324
|
+
* @returns {void}
|
|
325
|
+
*/
|
|
326
|
+
onResponseData (controller, chunk) {
|
|
327
|
+
if (this.#decompressors.length > 0) {
|
|
328
|
+
this.#decompressors[0].write(chunk)
|
|
329
|
+
return
|
|
330
|
+
}
|
|
331
|
+
super.onResponseData(controller, chunk)
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* @param {Controller} controller
|
|
336
|
+
* @param {Record<string, string | string[]> | undefined} trailers
|
|
337
|
+
* @returns {void}
|
|
338
|
+
*/
|
|
339
|
+
onResponseEnd (controller, trailers) {
|
|
340
|
+
if (this.#decompressors.length > 0) {
|
|
341
|
+
this.#inputEnded = true
|
|
342
|
+
this.#trailers = trailers
|
|
343
|
+
this.#decompressors[0].end()
|
|
344
|
+
return
|
|
345
|
+
}
|
|
346
|
+
super.onResponseEnd(controller, trailers)
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* @param {Controller} controller
|
|
351
|
+
* @param {Error} err
|
|
352
|
+
* @returns {void}
|
|
353
|
+
*/
|
|
354
|
+
onResponseError (controller, err) {
|
|
355
|
+
if (this.#terminated) {
|
|
356
|
+
return
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
this.#terminated = true
|
|
360
|
+
for (const decompressor of this.#decompressors) {
|
|
361
|
+
decompressor.destroy()
|
|
362
|
+
}
|
|
363
|
+
this.#cleanupDecompressors()
|
|
364
|
+
super.onResponseError(controller, err)
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* Creates a decompression interceptor for HTTP responses
|
|
370
|
+
* @param {DecompressHandlerOptions} [options] - Options for the interceptor
|
|
371
|
+
* @returns {Function} - Interceptor function
|
|
372
|
+
*/
|
|
373
|
+
function createDecompressInterceptor (options = {}) {
|
|
374
|
+
// Emit experimental warning only once
|
|
375
|
+
if (!warningEmitted) {
|
|
376
|
+
process.emitWarning(
|
|
377
|
+
'DecompressInterceptor is experimental and subject to change',
|
|
378
|
+
'ExperimentalWarning'
|
|
379
|
+
)
|
|
380
|
+
warningEmitted = true
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
return (dispatch) => {
|
|
384
|
+
return (opts, handler) => {
|
|
385
|
+
const decompressHandler = new DecompressHandler(handler, options)
|
|
386
|
+
return dispatch(opts, decompressHandler)
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
module.exports = createDecompressInterceptor
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const diagnosticsChannel = require('node:diagnostics_channel')
|
|
4
|
+
const util = require('../core/util')
|
|
5
|
+
const DeduplicationHandler = require('../handler/deduplication-handler')
|
|
6
|
+
const { normalizeHeaders, makeCacheKey, makeDeduplicationKey } = require('../util/cache.js')
|
|
7
|
+
|
|
8
|
+
const pendingRequestsChannel = diagnosticsChannel.channel('undici:request:pending-requests')
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @param {import('../../types/interceptors.d.ts').default.DeduplicateInterceptorOpts} [opts]
|
|
12
|
+
* @returns {import('../../types/dispatcher.d.ts').default.DispatcherComposeInterceptor}
|
|
13
|
+
*/
|
|
14
|
+
module.exports = (opts = {}) => {
|
|
15
|
+
const {
|
|
16
|
+
methods = ['GET'],
|
|
17
|
+
skipHeaderNames = [],
|
|
18
|
+
excludeHeaderNames = [],
|
|
19
|
+
maxBufferSize = 5 * 1024 * 1024
|
|
20
|
+
} = opts
|
|
21
|
+
|
|
22
|
+
if (typeof opts !== 'object' || opts === null) {
|
|
23
|
+
throw new TypeError(`expected type of opts to be an Object, got ${opts === null ? 'null' : typeof opts}`)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (!Array.isArray(methods)) {
|
|
27
|
+
throw new TypeError(`expected opts.methods to be an array, got ${typeof methods}`)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
for (const method of methods) {
|
|
31
|
+
if (!util.safeHTTPMethods.includes(method)) {
|
|
32
|
+
throw new TypeError(`expected opts.methods to only contain safe HTTP methods, got ${method}`)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (!Array.isArray(skipHeaderNames)) {
|
|
37
|
+
throw new TypeError(`expected opts.skipHeaderNames to be an array, got ${typeof skipHeaderNames}`)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (!Array.isArray(excludeHeaderNames)) {
|
|
41
|
+
throw new TypeError(`expected opts.excludeHeaderNames to be an array, got ${typeof excludeHeaderNames}`)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (!Number.isFinite(maxBufferSize) || maxBufferSize <= 0) {
|
|
45
|
+
throw new TypeError(`expected opts.maxBufferSize to be a positive finite number, got ${maxBufferSize}`)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Convert to lowercase Set for case-insensitive header matching
|
|
49
|
+
const skipHeaderNamesSet = new Set(skipHeaderNames.map(name => name.toLowerCase()))
|
|
50
|
+
|
|
51
|
+
// Convert to lowercase Set for case-insensitive header exclusion from deduplication key
|
|
52
|
+
const excludeHeaderNamesSet = new Set(excludeHeaderNames.map(name => name.toLowerCase()))
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Map of pending requests for deduplication
|
|
56
|
+
* @type {Map<string, DeduplicationHandler>}
|
|
57
|
+
*/
|
|
58
|
+
const pendingRequests = new Map()
|
|
59
|
+
|
|
60
|
+
return dispatch => {
|
|
61
|
+
return (opts, handler) => {
|
|
62
|
+
if (!opts.origin || methods.includes(opts.method) === false) {
|
|
63
|
+
return dispatch(opts, handler)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
opts = {
|
|
67
|
+
...opts,
|
|
68
|
+
headers: normalizeHeaders(opts)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Skip deduplication if request contains any of the specified headers
|
|
72
|
+
if (skipHeaderNamesSet.size > 0) {
|
|
73
|
+
for (const headerName of Object.keys(opts.headers)) {
|
|
74
|
+
if (skipHeaderNamesSet.has(headerName.toLowerCase())) {
|
|
75
|
+
return dispatch(opts, handler)
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const cacheKey = makeCacheKey(opts)
|
|
81
|
+
const dedupeKey = makeDeduplicationKey(cacheKey, excludeHeaderNamesSet)
|
|
82
|
+
|
|
83
|
+
// Check if there's already a pending request for this key
|
|
84
|
+
const pendingHandler = pendingRequests.get(dedupeKey)
|
|
85
|
+
if (pendingHandler) {
|
|
86
|
+
// Add this handler to the waiting list when safe.
|
|
87
|
+
// If body streaming has already started, this request must be sent independently.
|
|
88
|
+
if (pendingHandler.addWaitingHandler(handler)) {
|
|
89
|
+
return true
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return dispatch(opts, handler)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Create a new deduplication handler
|
|
96
|
+
const deduplicationHandler = new DeduplicationHandler(
|
|
97
|
+
handler,
|
|
98
|
+
() => {
|
|
99
|
+
// Clean up when request completes
|
|
100
|
+
pendingRequests.delete(dedupeKey)
|
|
101
|
+
if (pendingRequestsChannel.hasSubscribers) {
|
|
102
|
+
pendingRequestsChannel.publish({ size: pendingRequests.size, key: dedupeKey, type: 'removed' })
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
maxBufferSize
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
// Register the pending request
|
|
109
|
+
pendingRequests.set(dedupeKey, deduplicationHandler)
|
|
110
|
+
if (pendingRequestsChannel.hasSubscribers) {
|
|
111
|
+
pendingRequestsChannel.publish({ size: pendingRequests.size, key: dedupeKey, type: 'added' })
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return dispatch(opts, deduplicationHandler)
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|