cf-workers-native 0.0.0-stage → 0.1.2-beta.local.sha2f5e4e6956f4
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/LICENSE +21 -0
- package/Package.swift +25 -0
- package/README.md +92 -2
- package/dist/android.d.ts +2 -0
- package/dist/android.js +1 -0
- package/dist/browser/abort/index.d.ts +13 -0
- package/dist/browser/abort/index.js +66 -0
- package/dist/browser/body/index.d.ts +24 -0
- package/dist/browser/body/index.js +116 -0
- package/dist/browser/body/stream-body.d.ts +13 -0
- package/dist/browser/body/stream-body.js +84 -0
- package/dist/browser/documents/body.d.ts +3 -0
- package/dist/browser/documents/body.js +48 -0
- package/dist/browser/documents/form-body.d.ts +1 -0
- package/dist/browser/documents/form-body.js +54 -0
- package/dist/browser/documents/host.d.ts +11 -0
- package/dist/browser/documents/host.js +256 -0
- package/dist/browser/documents/links-source.d.ts +1 -0
- package/dist/browser/documents/links-source.js +1 -0
- package/dist/browser/documents/links.d.ts +1 -0
- package/dist/browser/documents/links.js +33 -0
- package/dist/browser/documents/page-config.d.ts +5 -0
- package/dist/browser/documents/page-config.js +5 -0
- package/dist/browser/documents/page-source.d.ts +1 -0
- package/dist/browser/documents/page-source.js +1 -0
- package/dist/browser/documents/page.d.ts +2 -0
- package/dist/browser/documents/page.js +153 -0
- package/dist/browser/documents/registration.d.ts +5 -0
- package/dist/browser/documents/registration.js +75 -0
- package/dist/browser/documents/runtime.d.ts +7 -0
- package/dist/browser/documents/runtime.js +161 -0
- package/dist/browser/documents/service-worker.js +285 -0
- package/dist/browser/encoding/index.d.ts +7 -0
- package/dist/browser/encoding/index.js +3 -0
- package/dist/browser/fetch/LICENSE-3RD-PARTY.md +9 -0
- package/dist/browser/fetch/LICENSE-APACHE +177 -0
- package/dist/browser/fetch/host-call.d.ts +3 -0
- package/dist/browser/fetch/host-call.js +67 -0
- package/dist/browser/fetch/index.d.ts +5 -0
- package/dist/browser/fetch/index.js +96 -0
- package/dist/browser/fetch/interop.d.ts +6 -0
- package/dist/browser/fetch/interop.js +48 -0
- package/dist/browser/fetch/native-network.d.ts +20 -0
- package/dist/browser/fetch/native-network.js +233 -0
- package/dist/browser/fetch/outbound.d.ts +2 -0
- package/dist/browser/fetch/outbound.js +11 -0
- package/dist/browser/fetch/relay.d.ts +7 -0
- package/dist/browser/fetch/relay.js +100 -0
- package/dist/browser/fetch/scope.d.ts +8 -0
- package/dist/browser/fetch/scope.js +108 -0
- package/dist/browser/fetch/transport.d.ts +39 -0
- package/dist/browser/fetch/transport.js +136 -0
- package/dist/browser/headers/LICENSE-3RD-PARTY.md +9 -0
- package/dist/browser/headers/LICENSE-APACHE +177 -0
- package/dist/browser/headers/index.d.ts +20 -0
- package/dist/browser/headers/index.js +194 -0
- package/dist/browser/isolated/bridge.d.ts +8 -0
- package/dist/browser/isolated/bridge.js +267 -0
- package/dist/browser/isolated/protocol.d.ts +40 -0
- package/dist/browser/isolated/protocol.js +1 -0
- package/dist/browser/isolated/transport.d.ts +2 -0
- package/dist/browser/isolated/transport.js +157 -0
- package/dist/browser/request/LICENSE-3RD-PARTY.md +10 -0
- package/dist/browser/request/LICENSE-APACHE +177 -0
- package/dist/browser/request/index.d.ts +48 -0
- package/dist/browser/request/index.js +182 -0
- package/dist/browser/response/LICENSE-3RD-PARTY.md +10 -0
- package/dist/browser/response/LICENSE-APACHE +177 -0
- package/dist/browser/response/index.d.ts +43 -0
- package/dist/browser/response/index.js +192 -0
- package/dist/browser/response/status.d.ts +1 -0
- package/dist/browser/response/status.js +75 -0
- package/dist/browser/structured-clone/index.d.ts +1 -0
- package/dist/browser/structured-clone/index.js +479 -0
- package/dist/cloudflare/apis/cloudflare-node/index.d.ts +18 -0
- package/dist/cloudflare/apis/cloudflare-node/index.js +150 -0
- package/dist/cloudflare/apis/cloudflare-workers/index.d.ts +8 -0
- package/dist/cloudflare/apis/cloudflare-workers/index.js +37 -0
- package/dist/cloudflare/apis/types.d.ts +7 -0
- package/dist/cloudflare/apis/types.js +1 -0
- package/dist/cloudflare/bindings/config.d.ts +42 -0
- package/dist/cloudflare/bindings/config.js +280 -0
- package/dist/cloudflare/bindings/kv/contract.d.ts +6 -0
- package/dist/cloudflare/bindings/kv/contract.js +181 -0
- package/dist/cloudflare/bindings/kv/index.d.ts +18 -0
- package/dist/cloudflare/bindings/kv/index.js +61 -0
- package/dist/cloudflare/bindings/kv/storage.d.ts +25 -0
- package/dist/cloudflare/bindings/kv/storage.js +320 -0
- package/dist/cloudflare/bindings/kv/types.d.ts +50 -0
- package/dist/cloudflare/bindings/kv/types.js +1 -0
- package/dist/cloudflare/bindings/remote.d.ts +8 -0
- package/dist/cloudflare/bindings/remote.js +261 -0
- package/dist/cloudflare/workers/contract.d.ts +8 -0
- package/dist/cloudflare/workers/contract.js +65 -0
- package/dist/cloudflare/workers/feature.d.ts +10 -0
- package/dist/cloudflare/workers/feature.js +28 -0
- package/dist/cloudflare/workers/runtime.d.ts +23 -0
- package/dist/cloudflare/workers/runtime.js +121 -0
- package/dist/cloudflare/workers/types.d.ts +49 -0
- package/dist/cloudflare/workers/types.js +1 -0
- package/dist/cloudflare/workers/worker-runtime.d.ts +44 -0
- package/dist/cloudflare/workers/worker-runtime.js +267 -0
- package/dist/compat/assert/LICENSE-3RD-PARTY.md +5 -0
- package/dist/compat/assert/LICENSE-APACHE +177 -0
- package/dist/compat/assert/assertion-error.d.ts +26 -0
- package/dist/compat/assert/assertion-error.js +468 -0
- package/dist/compat/assert/diff.d.ts +26 -0
- package/dist/compat/assert/diff.js +329 -0
- package/dist/compat/assert/errors.d.ts +11 -0
- package/dist/compat/assert/errors.js +55 -0
- package/dist/compat/assert/index.cjs +24 -0
- package/dist/compat/assert/index.d.cts +43 -0
- package/dist/compat/assert/index.d.ts +50 -0
- package/dist/compat/assert/index.js +858 -0
- package/dist/compat/async-hooks/LICENSE-APACHE +177 -0
- package/dist/compat/async-hooks/NOTICE.md +8 -0
- package/dist/compat/async-hooks/callbacks.d.ts +7 -0
- package/dist/compat/async-hooks/callbacks.js +18 -0
- package/dist/compat/async-hooks/hooks.d.ts +10 -0
- package/dist/compat/async-hooks/hooks.js +111 -0
- package/dist/compat/async-hooks/index.d.ts +41 -0
- package/dist/compat/async-hooks/index.js +298 -0
- package/dist/compat/buffer/LICENSE-3RD-PARTY.md +15 -0
- package/dist/compat/buffer/LICENSE-APACHE +177 -0
- package/dist/compat/buffer/blob.d.ts +22 -0
- package/dist/compat/buffer/blob.js +210 -0
- package/dist/compat/buffer/bytes.d.ts +34 -0
- package/dist/compat/buffer/bytes.js +228 -0
- package/dist/compat/buffer/errors.d.ts +41 -0
- package/dist/compat/buffer/errors.js +265 -0
- package/dist/compat/buffer/index.d.ts +25 -0
- package/dist/compat/buffer/index.js +24 -0
- package/dist/compat/buffer/internal-buffer.d.ts +148 -0
- package/dist/compat/buffer/internal-buffer.js +1809 -0
- package/dist/compat/buffer/support.d.ts +13 -0
- package/dist/compat/buffer/support.js +65 -0
- package/dist/compat/child-process/LICENSE-3RD-PARTY.md +8 -0
- package/dist/compat/child-process/LICENSE-APACHE +177 -0
- package/dist/compat/child-process/errors.d.ts +4 -0
- package/dist/compat/child-process/errors.js +6 -0
- package/dist/compat/child-process/index.d.ts +49 -0
- package/dist/compat/child-process/index.js +96 -0
- package/dist/compat/cluster/LICENSE-3RD-PARTY.md +40 -0
- package/dist/compat/cluster/LICENSE-APACHE +177 -0
- package/dist/compat/cluster/errors.d.ts +4 -0
- package/dist/compat/cluster/errors.js +6 -0
- package/dist/compat/cluster/index.d.ts +47 -0
- package/dist/compat/cluster/index.js +88 -0
- package/dist/compat/constants/LICENSE-3RD-PARTY.md +6 -0
- package/dist/compat/constants/LICENSE-APACHE +177 -0
- package/dist/compat/constants/index.d.ts +481 -0
- package/dist/compat/constants/index.js +488 -0
- package/dist/compat/dgram/LICENSE-3RD-PARTY.md +8 -0
- package/dist/compat/dgram/LICENSE-APACHE +177 -0
- package/dist/compat/dgram/index.d.ts +10 -0
- package/dist/compat/dgram/index.js +132 -0
- package/dist/compat/diagnostics-channel/LICENSE-3RD-PARTY.md +13 -0
- package/dist/compat/diagnostics-channel/LICENSE-APACHE +177 -0
- package/dist/compat/diagnostics-channel/index.d.ts +73 -0
- package/dist/compat/diagnostics-channel/index.js +261 -0
- package/dist/compat/diagnostics-channel/native.d.ts +26 -0
- package/dist/compat/diagnostics-channel/native.js +154 -0
- package/dist/compat/dns/LICENSE-3RD-PARTY.md +5 -0
- package/dist/compat/dns/LICENSE-APACHE +177 -0
- package/dist/compat/dns/client.d.ts +72 -0
- package/dist/compat/dns/client.js +161 -0
- package/dist/compat/dns/constants.d.ts +27 -0
- package/dist/compat/dns/constants.js +31 -0
- package/dist/compat/dns/errors.d.ts +8 -0
- package/dist/compat/dns/errors.js +12 -0
- package/dist/compat/dns/index.d.ts +97 -0
- package/dist/compat/dns/index.js +127 -0
- package/dist/compat/dns/parser.d.ts +18 -0
- package/dist/compat/dns/parser.js +144 -0
- package/dist/compat/dns/promise-resolver.d.ts +82 -0
- package/dist/compat/dns/promise-resolver.js +113 -0
- package/dist/compat/dns/promises.d.ts +50 -0
- package/dist/compat/dns/promises.js +53 -0
- package/dist/compat/dns/resolver.d.ts +34 -0
- package/dist/compat/dns/resolver.js +415 -0
- package/dist/compat/domain/LICENSE-3RD-PARTY.md +5 -0
- package/dist/compat/domain/LICENSE-APACHE +177 -0
- package/dist/compat/domain/index.d.ts +22 -0
- package/dist/compat/domain/index.js +79 -0
- package/dist/compat/fs/index.d.ts +85 -0
- package/dist/compat/fs/index.js +255 -0
- package/dist/compat/fs/promises/index.d.ts +3 -0
- package/dist/compat/fs/promises/index.js +3 -0
- package/dist/compat/http/index.d.ts +322 -0
- package/dist/compat/http/index.js +1356 -0
- package/dist/compat/http/registry.d.ts +19 -0
- package/dist/compat/http/registry.js +13 -0
- package/dist/compat/http-agent/LICENSE-3RD-PARTY.md +5 -0
- package/dist/compat/http-agent/LICENSE-APACHE +177 -0
- package/dist/compat/http-agent/index.d.ts +7 -0
- package/dist/compat/http-agent/index.js +10 -0
- package/dist/compat/http-client/LICENSE-3RD-PARTY.md +5 -0
- package/dist/compat/http-client/LICENSE-APACHE +177 -0
- package/dist/compat/http-client/index.d.ts +6 -0
- package/dist/compat/http-client/index.js +7 -0
- package/dist/compat/http-incoming/LICENSE-3RD-PARTY.md +5 -0
- package/dist/compat/http-incoming/LICENSE-APACHE +177 -0
- package/dist/compat/http-incoming/index.d.ts +6 -0
- package/dist/compat/http-incoming/index.js +9 -0
- package/dist/compat/http2/LICENSE-3RD-PARTY.md +29 -0
- package/dist/compat/http2/LICENSE-APACHE +177 -0
- package/dist/compat/http2/constants.d.ts +255 -0
- package/dist/compat/http2/constants.js +515 -0
- package/dist/compat/http2/errors.d.ts +4 -0
- package/dist/compat/http2/errors.js +6 -0
- package/dist/compat/http2/index.d.ts +283 -0
- package/dist/compat/http2/index.js +68 -0
- package/dist/compat/https/LICENSE-3RD-PARTY.md +5 -0
- package/dist/compat/https/LICENSE-APACHE +177 -0
- package/dist/compat/https/agent.d.ts +10 -0
- package/dist/compat/https/agent.js +99 -0
- package/dist/compat/https/errors.d.ts +4 -0
- package/dist/compat/https/errors.js +6 -0
- package/dist/compat/https/index.d.ts +20 -0
- package/dist/compat/https/index.js +50 -0
- package/dist/compat/https/server.d.ts +8 -0
- package/dist/compat/https/server.js +27 -0
- package/dist/compat/immediate/index.d.ts +11 -0
- package/dist/compat/immediate/index.js +58 -0
- package/dist/compat/inspector/LICENSE-3RD-PARTY.md +34 -0
- package/dist/compat/inspector/LICENSE-APACHE +177 -0
- package/dist/compat/inspector/errors.d.ts +4 -0
- package/dist/compat/inspector/errors.js +6 -0
- package/dist/compat/inspector/index.d.ts +18 -0
- package/dist/compat/inspector/index.js +117 -0
- package/dist/compat/inspector/promises.d.ts +18 -0
- package/dist/compat/inspector/promises.js +114 -0
- package/dist/compat/module/index.cjs +2 -0
- package/dist/compat/module/index.d.cts +2 -0
- package/dist/compat/module/index.d.ts +11 -0
- package/dist/compat/module/index.js +44 -0
- package/dist/compat/module/resolve-unavailable.d.ts +1 -0
- package/dist/compat/module/resolve-unavailable.js +3 -0
- package/dist/compat/net/LICENSE-3RD-PARTY.md +15 -0
- package/dist/compat/net/LICENSE-APACHE +177 -0
- package/dist/compat/net/error-base.d.ts +14 -0
- package/dist/compat/net/error-base.js +62 -0
- package/dist/compat/net/errors.d.ts +76 -0
- package/dist/compat/net/errors.js +333 -0
- package/dist/compat/net/index.d.ts +23 -0
- package/dist/compat/net/index.js +46 -0
- package/dist/compat/net/internal-net.d.ts +236 -0
- package/dist/compat/net/internal-net.js +2292 -0
- package/dist/compat/net/ports.d.ts +32 -0
- package/dist/compat/net/ports.js +149 -0
- package/dist/compat/net/reader.d.ts +8 -0
- package/dist/compat/net/reader.js +36 -0
- package/dist/compat/net/sockets.d.ts +20 -0
- package/dist/compat/net/sockets.js +195 -0
- package/dist/compat/net/validators.d.ts +18 -0
- package/dist/compat/net/validators.js +154 -0
- package/dist/compat/os/LICENSE-3RD-PARTY.md +8 -0
- package/dist/compat/os/LICENSE-APACHE +177 -0
- package/dist/compat/os/index.d.ts +329 -0
- package/dist/compat/os/index.js +278 -0
- package/dist/compat/path/LICENSE-3RD-PARTY.md +35 -0
- package/dist/compat/path/LICENSE-APACHE +177 -0
- package/dist/compat/path/index.d.ts +4 -0
- package/dist/compat/path/index.js +11 -0
- package/dist/compat/path/internal-path.d.ts +95 -0
- package/dist/compat/path/internal-path.js +1542 -0
- package/dist/compat/path/posix/index.d.ts +4 -0
- package/dist/compat/path/posix/index.js +5 -0
- package/dist/compat/path/win32/index.d.ts +4 -0
- package/dist/compat/path/win32/index.js +5 -0
- package/dist/compat/perf-hooks/LICENSE-3RD-PARTY.md +5 -0
- package/dist/compat/perf-hooks/LICENSE-APACHE +177 -0
- package/dist/compat/perf-hooks/index.d.ts +85 -0
- package/dist/compat/perf-hooks/index.js +79 -0
- package/dist/compat/perf-hooks/performance.d.ts +96 -0
- package/dist/compat/perf-hooks/performance.js +445 -0
- package/dist/compat/punycode/LICENSE-3RD-PARTY.md +7 -0
- package/dist/compat/punycode/LICENSE-APACHE +177 -0
- package/dist/compat/punycode/index.d.ts +93 -0
- package/dist/compat/punycode/index.js +410 -0
- package/dist/compat/querystring/LICENSE-3RD-PARTY.md +35 -0
- package/dist/compat/querystring/LICENSE-APACHE +177 -0
- package/dist/compat/querystring/index.d.ts +14 -0
- package/dist/compat/querystring/index.js +18 -0
- package/dist/compat/querystring/internal-querystring.d.ts +22 -0
- package/dist/compat/querystring/internal-querystring.js +498 -0
- package/dist/compat/readline/LICENSE-3RD-PARTY.md +37 -0
- package/dist/compat/readline/LICENSE-APACHE +177 -0
- package/dist/compat/readline/index.d.ts +21 -0
- package/dist/compat/readline/index.js +56 -0
- package/dist/compat/readline/interface.d.ts +22 -0
- package/dist/compat/readline/interface.js +85 -0
- package/dist/compat/readline/internal-promises.d.ts +32 -0
- package/dist/compat/readline/internal-promises.js +104 -0
- package/dist/compat/readline/promises.d.ts +8 -0
- package/dist/compat/readline/promises.js +32 -0
- package/dist/compat/repl/LICENSE-3RD-PARTY.md +5 -0
- package/dist/compat/repl/LICENSE-APACHE +177 -0
- package/dist/compat/repl/builtin-modules.d.ts +1 -0
- package/dist/compat/repl/builtin-modules.js +101 -0
- package/dist/compat/repl/errors.d.ts +4 -0
- package/dist/compat/repl/errors.js +6 -0
- package/dist/compat/repl/index.d.ts +53 -0
- package/dist/compat/repl/index.js +106 -0
- package/dist/compat/sqlite/LICENSE-3RD-PARTY.md +6 -0
- package/dist/compat/sqlite/LICENSE-APACHE +177 -0
- package/dist/compat/sqlite/index.d.ts +12 -0
- package/dist/compat/sqlite/index.js +101 -0
- package/dist/compat/sqlite/native.d.ts +16 -0
- package/dist/compat/sqlite/native.js +33 -0
- package/dist/compat/stream/LICENSE-3RD-PARTY.md +13 -0
- package/dist/compat/stream/LICENSE-APACHE +177 -0
- package/dist/compat/stream/add-abort-signal.d.ts +4 -0
- package/dist/compat/stream/add-abort-signal.js +73 -0
- package/dist/compat/stream/compose.d.ts +1 -0
- package/dist/compat/stream/compose.js +313 -0
- package/dist/compat/stream/destroy.d.ts +5 -0
- package/dist/compat/stream/destroy.js +315 -0
- package/dist/compat/stream/duplex.d.ts +48 -0
- package/dist/compat/stream/duplex.js +789 -0
- package/dist/compat/stream/end-of-stream.d.ts +16 -0
- package/dist/compat/stream/end-of-stream.js +269 -0
- package/dist/compat/stream/errors.d.ts +40 -0
- package/dist/compat/stream/errors.js +86 -0
- package/dist/compat/stream/events.d.ts +6 -0
- package/dist/compat/stream/events.js +28 -0
- package/dist/compat/stream/index.cjs +27 -0
- package/dist/compat/stream/index.d.cts +25 -0
- package/dist/compat/stream/index.d.ts +20 -0
- package/dist/compat/stream/index.js +55 -0
- package/dist/compat/stream/legacy.d.ts +8 -0
- package/dist/compat/stream/legacy.js +105 -0
- package/dist/compat/stream/once.d.ts +7 -0
- package/dist/compat/stream/once.js +13 -0
- package/dist/compat/stream/pipeline.d.ts +5 -0
- package/dist/compat/stream/pipeline.js +567 -0
- package/dist/compat/stream/process.d.ts +1 -0
- package/dist/compat/stream/process.js +4 -0
- package/dist/compat/stream/promises.d.ts +7 -0
- package/dist/compat/stream/promises.js +60 -0
- package/dist/compat/stream/readable.d.ts +29 -0
- package/dist/compat/stream/readable.js +2267 -0
- package/dist/compat/stream/state.d.ts +8 -0
- package/dist/compat/stream/state.js +63 -0
- package/dist/compat/stream/transform.d.ts +2 -0
- package/dist/compat/stream/transform.js +202 -0
- package/dist/compat/stream/util.d.ts +55 -0
- package/dist/compat/stream/util.js +345 -0
- package/dist/compat/stream/validators.d.ts +2 -0
- package/dist/compat/stream/validators.js +14 -0
- package/dist/compat/stream/writable.d.ts +21 -0
- package/dist/compat/stream/writable.js +1325 -0
- package/dist/compat/stream-consumers/LICENSE-3RD-PARTY.md +5 -0
- package/dist/compat/stream-consumers/LICENSE-APACHE +177 -0
- package/dist/compat/stream-consumers/index.d.ts +14 -0
- package/dist/compat/stream-consumers/index.js +62 -0
- package/dist/compat/stream-consumers/iterable.d.ts +1 -0
- package/dist/compat/stream-consumers/iterable.js +34 -0
- package/dist/compat/stream-duplex/LICENSE-3RD-PARTY.md +13 -0
- package/dist/compat/stream-duplex/LICENSE-APACHE +177 -0
- package/dist/compat/stream-duplex/index.cjs +3 -0
- package/dist/compat/stream-duplex/index.d.cts +2 -0
- package/dist/compat/stream-duplex/index.d.ts +3 -0
- package/dist/compat/stream-duplex/index.js +8 -0
- package/dist/compat/stream-passthrough/LICENSE-3RD-PARTY.md +13 -0
- package/dist/compat/stream-passthrough/LICENSE-APACHE +177 -0
- package/dist/compat/stream-passthrough/index.cjs +3 -0
- package/dist/compat/stream-passthrough/index.d.cts +2 -0
- package/dist/compat/stream-passthrough/index.d.ts +3 -0
- package/dist/compat/stream-passthrough/index.js +8 -0
- package/dist/compat/stream-promises/LICENSE-3RD-PARTY.md +13 -0
- package/dist/compat/stream-promises/LICENSE-APACHE +177 -0
- package/dist/compat/stream-promises/index.d.ts +1 -0
- package/dist/compat/stream-promises/index.js +1 -0
- package/dist/compat/stream-readable/LICENSE-3RD-PARTY.md +13 -0
- package/dist/compat/stream-readable/LICENSE-APACHE +177 -0
- package/dist/compat/stream-readable/index.cjs +3 -0
- package/dist/compat/stream-readable/index.d.cts +2 -0
- package/dist/compat/stream-readable/index.d.ts +3 -0
- package/dist/compat/stream-readable/index.js +8 -0
- package/dist/compat/stream-transform/LICENSE-3RD-PARTY.md +13 -0
- package/dist/compat/stream-transform/LICENSE-APACHE +177 -0
- package/dist/compat/stream-transform/index.cjs +3 -0
- package/dist/compat/stream-transform/index.d.cts +2 -0
- package/dist/compat/stream-transform/index.d.ts +3 -0
- package/dist/compat/stream-transform/index.js +8 -0
- package/dist/compat/stream-web/LICENSE-MIT +22 -0
- package/dist/compat/stream-web/NOTICE.md +3 -0
- package/dist/compat/stream-web/context.d.ts +2 -0
- package/dist/compat/stream-web/context.js +35 -0
- package/dist/compat/stream-web/index.d.ts +80 -0
- package/dist/compat/stream-web/index.js +129 -0
- package/dist/compat/stream-web/interop.d.ts +6 -0
- package/dist/compat/stream-web/interop.js +72 -0
- package/dist/compat/stream-web/ponyfill.d.ts +1 -0
- package/dist/compat/stream-web/ponyfill.js +2093 -0
- package/dist/compat/stream-web/runtime.d.ts +16 -0
- package/dist/compat/stream-web/runtime.js +51 -0
- package/dist/compat/stream-writable/LICENSE-3RD-PARTY.md +13 -0
- package/dist/compat/stream-writable/LICENSE-APACHE +177 -0
- package/dist/compat/stream-writable/index.cjs +3 -0
- package/dist/compat/stream-writable/index.d.cts +2 -0
- package/dist/compat/stream-writable/index.d.ts +3 -0
- package/dist/compat/stream-writable/index.js +8 -0
- package/dist/compat/string-decoder/LICENSE-3RD-PARTY.md +38 -0
- package/dist/compat/string-decoder/LICENSE-APACHE +177 -0
- package/dist/compat/string-decoder/index.d.ts +33 -0
- package/dist/compat/string-decoder/index.js +518 -0
- package/dist/compat/test/LICENSE-3RD-PARTY.md +37 -0
- package/dist/compat/test/LICENSE-APACHE +177 -0
- package/dist/compat/test/index.d.ts +9 -0
- package/dist/compat/test/index.js +11 -0
- package/dist/compat/test/mock.d.ts +103 -0
- package/dist/compat/test/mock.js +397 -0
- package/dist/compat/test/validators.d.ts +2 -0
- package/dist/compat/test/validators.js +14 -0
- package/dist/compat/timers/LICENSE-3RD-PARTY.md +7 -0
- package/dist/compat/timers/LICENSE-APACHE +177 -0
- package/dist/compat/timers/errors.d.ts +28 -0
- package/dist/compat/timers/errors.js +206 -0
- package/dist/compat/timers/host.d.ts +11 -0
- package/dist/compat/timers/host.js +60 -0
- package/dist/compat/timers/index.cjs +3 -0
- package/dist/compat/timers/index.d.cts +23 -0
- package/dist/compat/timers/index.d.ts +36 -0
- package/dist/compat/timers/index.js +20 -0
- package/dist/compat/timers/installation.d.ts +4 -0
- package/dist/compat/timers/installation.js +61 -0
- package/dist/compat/timers/internal-promises.d.ts +19 -0
- package/dist/compat/timers/internal-promises.js +173 -0
- package/dist/compat/timers/promises.cjs +2 -0
- package/dist/compat/timers/promises.d.cts +12 -0
- package/dist/compat/timers/promises.d.ts +14 -0
- package/dist/compat/timers/promises.js +3 -0
- package/dist/compat/timers/timers.d.ts +32 -0
- package/dist/compat/timers/timers.js +147 -0
- package/dist/compat/timers/validation.d.ts +5 -0
- package/dist/compat/timers/validation.js +22 -0
- package/dist/compat/timers/wait.d.ts +4 -0
- package/dist/compat/timers/wait.js +91 -0
- package/dist/compat/tls-common/LICENSE-3RD-PARTY.md +11 -0
- package/dist/compat/tls-common/LICENSE-APACHE +177 -0
- package/dist/compat/tls-common/index.d.ts +14 -0
- package/dist/compat/tls-common/index.js +88 -0
- package/dist/compat/trace-events/LICENSE-3RD-PARTY.md +5 -0
- package/dist/compat/trace-events/LICENSE-APACHE +177 -0
- package/dist/compat/trace-events/index.d.ts +18 -0
- package/dist/compat/trace-events/index.js +88 -0
- package/dist/compat/tty/LICENSE-3RD-PARTY.md +8 -0
- package/dist/compat/tty/LICENSE-APACHE +177 -0
- package/dist/compat/tty/index.d.ts +17 -0
- package/dist/compat/tty/index.js +101 -0
- package/dist/compat/url/LICENSE-3RD-PARTY.md +63 -0
- package/dist/compat/url/LICENSE-ADA +18 -0
- package/dist/compat/url/LICENSE-APACHE +177 -0
- package/dist/compat/url/LICENSE-UNICODE +39 -0
- package/dist/compat/url/LICENSE-WHATWG-URL +21 -0
- package/dist/compat/url/brand.d.ts +4 -0
- package/dist/compat/url/brand.js +10 -0
- package/dist/compat/url/constants.d.ts +27 -0
- package/dist/compat/url/constants.js +28 -0
- package/dist/compat/url/errors.d.ts +44 -0
- package/dist/compat/url/errors.js +248 -0
- package/dist/compat/url/idna-data.d.ts +3958 -0
- package/dist/compat/url/idna-data.js +22 -0
- package/dist/compat/url/idna.d.ts +9 -0
- package/dist/compat/url/idna.js +47 -0
- package/dist/compat/url/index.d.ts +48 -0
- package/dist/compat/url/index.js +39 -0
- package/dist/compat/url/installation.d.ts +4 -0
- package/dist/compat/url/installation.js +61 -0
- package/dist/compat/url/internal-url.d.ts +34 -0
- package/dist/compat/url/internal-url.js +264 -0
- package/dist/compat/url/legacy-url.d.ts +28 -0
- package/dist/compat/url/legacy-url.js +870 -0
- package/dist/compat/url/parser-platform.d.ts +3 -0
- package/dist/compat/url/parser-platform.js +26 -0
- package/dist/compat/url/standard-url.d.ts +2 -0
- package/dist/compat/url/standard-url.js +3189 -0
- package/dist/compat/url/unicode.d.ts +2 -0
- package/dist/compat/url/unicode.js +119 -0
- package/dist/compat/url/validation.d.ts +2 -0
- package/dist/compat/url/validation.js +9 -0
- package/dist/compat/url/web-url.d.ts +27 -0
- package/dist/compat/url/web-url.js +119 -0
- package/dist/compat/util/LICENSE-3RD-PARTY.md +5 -0
- package/dist/compat/util/LICENSE-APACHE +177 -0
- package/dist/compat/util/additional.d.ts +11 -0
- package/dist/compat/util/additional.js +121 -0
- package/dist/compat/util/comparison-types.d.ts +16 -0
- package/dist/compat/util/comparison-types.js +50 -0
- package/dist/compat/util/comparisons.d.ts +1 -0
- package/dist/compat/util/comparisons.js +527 -0
- package/dist/compat/util/core.d.ts +18 -0
- package/dist/compat/util/core.js +265 -0
- package/dist/compat/util/debuglog.d.ts +1 -0
- package/dist/compat/util/debuglog.js +78 -0
- package/dist/compat/util/index.d.ts +35 -0
- package/dist/compat/util/index.js +77 -0
- package/dist/compat/util/inspect-binding.d.ts +13 -0
- package/dist/compat/util/inspect-binding.js +39 -0
- package/dist/compat/util/inspect-types.d.ts +13 -0
- package/dist/compat/util/inspect-types.js +30 -0
- package/dist/compat/util/inspect.d.ts +152 -0
- package/dist/compat/util/inspect.js +2503 -0
- package/dist/compat/util/mime.d.ts +24 -0
- package/dist/compat/util/mime.js +284 -0
- package/dist/compat/util/properties.d.ts +9 -0
- package/dist/compat/util/properties.js +76 -0
- package/dist/compat/v8/LICENSE-3RD-PARTY.md +6 -0
- package/dist/compat/v8/LICENSE-APACHE +177 -0
- package/dist/compat/v8/errors.d.ts +5 -0
- package/dist/compat/v8/errors.js +7 -0
- package/dist/compat/v8/index.d.ts +106 -0
- package/dist/compat/v8/index.js +280 -0
- package/dist/compat/vm/LICENSE-3RD-PARTY.md +39 -0
- package/dist/compat/vm/LICENSE-APACHE +177 -0
- package/dist/compat/vm/errors.d.ts +5 -0
- package/dist/compat/vm/errors.js +7 -0
- package/dist/compat/vm/index.d.ts +47 -0
- package/dist/compat/vm/index.js +231 -0
- package/dist/compat/vm/validation.d.ts +3 -0
- package/dist/compat/vm/validation.js +14 -0
- package/dist/compat/wasi/LICENSE-3RD-PARTY.md +8 -0
- package/dist/compat/wasi/LICENSE-APACHE +177 -0
- package/dist/compat/wasi/errors.d.ts +4 -0
- package/dist/compat/wasi/errors.js +6 -0
- package/dist/compat/wasi/index.d.ts +15 -0
- package/dist/compat/wasi/index.js +44 -0
- package/dist/compat/worker-threads/LICENSE-3RD-PARTY.md +5 -0
- package/dist/compat/worker-threads/LICENSE-APACHE +177 -0
- package/dist/compat/worker-threads/errors.d.ts +4 -0
- package/dist/compat/worker-threads/errors.js +6 -0
- package/dist/compat/worker-threads/index.d.ts +71 -0
- package/dist/compat/worker-threads/index.js +138 -0
- package/dist/compat/worker-threads/message-channel.d.ts +18 -0
- package/dist/compat/worker-threads/message-channel.js +157 -0
- package/dist/configured.d.ts +3 -0
- package/dist/configured.js +4 -0
- package/dist/environment.d.ts +4 -0
- package/dist/environment.js +18 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +107 -0
- package/dist/ios.d.ts +2 -0
- package/dist/ios.js +1 -0
- package/dist/native-entry.d.ts +8 -0
- package/dist/native-entry.js +67 -0
- package/dist/shared/brotli/LICENSE-APACHE +201 -0
- package/dist/shared/brotli/LICENSE-MIT +9 -0
- package/dist/shared/brotli/NOTICE +3 -0
- package/dist/shared/brotli/index.d.ts +2 -0
- package/dist/shared/brotli/index.js +288 -0
- package/dist/shared/contracts/index.d.ts +42 -0
- package/dist/shared/contracts/index.js +88 -0
- package/dist/shared/contracts/testing.d.ts +22 -0
- package/dist/shared/contracts/testing.js +57 -0
- package/dist/shared/globals/index.d.ts +3 -0
- package/dist/shared/globals/index.js +87 -0
- package/dist/shared/globals/inject.d.ts +2 -0
- package/dist/shared/globals/inject.js +3 -0
- package/dist/shared/globals/install.d.ts +1 -0
- package/dist/shared/globals/install.js +15 -0
- package/dist/shared/globals/node-install.d.ts +1 -0
- package/dist/shared/globals/node-install.js +4 -0
- package/dist/shared/globals/platform.d.ts +104 -0
- package/dist/shared/globals/platform.js +37 -0
- package/dist/shared/globals/runtime.d.ts +6 -0
- package/dist/shared/globals/runtime.js +8 -0
- package/dist/shared/globals/symbols.d.ts +4 -0
- package/dist/shared/globals/symbols.js +35 -0
- package/dist/shared/globals/web.d.ts +4 -0
- package/dist/shared/globals/web.js +108 -0
- package/dist/shared/http-wire/LICENSE.llhttp +22 -0
- package/dist/shared/http-wire/LICENSE.undici +21 -0
- package/dist/shared/http-wire/NOTICE.md +14 -0
- package/dist/shared/http-wire/index.d.ts +27 -0
- package/dist/shared/http-wire/index.js +132 -0
- package/dist/shared/http-wire/wasm.d.ts +2 -0
- package/dist/shared/http-wire/wasm.js +2 -0
- package/dist/tooling/async.d.ts +7 -0
- package/dist/tooling/async.js +99 -0
- package/dist/tooling/build-isolation.d.ts +4 -0
- package/dist/tooling/build-isolation.js +34 -0
- package/dist/tooling/documents.d.ts +7 -0
- package/dist/tooling/documents.js +26 -0
- package/dist/tooling/esbuild.d.ts +15 -0
- package/dist/tooling/esbuild.js +193 -0
- package/dist/tooling/files.d.ts +2 -0
- package/dist/tooling/files.js +18 -0
- package/dist/tooling/opennext/build.d.ts +1 -0
- package/dist/tooling/opennext/build.js +121 -0
- package/dist/tooling/opennext/index.d.ts +3 -0
- package/dist/tooling/opennext/index.js +213 -0
- package/dist/tooling/opennext/plan.d.ts +9 -0
- package/dist/tooling/opennext/plan.js +36 -0
- package/dist/tooling/opennext/safety.d.ts +4 -0
- package/dist/tooling/opennext/safety.js +36 -0
- package/dist/tooling/route-permissions.d.ts +3 -0
- package/dist/tooling/route-permissions.js +15 -0
- package/dist/tooling/server-modules.d.ts +30 -0
- package/dist/tooling/server-modules.js +98 -0
- package/dist/tooling/server-only-html.d.ts +1 -0
- package/dist/tooling/server-only-html.js +66 -0
- package/dist/tooling/server-only.d.ts +6 -0
- package/dist/tooling/server-only.js +53 -0
- package/dist/tooling/server.d.ts +25 -0
- package/dist/tooling/server.js +981 -0
- package/dist/tooling/shared.d.ts +13 -0
- package/dist/tooling/shared.js +130 -0
- package/dist/tooling/vite.d.ts +18 -0
- package/dist/tooling/vite.js +448 -0
- package/dist/tooling/void/index.d.ts +3 -0
- package/dist/tooling/void/index.js +205 -0
- package/dist/tooling/void/plan.d.ts +17 -0
- package/dist/tooling/void/plan.js +288 -0
- package/native/android/build.gradle +68 -0
- package/native/android/consumer-rules.pro +2 -0
- package/native/android/src/main/AndroidManifest.xml +6 -0
- package/native/android/src/main/java/jp/rdlabo/workerscapacitor/WorkerSockets.java +202 -0
- package/native/android/src/main/java/jp/rdlabo/workerscapacitor/WorkersCapacitorPlugin.java +256 -0
- package/native/android/src/main/java/jp/rdlabo/workerscapacitor/WorkersNative.java +22 -0
- package/native/android/src/main/java/jp/rdlabo/workerscapacitor/WorkersNativeActivity.java +178 -0
- package/native/android/src/main/java/jp/rdlabo/workerscapacitor/WorkersNativeBridge.java +45 -0
- package/native/ios/DocumentBridge.swift +330 -0
- package/native/ios/NetworkBridge.swift +51 -0
- package/native/ios/SocketBridge.swift +180 -0
- package/native/ios/WorkersCapacitorPlugin.swift +152 -0
- package/native/ios-host/WorkersView.swift +194 -0
- package/package.json +154 -4
|
@@ -0,0 +1,1356 @@
|
|
|
1
|
+
import { asyncDispose } from "../../shared/globals/symbols.js";
|
|
2
|
+
// Copyright (c) 2017-2026 Cloudflare, Inc.
|
|
3
|
+
// Licensed under the Apache 2.0 license found in the LICENSE file or at:
|
|
4
|
+
// https://opensource.org/licenses/Apache-2.0
|
|
5
|
+
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
|
6
|
+
// Adapted from workerd v1.20261012.1 node:http compatibility sources.
|
|
7
|
+
import { Readable, Writable } from "node:stream";
|
|
8
|
+
import { EventEmitter } from "node:events";
|
|
9
|
+
import { Buffer } from "node:buffer";
|
|
10
|
+
import { ephemeral, hasHandler, kSetIncomingBody, kSetIncomingFetchResponse, kSetIncomingSocket, release, setHandler, } from "./registry.js";
|
|
11
|
+
export const METHODS = [
|
|
12
|
+
"ACL",
|
|
13
|
+
"BIND",
|
|
14
|
+
"CHECKOUT",
|
|
15
|
+
"CONNECT",
|
|
16
|
+
"COPY",
|
|
17
|
+
"DELETE",
|
|
18
|
+
"GET",
|
|
19
|
+
"HEAD",
|
|
20
|
+
"LINK",
|
|
21
|
+
"LOCK",
|
|
22
|
+
"M-SEARCH",
|
|
23
|
+
"MERGE",
|
|
24
|
+
"MKACTIVITY",
|
|
25
|
+
"MKCALENDAR",
|
|
26
|
+
"MKCOL",
|
|
27
|
+
"MOVE",
|
|
28
|
+
"NOTIFY",
|
|
29
|
+
"OPTIONS",
|
|
30
|
+
"PATCH",
|
|
31
|
+
"POST",
|
|
32
|
+
"PROPFIND",
|
|
33
|
+
"PROPPATCH",
|
|
34
|
+
"PURGE",
|
|
35
|
+
"PUT",
|
|
36
|
+
"QUERY",
|
|
37
|
+
"REBIND",
|
|
38
|
+
"REPORT",
|
|
39
|
+
"SEARCH",
|
|
40
|
+
"SOURCE",
|
|
41
|
+
"SUBSCRIBE",
|
|
42
|
+
"TRACE",
|
|
43
|
+
"UNBIND",
|
|
44
|
+
"UNLINK",
|
|
45
|
+
"UNLOCK",
|
|
46
|
+
"UNSUBSCRIBE",
|
|
47
|
+
];
|
|
48
|
+
export const STATUS_CODES = {
|
|
49
|
+
100: "Continue",
|
|
50
|
+
101: "Switching Protocols",
|
|
51
|
+
102: "Processing",
|
|
52
|
+
103: "Early Hints",
|
|
53
|
+
200: "OK",
|
|
54
|
+
201: "Created",
|
|
55
|
+
202: "Accepted",
|
|
56
|
+
203: "Non-Authoritative Information",
|
|
57
|
+
204: "No Content",
|
|
58
|
+
205: "Reset Content",
|
|
59
|
+
206: "Partial Content",
|
|
60
|
+
207: "Multi-Status",
|
|
61
|
+
208: "Already Reported",
|
|
62
|
+
226: "IM Used",
|
|
63
|
+
300: "Multiple Choices",
|
|
64
|
+
301: "Moved Permanently",
|
|
65
|
+
302: "Found",
|
|
66
|
+
303: "See Other",
|
|
67
|
+
304: "Not Modified",
|
|
68
|
+
305: "Use Proxy",
|
|
69
|
+
307: "Temporary Redirect",
|
|
70
|
+
308: "Permanent Redirect",
|
|
71
|
+
400: "Bad Request",
|
|
72
|
+
401: "Unauthorized",
|
|
73
|
+
402: "Payment Required",
|
|
74
|
+
403: "Forbidden",
|
|
75
|
+
404: "Not Found",
|
|
76
|
+
405: "Method Not Allowed",
|
|
77
|
+
406: "Not Acceptable",
|
|
78
|
+
407: "Proxy Authentication Required",
|
|
79
|
+
408: "Request Timeout",
|
|
80
|
+
409: "Conflict",
|
|
81
|
+
410: "Gone",
|
|
82
|
+
411: "Length Required",
|
|
83
|
+
412: "Precondition Failed",
|
|
84
|
+
413: "Payload Too Large",
|
|
85
|
+
414: "URI Too Long",
|
|
86
|
+
415: "Unsupported Media Type",
|
|
87
|
+
416: "Range Not Satisfiable",
|
|
88
|
+
417: "Expectation Failed",
|
|
89
|
+
418: "I'm a Teapot",
|
|
90
|
+
421: "Misdirected Request",
|
|
91
|
+
422: "Unprocessable Entity",
|
|
92
|
+
423: "Locked",
|
|
93
|
+
424: "Failed Dependency",
|
|
94
|
+
425: "Too Early",
|
|
95
|
+
426: "Upgrade Required",
|
|
96
|
+
428: "Precondition Required",
|
|
97
|
+
429: "Too Many Requests",
|
|
98
|
+
431: "Request Header Fields Too Large",
|
|
99
|
+
451: "Unavailable For Legal Reasons",
|
|
100
|
+
500: "Internal Server Error",
|
|
101
|
+
501: "Not Implemented",
|
|
102
|
+
502: "Bad Gateway",
|
|
103
|
+
503: "Service Unavailable",
|
|
104
|
+
504: "Gateway Timeout",
|
|
105
|
+
505: "HTTP Version Not Supported",
|
|
106
|
+
506: "Variant Also Negotiates",
|
|
107
|
+
507: "Insufficient Storage",
|
|
108
|
+
508: "Loop Detected",
|
|
109
|
+
509: "Bandwidth Limit Exceeded",
|
|
110
|
+
510: "Not Extended",
|
|
111
|
+
511: "Network Authentication Required",
|
|
112
|
+
};
|
|
113
|
+
export const maxHeaderSize = 16384;
|
|
114
|
+
function coded(error, code) {
|
|
115
|
+
return Object.assign(error, { code });
|
|
116
|
+
}
|
|
117
|
+
function validateType(value, type, name) {
|
|
118
|
+
if (typeof value !== type)
|
|
119
|
+
throw coded(new TypeError(`${name} must be of type ${type}`), "ERR_INVALID_ARG_TYPE");
|
|
120
|
+
}
|
|
121
|
+
function validateInteger(value, name, minimum = Number.MIN_SAFE_INTEGER) {
|
|
122
|
+
validateType(value, "number", name);
|
|
123
|
+
if (!Number.isSafeInteger(value) || value < minimum)
|
|
124
|
+
throw coded(new RangeError(`${name} is out of range`), "ERR_OUT_OF_RANGE");
|
|
125
|
+
}
|
|
126
|
+
function unsupportedOption(name) {
|
|
127
|
+
throw coded(new Error(`The ${name} option is not implemented`), "ERR_OPTION_NOT_IMPLEMENTED");
|
|
128
|
+
}
|
|
129
|
+
function notImplemented(name) {
|
|
130
|
+
return coded(new Error(`The ${name} method is not implemented`), "ERR_METHOD_NOT_IMPLEMENTED");
|
|
131
|
+
}
|
|
132
|
+
function validateString(value, name) {
|
|
133
|
+
if (typeof value !== "string")
|
|
134
|
+
throw coded(new TypeError(`The "${name}" argument must be of type string.`), "ERR_INVALID_ARG_TYPE");
|
|
135
|
+
}
|
|
136
|
+
function validateBoolean(value, name) {
|
|
137
|
+
if (typeof value !== "boolean")
|
|
138
|
+
throw coded(new TypeError(`The "${name}" argument must be of type boolean.`), "ERR_INVALID_ARG_TYPE");
|
|
139
|
+
}
|
|
140
|
+
function validateNumber(value, name) {
|
|
141
|
+
if (typeof value !== "number")
|
|
142
|
+
throw coded(new TypeError(`The "${name}" argument must be of type number.`), "ERR_INVALID_ARG_TYPE");
|
|
143
|
+
}
|
|
144
|
+
export function validateHeaderName(name, label = "Header name") {
|
|
145
|
+
if (typeof name !== "string" || !/^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/.test(name))
|
|
146
|
+
throw coded(new TypeError(`${label} must be a valid HTTP token ["${String(name)}"]`), "ERR_INVALID_HTTP_TOKEN");
|
|
147
|
+
}
|
|
148
|
+
export function validateHeaderValue(name, value) {
|
|
149
|
+
if (value === undefined)
|
|
150
|
+
throw coded(new TypeError(`Invalid value "undefined" for header "${name}"`), "ERR_HTTP_INVALID_HEADER_VALUE");
|
|
151
|
+
for (const item of Array.isArray(value) ? value : [value])
|
|
152
|
+
if (/[^\t\x20-\x7e\x80-\xff]/.test(String(item)))
|
|
153
|
+
throw coded(new TypeError(`Invalid character in header content ["${name}"]`), "ERR_INVALID_CHAR");
|
|
154
|
+
}
|
|
155
|
+
const kHeaders = Symbol("headers");
|
|
156
|
+
export class OutgoingMessage extends Writable {
|
|
157
|
+
[kHeaders] = null;
|
|
158
|
+
strictContentLength = false;
|
|
159
|
+
bytesWritten = 0;
|
|
160
|
+
endingChunk = false;
|
|
161
|
+
chunkedEncoding = false;
|
|
162
|
+
sendDate = false;
|
|
163
|
+
shouldKeepAlive = true;
|
|
164
|
+
useChunkedEncodingByDefault = true;
|
|
165
|
+
maxRequestsOnConnectionReached = false;
|
|
166
|
+
outputData = [];
|
|
167
|
+
outputSize = 0;
|
|
168
|
+
writtenHeaderBytes = 0;
|
|
169
|
+
finished = false;
|
|
170
|
+
_closed = false;
|
|
171
|
+
_headerSent = false;
|
|
172
|
+
_header = null;
|
|
173
|
+
_contentLength = null;
|
|
174
|
+
_hasBody = true;
|
|
175
|
+
_removedContLen = false;
|
|
176
|
+
_removedConnection = false;
|
|
177
|
+
_removedTE = false;
|
|
178
|
+
_last = false;
|
|
179
|
+
_defaultKeepAlive = true;
|
|
180
|
+
_maxRequestsPerSocket;
|
|
181
|
+
_keepAliveTimeout = 0;
|
|
182
|
+
_onPendingData = () => { };
|
|
183
|
+
constructor(_req, options = {}) {
|
|
184
|
+
super({ autoDestroy: false, highWaterMark: options.highWaterMark });
|
|
185
|
+
}
|
|
186
|
+
get headersSent() {
|
|
187
|
+
return this._header !== null || this._headerSent;
|
|
188
|
+
}
|
|
189
|
+
setHeader(name, value) {
|
|
190
|
+
if (this.headersSent)
|
|
191
|
+
throw coded(new Error("Cannot set headers after they are sent to the client"), "ERR_HTTP_HEADERS_SENT");
|
|
192
|
+
validateHeaderName(name);
|
|
193
|
+
validateHeaderValue(name, value);
|
|
194
|
+
this[kHeaders] ??= Object.create(null);
|
|
195
|
+
this[kHeaders][name.toLowerCase()] = [
|
|
196
|
+
name,
|
|
197
|
+
value,
|
|
198
|
+
];
|
|
199
|
+
return this;
|
|
200
|
+
}
|
|
201
|
+
setHeaders(headers) {
|
|
202
|
+
if (this.headersSent)
|
|
203
|
+
throw coded(new Error("Cannot set headers after they are sent"), "ERR_HTTP_HEADERS_SENT");
|
|
204
|
+
if (!headers ||
|
|
205
|
+
Array.isArray(headers) ||
|
|
206
|
+
typeof headers !== "object" ||
|
|
207
|
+
typeof headers.keys !== "function" ||
|
|
208
|
+
typeof headers.get !== "function")
|
|
209
|
+
throw coded(new TypeError("headers must be Headers or Map"), "ERR_INVALID_ARG_TYPE");
|
|
210
|
+
const cookies = [];
|
|
211
|
+
for (const [name, value] of headers) {
|
|
212
|
+
if (name === "set-cookie")
|
|
213
|
+
cookies.push(...(Array.isArray(value) ? value : [value]));
|
|
214
|
+
else
|
|
215
|
+
this.setHeader(name, value);
|
|
216
|
+
}
|
|
217
|
+
if (cookies.length)
|
|
218
|
+
this.setHeader("set-cookie", cookies);
|
|
219
|
+
return this;
|
|
220
|
+
}
|
|
221
|
+
appendHeader(name, value) {
|
|
222
|
+
validateHeaderName(name);
|
|
223
|
+
validateHeaderValue(name, value);
|
|
224
|
+
const old = this.getHeader(name);
|
|
225
|
+
if (old === undefined)
|
|
226
|
+
return this.setHeader(name, value);
|
|
227
|
+
return this.setHeader(name, [
|
|
228
|
+
...(Array.isArray(old) ? old : [String(old)]),
|
|
229
|
+
...(Array.isArray(value) ? value : [String(value)]),
|
|
230
|
+
]);
|
|
231
|
+
}
|
|
232
|
+
getHeader(name) {
|
|
233
|
+
validateString(name, "name");
|
|
234
|
+
return this[kHeaders]?.[name.toLowerCase()]?.[1];
|
|
235
|
+
}
|
|
236
|
+
getHeaders() {
|
|
237
|
+
const result = Object.create(null);
|
|
238
|
+
for (const [key, entry] of Object.entries(this[kHeaders] ?? {}))
|
|
239
|
+
result[key] = entry[1];
|
|
240
|
+
return result;
|
|
241
|
+
}
|
|
242
|
+
getHeaderNames() {
|
|
243
|
+
return Object.keys(this[kHeaders] ?? {});
|
|
244
|
+
}
|
|
245
|
+
getRawHeaderNames() {
|
|
246
|
+
return Object.values(this[kHeaders] ?? {}).map(([name]) => name);
|
|
247
|
+
}
|
|
248
|
+
hasHeader(name) {
|
|
249
|
+
validateString(name, "name");
|
|
250
|
+
return this[kHeaders]?.[name.toLowerCase()] !== undefined;
|
|
251
|
+
}
|
|
252
|
+
removeHeader(name) {
|
|
253
|
+
validateString(name, "name");
|
|
254
|
+
if (this.headersSent)
|
|
255
|
+
throw coded(new Error("Cannot remove headers after they are sent to the client"), "ERR_HTTP_HEADERS_SENT");
|
|
256
|
+
if (this[kHeaders])
|
|
257
|
+
delete this[kHeaders][name.toLowerCase()];
|
|
258
|
+
}
|
|
259
|
+
cork() {
|
|
260
|
+
super.cork();
|
|
261
|
+
}
|
|
262
|
+
uncork() {
|
|
263
|
+
super.uncork();
|
|
264
|
+
}
|
|
265
|
+
#checkContentLength(chunk, encoding, final) {
|
|
266
|
+
if (!this.strictContentLength || this.finished || this.destroyed)
|
|
267
|
+
return;
|
|
268
|
+
const length = typeof chunk === "string"
|
|
269
|
+
? Buffer.byteLength(chunk, typeof encoding === "string"
|
|
270
|
+
? encoding
|
|
271
|
+
: undefined)
|
|
272
|
+
: chunk instanceof Uint8Array
|
|
273
|
+
? chunk.byteLength
|
|
274
|
+
: 0;
|
|
275
|
+
const total = this.bytesWritten + length;
|
|
276
|
+
const expected = this._contentLength ??
|
|
277
|
+
(final && this.hasHeader("content-length")
|
|
278
|
+
? Number(this.getHeader("content-length"))
|
|
279
|
+
: null);
|
|
280
|
+
if (expected != null &&
|
|
281
|
+
this._hasBody &&
|
|
282
|
+
!this._removedContLen &&
|
|
283
|
+
!this.chunkedEncoding &&
|
|
284
|
+
!this.hasHeader("transfer-encoding") &&
|
|
285
|
+
(final ? total !== expected : total > expected))
|
|
286
|
+
throw coded(new Error(`Response body's content-length of ${total} byte(s) does not match the content-length of ${expected} byte(s) set in header`), "ERR_HTTP_CONTENT_LENGTH_MISMATCH");
|
|
287
|
+
this.bytesWritten = total;
|
|
288
|
+
}
|
|
289
|
+
write(chunk, encoding, callback) {
|
|
290
|
+
if (chunk === null)
|
|
291
|
+
throw coded(new TypeError("May not write null values to stream"), "ERR_STREAM_NULL_VALUES");
|
|
292
|
+
if (typeof chunk !== "string" && !(chunk instanceof Uint8Array))
|
|
293
|
+
throw coded(new TypeError("chunk must be a string, Buffer or Uint8Array"), "ERR_INVALID_ARG_TYPE");
|
|
294
|
+
if (!this.endingChunk)
|
|
295
|
+
this.#checkContentLength(chunk, encoding, false);
|
|
296
|
+
if (!this._header && !this.finished && !this.destroyed)
|
|
297
|
+
this._implicitHeader();
|
|
298
|
+
return super.write(chunk, encoding, callback);
|
|
299
|
+
}
|
|
300
|
+
destroy(error) {
|
|
301
|
+
super.destroy(error);
|
|
302
|
+
return this;
|
|
303
|
+
}
|
|
304
|
+
flushHeaders() {
|
|
305
|
+
if (!this._header)
|
|
306
|
+
this._implicitHeader();
|
|
307
|
+
this._headerSent = true;
|
|
308
|
+
}
|
|
309
|
+
_finish() { }
|
|
310
|
+
_flush() { }
|
|
311
|
+
_flushOutput() {
|
|
312
|
+
return undefined;
|
|
313
|
+
}
|
|
314
|
+
_storeHeader(firstLine, headers) {
|
|
315
|
+
if (headers)
|
|
316
|
+
for (const [name, value] of Object.entries(headers))
|
|
317
|
+
if (value !== undefined)
|
|
318
|
+
this.setHeader(name, value);
|
|
319
|
+
this._header = firstLine;
|
|
320
|
+
}
|
|
321
|
+
_send(data, encoding, callback) {
|
|
322
|
+
return this._writeRaw(data, encoding, callback);
|
|
323
|
+
}
|
|
324
|
+
_writeRaw(data, encoding, callback) {
|
|
325
|
+
return this.write(data, encoding ?? undefined, callback);
|
|
326
|
+
}
|
|
327
|
+
_implicitHeader() {
|
|
328
|
+
throw notImplemented("_implicitHeader()");
|
|
329
|
+
}
|
|
330
|
+
_renderHeaders() {
|
|
331
|
+
if (this.headersSent)
|
|
332
|
+
throw coded(new Error("Cannot render headers after they are sent"), "ERR_HTTP_HEADERS_SENT");
|
|
333
|
+
return Object.fromEntries(Object.values(this[kHeaders] ?? {}).map(([name, value]) => [name, value]));
|
|
334
|
+
}
|
|
335
|
+
pipe(destination) {
|
|
336
|
+
this.emit("error", coded(new Error("Cannot pipe, not readable"), "ERR_STREAM_CANNOT_PIPE"));
|
|
337
|
+
return destination;
|
|
338
|
+
}
|
|
339
|
+
end(chunk, encoding, callback) {
|
|
340
|
+
if (!this._header &&
|
|
341
|
+
this.strictContentLength &&
|
|
342
|
+
!this.finished &&
|
|
343
|
+
!this.destroyed)
|
|
344
|
+
this._implicitHeader();
|
|
345
|
+
this.#checkContentLength(chunk, encoding, true);
|
|
346
|
+
this.endingChunk = true;
|
|
347
|
+
try {
|
|
348
|
+
super.end(chunk, encoding, callback);
|
|
349
|
+
}
|
|
350
|
+
finally {
|
|
351
|
+
this.endingChunk = false;
|
|
352
|
+
}
|
|
353
|
+
this.finished = true;
|
|
354
|
+
return this;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
Object.defineProperties(OutgoingMessage.prototype, {
|
|
358
|
+
closed: {
|
|
359
|
+
configurable: true,
|
|
360
|
+
get() {
|
|
361
|
+
return this._closed;
|
|
362
|
+
},
|
|
363
|
+
},
|
|
364
|
+
errored: {
|
|
365
|
+
configurable: true,
|
|
366
|
+
get() {
|
|
367
|
+
return null;
|
|
368
|
+
},
|
|
369
|
+
},
|
|
370
|
+
writableCorked: {
|
|
371
|
+
configurable: true,
|
|
372
|
+
get() {
|
|
373
|
+
return this._writableState.corked;
|
|
374
|
+
},
|
|
375
|
+
},
|
|
376
|
+
writableEnded: {
|
|
377
|
+
configurable: true,
|
|
378
|
+
get() {
|
|
379
|
+
return this.finished;
|
|
380
|
+
},
|
|
381
|
+
},
|
|
382
|
+
writableHighWaterMark: {
|
|
383
|
+
configurable: true,
|
|
384
|
+
get() {
|
|
385
|
+
return this._writableState.highWaterMark;
|
|
386
|
+
},
|
|
387
|
+
},
|
|
388
|
+
writableLength: {
|
|
389
|
+
configurable: true,
|
|
390
|
+
get() {
|
|
391
|
+
return this._writableState.length;
|
|
392
|
+
},
|
|
393
|
+
},
|
|
394
|
+
writableNeedDrain: {
|
|
395
|
+
configurable: true,
|
|
396
|
+
get() {
|
|
397
|
+
return this._writableState.needDrain;
|
|
398
|
+
},
|
|
399
|
+
},
|
|
400
|
+
writableObjectMode: {
|
|
401
|
+
configurable: true,
|
|
402
|
+
get() {
|
|
403
|
+
return false;
|
|
404
|
+
},
|
|
405
|
+
},
|
|
406
|
+
});
|
|
407
|
+
export class IncomingMessage extends Readable {
|
|
408
|
+
url = "";
|
|
409
|
+
method = null;
|
|
410
|
+
statusCode = null;
|
|
411
|
+
statusMessage = null;
|
|
412
|
+
httpVersion = "1.1";
|
|
413
|
+
httpVersionMajor = 1;
|
|
414
|
+
httpVersionMinor = 1;
|
|
415
|
+
complete = false;
|
|
416
|
+
rawHeaders = [];
|
|
417
|
+
joinDuplicateHeaders = false;
|
|
418
|
+
cloudflare = {};
|
|
419
|
+
aborted = false;
|
|
420
|
+
_dumped = false;
|
|
421
|
+
_consuming = false;
|
|
422
|
+
_paused = false;
|
|
423
|
+
headerValues = null;
|
|
424
|
+
distinctValues = null;
|
|
425
|
+
reader;
|
|
426
|
+
bodyStream = null;
|
|
427
|
+
reading = false;
|
|
428
|
+
idleTimer;
|
|
429
|
+
socketValue = Object.assign(new EventEmitter(), {
|
|
430
|
+
encrypted: false,
|
|
431
|
+
localAddress: "127.0.0.1",
|
|
432
|
+
localPort: 0,
|
|
433
|
+
remoteAddress: "127.0.0.1",
|
|
434
|
+
remoteFamily: "IPv4",
|
|
435
|
+
remotePort: 0,
|
|
436
|
+
readable: true,
|
|
437
|
+
writable: true,
|
|
438
|
+
});
|
|
439
|
+
[kSetIncomingBody](body) {
|
|
440
|
+
this.bodyStream = body;
|
|
441
|
+
}
|
|
442
|
+
[kSetIncomingFetchResponse](response, idleTimer) {
|
|
443
|
+
this.idleTimer = idleTimer;
|
|
444
|
+
this.url = response.url;
|
|
445
|
+
this.statusCode = response.status;
|
|
446
|
+
this.statusMessage = response.statusText;
|
|
447
|
+
// workerd's fetch-backed IncomingMessage exposes joined get() values,
|
|
448
|
+
// including Set-Cookie, rather than the iterator's repeated entries.
|
|
449
|
+
this.headerValues = {};
|
|
450
|
+
this.distinctValues = {};
|
|
451
|
+
for (const key of response.headers.keys()) {
|
|
452
|
+
const value = response.headers.get(key);
|
|
453
|
+
this.headerValues[key] = value;
|
|
454
|
+
this.distinctValues[key] = [value];
|
|
455
|
+
}
|
|
456
|
+
this[kSetIncomingBody](response.body);
|
|
457
|
+
}
|
|
458
|
+
_addHeaderLine(field, value, dest) {
|
|
459
|
+
const key = field.toLowerCase();
|
|
460
|
+
if (key === "set-cookie")
|
|
461
|
+
dest[key]?.push(value) ?? (dest[key] = [value]);
|
|
462
|
+
else if (key === "cookie" && typeof dest[key] === "string")
|
|
463
|
+
dest[key] += `; ${value}`;
|
|
464
|
+
else if (dest[key] === undefined)
|
|
465
|
+
dest[key] = value;
|
|
466
|
+
else if (this.joinDuplicateHeaders ||
|
|
467
|
+
![
|
|
468
|
+
"age",
|
|
469
|
+
"authorization",
|
|
470
|
+
"content-length",
|
|
471
|
+
"content-type",
|
|
472
|
+
"etag",
|
|
473
|
+
"expires",
|
|
474
|
+
"from",
|
|
475
|
+
"host",
|
|
476
|
+
"if-modified-since",
|
|
477
|
+
"if-unmodified-since",
|
|
478
|
+
"last-modified",
|
|
479
|
+
"location",
|
|
480
|
+
"max-forwards",
|
|
481
|
+
"proxy-authorization",
|
|
482
|
+
"referer",
|
|
483
|
+
"retry-after",
|
|
484
|
+
"server",
|
|
485
|
+
"user-agent",
|
|
486
|
+
].includes(key))
|
|
487
|
+
dest[key] += `, ${value}`;
|
|
488
|
+
}
|
|
489
|
+
_addHeaderLineDistinct(field, value, dest) {
|
|
490
|
+
(dest[field.toLowerCase()] ??= []).push(value);
|
|
491
|
+
}
|
|
492
|
+
_addHeaderLines(headers, n) {
|
|
493
|
+
this.rawHeaders = headers?.slice(0, n) ?? [];
|
|
494
|
+
this.headerValues = null;
|
|
495
|
+
this.distinctValues = null;
|
|
496
|
+
}
|
|
497
|
+
get headers() {
|
|
498
|
+
if (!this.headerValues) {
|
|
499
|
+
this.headerValues = {};
|
|
500
|
+
for (let i = 0; i < this.rawHeaders.length; i += 2)
|
|
501
|
+
this._addHeaderLine(this.rawHeaders[i], this.rawHeaders[i + 1], this.headerValues);
|
|
502
|
+
}
|
|
503
|
+
return this.headerValues;
|
|
504
|
+
}
|
|
505
|
+
set headers(value) {
|
|
506
|
+
this.headerValues = value;
|
|
507
|
+
}
|
|
508
|
+
get headersDistinct() {
|
|
509
|
+
if (!this.distinctValues) {
|
|
510
|
+
this.distinctValues = {};
|
|
511
|
+
for (let i = 0; i < this.rawHeaders.length; i += 2)
|
|
512
|
+
(this.distinctValues[this.rawHeaders[i].toLowerCase()] ??= []).push(this.rawHeaders[i + 1]);
|
|
513
|
+
}
|
|
514
|
+
return this.distinctValues;
|
|
515
|
+
}
|
|
516
|
+
set headersDistinct(value) {
|
|
517
|
+
this.distinctValues = value;
|
|
518
|
+
}
|
|
519
|
+
get trailers() {
|
|
520
|
+
return {};
|
|
521
|
+
}
|
|
522
|
+
set trailers(_value) { }
|
|
523
|
+
get trailersDistinct() {
|
|
524
|
+
return {};
|
|
525
|
+
}
|
|
526
|
+
set trailersDistinct(_value) { }
|
|
527
|
+
get socket() {
|
|
528
|
+
return this.socketValue;
|
|
529
|
+
}
|
|
530
|
+
get connection() {
|
|
531
|
+
return this.socket;
|
|
532
|
+
}
|
|
533
|
+
set connection(value) {
|
|
534
|
+
this.socketValue = value;
|
|
535
|
+
}
|
|
536
|
+
[kSetIncomingSocket](values) {
|
|
537
|
+
Object.assign(this.socketValue, values);
|
|
538
|
+
}
|
|
539
|
+
_dump() {
|
|
540
|
+
if (!this._dumped) {
|
|
541
|
+
this._dumped = true;
|
|
542
|
+
this.removeAllListeners("data");
|
|
543
|
+
this.resume();
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
setTimeout(msecs, callback) {
|
|
547
|
+
if (!Number.isFinite(msecs) || msecs < 0)
|
|
548
|
+
throw coded(new RangeError('The value of "msecs" is out of range.'), "ERR_OUT_OF_RANGE");
|
|
549
|
+
if (callback)
|
|
550
|
+
this.on("timeout", callback);
|
|
551
|
+
this.idleTimer?.setTimeout(msecs);
|
|
552
|
+
return this;
|
|
553
|
+
}
|
|
554
|
+
_read() {
|
|
555
|
+
if (this.reading)
|
|
556
|
+
return;
|
|
557
|
+
if (!this.bodyStream) {
|
|
558
|
+
this.complete = true;
|
|
559
|
+
this.push(null);
|
|
560
|
+
return;
|
|
561
|
+
}
|
|
562
|
+
this.reader ??= this.bodyStream.getReader();
|
|
563
|
+
this.reading = true;
|
|
564
|
+
void this.reader.read().then(({ value, done }) => {
|
|
565
|
+
this.reading = false;
|
|
566
|
+
if (this.destroyed)
|
|
567
|
+
return;
|
|
568
|
+
if (done) {
|
|
569
|
+
this.complete = true;
|
|
570
|
+
this.reader?.releaseLock();
|
|
571
|
+
this.reader = undefined;
|
|
572
|
+
this.push(null);
|
|
573
|
+
}
|
|
574
|
+
else {
|
|
575
|
+
this.idleTimer?.touch();
|
|
576
|
+
if (this.push(Buffer.from(value)))
|
|
577
|
+
this._read();
|
|
578
|
+
}
|
|
579
|
+
}, (error) => {
|
|
580
|
+
this.reading = false;
|
|
581
|
+
this.destroy(error);
|
|
582
|
+
});
|
|
583
|
+
}
|
|
584
|
+
_destroy(error, callback) {
|
|
585
|
+
if (!this.complete) {
|
|
586
|
+
this.aborted = true;
|
|
587
|
+
this.emit("aborted");
|
|
588
|
+
}
|
|
589
|
+
const reader = this.reader;
|
|
590
|
+
this.reader = undefined;
|
|
591
|
+
const cancellation = reader
|
|
592
|
+
? reader.cancel(error ?? undefined).finally(() => reader.releaseLock())
|
|
593
|
+
: !this.complete && this.bodyStream && !this.bodyStream.locked
|
|
594
|
+
? this.bodyStream.cancel(error ?? undefined)
|
|
595
|
+
: Promise.resolve();
|
|
596
|
+
void cancellation.then(() => callback(this.listenerCount("error") ? error : null), () => callback(this.listenerCount("error") ? error : null));
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
export class ServerResponse extends OutgoingMessage {
|
|
600
|
+
statusCode = 200;
|
|
601
|
+
statusMessage = "unknown";
|
|
602
|
+
req;
|
|
603
|
+
socket;
|
|
604
|
+
body;
|
|
605
|
+
controller;
|
|
606
|
+
pending;
|
|
607
|
+
bodyClosed = false;
|
|
608
|
+
constructor(req, options = {}) {
|
|
609
|
+
super(req, options);
|
|
610
|
+
this.req = req;
|
|
611
|
+
this.socket = req.socket;
|
|
612
|
+
this.body = new ReadableStream({
|
|
613
|
+
start: (controller) => {
|
|
614
|
+
this.controller = controller;
|
|
615
|
+
},
|
|
616
|
+
pull: () => {
|
|
617
|
+
const pending = this.pending;
|
|
618
|
+
this.pending = undefined;
|
|
619
|
+
pending?.();
|
|
620
|
+
},
|
|
621
|
+
cancel: (reason) => {
|
|
622
|
+
this.bodyClosed = true;
|
|
623
|
+
this.destroy(reason instanceof Error ? reason : undefined);
|
|
624
|
+
},
|
|
625
|
+
});
|
|
626
|
+
}
|
|
627
|
+
_implicitHeader() {
|
|
628
|
+
this.writeHead(this.statusCode);
|
|
629
|
+
}
|
|
630
|
+
writeHead(status, reason, headers) {
|
|
631
|
+
if (this.headersSent)
|
|
632
|
+
throw coded(new Error("Cannot write headers after they are sent to the client"), "ERR_HTTP_HEADERS_SENT");
|
|
633
|
+
const original = status;
|
|
634
|
+
status |= 0;
|
|
635
|
+
if (status < 200 || status > 999)
|
|
636
|
+
throw coded(new RangeError(`Invalid status code: ${original}`), "ERR_HTTP_INVALID_STATUS_CODE");
|
|
637
|
+
this.statusCode = status;
|
|
638
|
+
if (typeof reason === "string")
|
|
639
|
+
this.statusMessage = reason;
|
|
640
|
+
else {
|
|
641
|
+
this.statusMessage = STATUS_CODES[status] ?? "unknown";
|
|
642
|
+
headers ??= reason;
|
|
643
|
+
}
|
|
644
|
+
if (/[\r\n]/.test(this.statusMessage))
|
|
645
|
+
throw coded(new TypeError("Invalid character in statusMessage"), "ERR_INVALID_CHAR");
|
|
646
|
+
if (Array.isArray(headers)) {
|
|
647
|
+
if (headers.length % 2)
|
|
648
|
+
throw coded(new TypeError("The argument 'headers' is invalid"), "ERR_INVALID_ARG_VALUE");
|
|
649
|
+
for (let i = 0; i < headers.length; i += 2)
|
|
650
|
+
this.appendHeader(String(headers[i]), headers[i + 1]);
|
|
651
|
+
}
|
|
652
|
+
else if (headers)
|
|
653
|
+
for (const [name, value] of Object.entries(headers))
|
|
654
|
+
if (value !== undefined)
|
|
655
|
+
this.setHeader(name, value);
|
|
656
|
+
if (status === 204 || status === 304)
|
|
657
|
+
this._hasBody = false;
|
|
658
|
+
if (this.hasHeader("content-length"))
|
|
659
|
+
this._contentLength = Number(this.getHeader("content-length"));
|
|
660
|
+
this._header = `HTTP/1.1 ${status} ${this.statusMessage}\r\n`;
|
|
661
|
+
this.flushHeaders();
|
|
662
|
+
return this;
|
|
663
|
+
}
|
|
664
|
+
writeHeader = this.writeHead.bind(this);
|
|
665
|
+
flushHeaders = () => {
|
|
666
|
+
if (!this._header)
|
|
667
|
+
this._implicitHeader();
|
|
668
|
+
if (!this._headerSent) {
|
|
669
|
+
this._headerSent = true;
|
|
670
|
+
this.emit("headers");
|
|
671
|
+
}
|
|
672
|
+
};
|
|
673
|
+
assignSocket(_socket) {
|
|
674
|
+
throw notImplemented("assignSocket");
|
|
675
|
+
}
|
|
676
|
+
detachSocket(_socket) {
|
|
677
|
+
throw notImplemented("detachSocket");
|
|
678
|
+
}
|
|
679
|
+
writeContinue(_callback) {
|
|
680
|
+
throw notImplemented("writeContinue");
|
|
681
|
+
}
|
|
682
|
+
writeProcessing(_callback) {
|
|
683
|
+
throw notImplemented("writeProcessing");
|
|
684
|
+
}
|
|
685
|
+
writeEarlyHints(_hints, _callback) {
|
|
686
|
+
throw notImplemented("writeEarlyHints");
|
|
687
|
+
}
|
|
688
|
+
_write = (chunk, encoding, done) => {
|
|
689
|
+
this.flushHeaders();
|
|
690
|
+
if (this.destroyed || !this._hasBody) {
|
|
691
|
+
done();
|
|
692
|
+
return;
|
|
693
|
+
}
|
|
694
|
+
const data = typeof chunk === "string"
|
|
695
|
+
? Buffer.from(chunk, encoding)
|
|
696
|
+
: new Uint8Array(chunk);
|
|
697
|
+
this.controller.enqueue(data);
|
|
698
|
+
if ((this.controller.desiredSize ?? 0) > 0)
|
|
699
|
+
done();
|
|
700
|
+
else
|
|
701
|
+
this.pending = done;
|
|
702
|
+
};
|
|
703
|
+
_final = (done) => {
|
|
704
|
+
this.finished = true;
|
|
705
|
+
this.flushHeaders();
|
|
706
|
+
if (!this.bodyClosed) {
|
|
707
|
+
this.bodyClosed = true;
|
|
708
|
+
this.controller.close();
|
|
709
|
+
}
|
|
710
|
+
done();
|
|
711
|
+
};
|
|
712
|
+
destroy(error) {
|
|
713
|
+
super.destroy(error);
|
|
714
|
+
return this;
|
|
715
|
+
}
|
|
716
|
+
_destroy = (error, callback) => {
|
|
717
|
+
if (!this.bodyClosed) {
|
|
718
|
+
this.bodyClosed = true;
|
|
719
|
+
this.controller.error(error ??
|
|
720
|
+
coded(new Error("Premature close"), "ERR_STREAM_PREMATURE_CLOSE"));
|
|
721
|
+
}
|
|
722
|
+
const pending = this.pending;
|
|
723
|
+
this.pending = undefined;
|
|
724
|
+
pending?.(error);
|
|
725
|
+
callback(error);
|
|
726
|
+
};
|
|
727
|
+
}
|
|
728
|
+
const captureRejection = (EventEmitter.captureRejectionSymbol ??
|
|
729
|
+
Symbol.for("nodejs.rejection"));
|
|
730
|
+
export class Server extends EventEmitter {
|
|
731
|
+
httpAllowHalfOpen = false;
|
|
732
|
+
timeout = 0;
|
|
733
|
+
maxHeadersCount = null;
|
|
734
|
+
maxRequestsPerSocket = 0;
|
|
735
|
+
connectionsCheckingInterval = 30_000;
|
|
736
|
+
requestTimeout = 300_000;
|
|
737
|
+
headersTimeout = 60_000;
|
|
738
|
+
requireHostHeader = false;
|
|
739
|
+
joinDuplicateHeaders = false;
|
|
740
|
+
rejectNonStandardBodyWrites = false;
|
|
741
|
+
keepAliveTimeout = 5_000;
|
|
742
|
+
keepAliveTimeoutBuffer = 1_000;
|
|
743
|
+
highWaterMark = 16 * 1024;
|
|
744
|
+
port;
|
|
745
|
+
IncomingMessageClass = IncomingMessage;
|
|
746
|
+
ServerResponseClass = ServerResponse;
|
|
747
|
+
constructor(options, listener) {
|
|
748
|
+
super({ captureRejections: true });
|
|
749
|
+
this.emit = ((event, ...args) => {
|
|
750
|
+
if (event !== "request")
|
|
751
|
+
return EventEmitter.prototype.emit.call(this, event, ...args);
|
|
752
|
+
const listeners = this.rawListeners(event);
|
|
753
|
+
for (const requestListener of listeners) {
|
|
754
|
+
try {
|
|
755
|
+
const result = requestListener.apply(this, args);
|
|
756
|
+
if (result &&
|
|
757
|
+
typeof result.then === "function")
|
|
758
|
+
void Promise.resolve(result).catch((error) => args[1].destroy(error));
|
|
759
|
+
}
|
|
760
|
+
catch (error) {
|
|
761
|
+
args[1].destroy(error);
|
|
762
|
+
throw error;
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
return listeners.length !== 0;
|
|
766
|
+
});
|
|
767
|
+
if (typeof options === "function")
|
|
768
|
+
listener = options;
|
|
769
|
+
else if (options != null) {
|
|
770
|
+
if (typeof options !== "object")
|
|
771
|
+
throw coded(new TypeError('The "options" argument must be of type object.'), "ERR_INVALID_ARG_TYPE");
|
|
772
|
+
if (options.maxHeaderSize !== undefined) {
|
|
773
|
+
validateInteger(options.maxHeaderSize, "maxHeaderSize", 0);
|
|
774
|
+
unsupportedOption("maxHeaderSize");
|
|
775
|
+
}
|
|
776
|
+
for (const key of ["requestTimeout", "headersTimeout"]) {
|
|
777
|
+
if (options[key] !== undefined) {
|
|
778
|
+
validateInteger(options[key], key, 0);
|
|
779
|
+
this[key] = options[key];
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
this.headersTimeout =
|
|
783
|
+
options.headersTimeout ?? Math.min(60_000, this.requestTimeout);
|
|
784
|
+
if (this.headersTimeout > 0 &&
|
|
785
|
+
this.requestTimeout > 0 &&
|
|
786
|
+
this.headersTimeout > this.requestTimeout)
|
|
787
|
+
throw coded(new RangeError("headersTimeout must be <= requestTimeout"), "ERR_OUT_OF_RANGE");
|
|
788
|
+
for (const key of [
|
|
789
|
+
"keepAliveTimeout",
|
|
790
|
+
"keepAliveTimeoutBuffer",
|
|
791
|
+
"connectionsCheckingInterval",
|
|
792
|
+
]) {
|
|
793
|
+
if (options[key] !== undefined) {
|
|
794
|
+
validateInteger(options[key], key, key === "keepAliveTimeoutBuffer" ? Number.MIN_SAFE_INTEGER : 0);
|
|
795
|
+
unsupportedOption(key);
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
for (const key of [
|
|
799
|
+
"insecureHTTPParser",
|
|
800
|
+
"requireHostHeader",
|
|
801
|
+
"joinDuplicateHeaders",
|
|
802
|
+
"rejectNonStandardBodyWrites",
|
|
803
|
+
])
|
|
804
|
+
if (options[key] !== undefined)
|
|
805
|
+
validateType(options[key], "boolean", key);
|
|
806
|
+
this.requireHostHeader = options.requireHostHeader ?? true;
|
|
807
|
+
this.joinDuplicateHeaders = options.joinDuplicateHeaders ?? false;
|
|
808
|
+
this.rejectNonStandardBodyWrites =
|
|
809
|
+
options.rejectNonStandardBodyWrites ?? false;
|
|
810
|
+
if (options.highWaterMark !== undefined) {
|
|
811
|
+
validateType(options.highWaterMark, "number", "highWaterMark");
|
|
812
|
+
if (options.highWaterMark > 0)
|
|
813
|
+
this.highWaterMark = options.highWaterMark;
|
|
814
|
+
}
|
|
815
|
+
if (options.IncomingMessage)
|
|
816
|
+
this.IncomingMessageClass =
|
|
817
|
+
options.IncomingMessage;
|
|
818
|
+
if (options.ServerResponse)
|
|
819
|
+
this.ServerResponseClass =
|
|
820
|
+
options.ServerResponse;
|
|
821
|
+
}
|
|
822
|
+
if (listener)
|
|
823
|
+
this.on("request", listener);
|
|
824
|
+
}
|
|
825
|
+
[captureRejection](error, event, ...args) {
|
|
826
|
+
if (event === "request") {
|
|
827
|
+
args[1].destroy(error);
|
|
828
|
+
return;
|
|
829
|
+
}
|
|
830
|
+
this.emit("error", error);
|
|
831
|
+
}
|
|
832
|
+
get listening() {
|
|
833
|
+
return this.port !== undefined;
|
|
834
|
+
}
|
|
835
|
+
listen(value, ...args) {
|
|
836
|
+
if (this.listening)
|
|
837
|
+
throw coded(new Error("Listen method has been called more than once without closing."), "ERR_SERVER_ALREADY_LISTEN");
|
|
838
|
+
const requested = typeof value === "object" && value !== null ? value.port : value;
|
|
839
|
+
let port = requested == null || typeof requested === "function"
|
|
840
|
+
? 0
|
|
841
|
+
: Number(requested);
|
|
842
|
+
if (!Number.isInteger(port) || port < 0 || port > 65535)
|
|
843
|
+
throw coded(new RangeError(`options.port should be >= 0 and < 65536. Received ${String(requested)}.`), "ERR_SOCKET_BAD_PORT");
|
|
844
|
+
if (port === 0) {
|
|
845
|
+
port = ephemeral();
|
|
846
|
+
if (port === 0)
|
|
847
|
+
throw new Error("No available logical HTTP ports");
|
|
848
|
+
}
|
|
849
|
+
if (hasHandler(port))
|
|
850
|
+
throw Object.assign(new Error(`listen EADDRINUSE: address already in use 127.0.0.1:${port}`), { code: "EADDRINUSE", port });
|
|
851
|
+
this.port = port;
|
|
852
|
+
setHandler(port, {
|
|
853
|
+
server: this,
|
|
854
|
+
createRequestResponse: () => ({
|
|
855
|
+
IncomingMessage: this.IncomingMessageClass,
|
|
856
|
+
ServerResponse: this.ServerResponseClass,
|
|
857
|
+
}),
|
|
858
|
+
});
|
|
859
|
+
const callback = [...args].reverse().find((arg) => typeof arg === "function") ??
|
|
860
|
+
(typeof value === "function" ? value : undefined);
|
|
861
|
+
if (callback)
|
|
862
|
+
this.once("listening", callback);
|
|
863
|
+
queueMicrotask(() => this.emit("listening"));
|
|
864
|
+
return this;
|
|
865
|
+
}
|
|
866
|
+
address() {
|
|
867
|
+
return this.port === undefined
|
|
868
|
+
? null
|
|
869
|
+
: { port: this.port, address: "127.0.0.1", family: "IPv4" };
|
|
870
|
+
}
|
|
871
|
+
close(callback) {
|
|
872
|
+
if (this.port !== undefined)
|
|
873
|
+
release(this.port);
|
|
874
|
+
this.port = undefined;
|
|
875
|
+
if (callback)
|
|
876
|
+
this.once("close", callback);
|
|
877
|
+
queueMicrotask(() => this.emit("close"));
|
|
878
|
+
return this;
|
|
879
|
+
}
|
|
880
|
+
closeAllConnections() { }
|
|
881
|
+
closeIdleConnections() { }
|
|
882
|
+
setTimeout(msecs, callback) {
|
|
883
|
+
if (typeof msecs === "function")
|
|
884
|
+
callback = msecs;
|
|
885
|
+
else if (typeof msecs === "number")
|
|
886
|
+
this.timeout = msecs;
|
|
887
|
+
if (callback)
|
|
888
|
+
this.on("timeout", callback);
|
|
889
|
+
return this;
|
|
890
|
+
}
|
|
891
|
+
getConnections(callback) {
|
|
892
|
+
if (callback) {
|
|
893
|
+
validateType(callback, "function", "callback");
|
|
894
|
+
queueMicrotask(() => callback(null, 0));
|
|
895
|
+
}
|
|
896
|
+
return this;
|
|
897
|
+
}
|
|
898
|
+
ref() {
|
|
899
|
+
return this;
|
|
900
|
+
}
|
|
901
|
+
unref() {
|
|
902
|
+
return this;
|
|
903
|
+
}
|
|
904
|
+
get maxConnections() {
|
|
905
|
+
return Infinity;
|
|
906
|
+
}
|
|
907
|
+
get connections() {
|
|
908
|
+
return 0;
|
|
909
|
+
}
|
|
910
|
+
async [asyncDispose]() {
|
|
911
|
+
await new Promise((resolve) => this.close(resolve));
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
export class Agent extends EventEmitter {
|
|
915
|
+
static defaultMaxSockets = Infinity;
|
|
916
|
+
defaultPort;
|
|
917
|
+
protocol;
|
|
918
|
+
options;
|
|
919
|
+
agentKeepAliveTimeoutBuffer = 1000;
|
|
920
|
+
keepAliveMsecs;
|
|
921
|
+
keepAlive;
|
|
922
|
+
maxSockets;
|
|
923
|
+
maxFreeSockets;
|
|
924
|
+
scheduling;
|
|
925
|
+
maxTotalSockets;
|
|
926
|
+
totalSocketCount = 0;
|
|
927
|
+
freeSockets = {};
|
|
928
|
+
sockets = {};
|
|
929
|
+
requests = {};
|
|
930
|
+
constructor(options = {}) {
|
|
931
|
+
super();
|
|
932
|
+
this.options = { __proto__: null, ...options };
|
|
933
|
+
const values = this.options;
|
|
934
|
+
this.defaultPort = values.defaultPort || 80;
|
|
935
|
+
this.protocol = values.protocol || "http:";
|
|
936
|
+
values.path = null;
|
|
937
|
+
if (!("proxyEnv" in values))
|
|
938
|
+
values.proxyEnv = undefined;
|
|
939
|
+
if (values.noDelay === undefined)
|
|
940
|
+
values.noDelay = true;
|
|
941
|
+
this.keepAliveMsecs = this.options.keepAliveMsecs || 1000;
|
|
942
|
+
this.keepAlive = this.options.keepAlive || false;
|
|
943
|
+
this.maxSockets = this.options.maxSockets || Agent.defaultMaxSockets;
|
|
944
|
+
this.maxFreeSockets = this.options.maxFreeSockets || 256;
|
|
945
|
+
this.scheduling = this.options.scheduling || "lifo";
|
|
946
|
+
if (!["fifo", "lifo"].includes(this.scheduling))
|
|
947
|
+
throw coded(new TypeError("options.scheduling is invalid"), "ERR_INVALID_ARG_VALUE");
|
|
948
|
+
const maximum = this.options.maxTotalSockets;
|
|
949
|
+
if (maximum !== undefined) {
|
|
950
|
+
validateNumber(maximum, "maxTotalSockets");
|
|
951
|
+
if (Number.isNaN(maximum) || maximum < 1)
|
|
952
|
+
throw coded(new RangeError("maxTotalSockets is out of range"), "ERR_OUT_OF_RANGE");
|
|
953
|
+
}
|
|
954
|
+
this.maxTotalSockets = maximum === undefined ? Infinity : maximum;
|
|
955
|
+
}
|
|
956
|
+
createConnection() {
|
|
957
|
+
throw notImplemented("createConnection");
|
|
958
|
+
}
|
|
959
|
+
getName(options = {}) {
|
|
960
|
+
let name = `${options.host || "localhost"}:${options.port || ""}:${options.localAddress || ""}`;
|
|
961
|
+
if (options.family === 4 || options.family === 6)
|
|
962
|
+
name += `:${options.family}`;
|
|
963
|
+
if (options.socketPath)
|
|
964
|
+
name += `:${options.socketPath}`;
|
|
965
|
+
return name;
|
|
966
|
+
}
|
|
967
|
+
addRequest(_request, _options) { }
|
|
968
|
+
createSocket(_request, _options, _callback) { }
|
|
969
|
+
removeSocket(_socket) { }
|
|
970
|
+
keepSocketAlive(_socket) {
|
|
971
|
+
return false;
|
|
972
|
+
}
|
|
973
|
+
reuseSocket(_socket, _request) { }
|
|
974
|
+
destroy(_error) { }
|
|
975
|
+
}
|
|
976
|
+
export const globalAgent = new Agent({
|
|
977
|
+
keepAlive: true,
|
|
978
|
+
scheduling: "lifo",
|
|
979
|
+
timeout: 5000,
|
|
980
|
+
});
|
|
981
|
+
const INVALID_PATH = /[^\u0021-\u00ff]/;
|
|
982
|
+
const AUTHORITY_OVERRIDE = /^(?:[/\\]{2}|[^/\\]*:)/;
|
|
983
|
+
export class ClientRequest extends OutgoingMessage {
|
|
984
|
+
method = "GET";
|
|
985
|
+
path = "/";
|
|
986
|
+
host;
|
|
987
|
+
protocol = "http:";
|
|
988
|
+
port = "80";
|
|
989
|
+
joinDuplicateHeaders;
|
|
990
|
+
agent;
|
|
991
|
+
aborted = false;
|
|
992
|
+
reusedSocket = false;
|
|
993
|
+
maxHeadersCount = Infinity;
|
|
994
|
+
connection = null;
|
|
995
|
+
socket = null;
|
|
996
|
+
timeout;
|
|
997
|
+
_ended = false;
|
|
998
|
+
abortController = new AbortController();
|
|
999
|
+
upload;
|
|
1000
|
+
uploadWriter;
|
|
1001
|
+
response;
|
|
1002
|
+
timer;
|
|
1003
|
+
sent = false;
|
|
1004
|
+
constructor(input, options, callback) {
|
|
1005
|
+
super();
|
|
1006
|
+
let values;
|
|
1007
|
+
if (typeof input === "string" || input instanceof URL) {
|
|
1008
|
+
const url = new URL(input);
|
|
1009
|
+
values = {
|
|
1010
|
+
protocol: url.protocol,
|
|
1011
|
+
hostname: url.hostname,
|
|
1012
|
+
port: url.port,
|
|
1013
|
+
path: `${url.pathname}${url.search}`,
|
|
1014
|
+
auth: url.username
|
|
1015
|
+
? `${decodeURIComponent(url.username)}:${decodeURIComponent(url.password)}`
|
|
1016
|
+
: undefined,
|
|
1017
|
+
};
|
|
1018
|
+
if (typeof options === "function")
|
|
1019
|
+
callback = options;
|
|
1020
|
+
else
|
|
1021
|
+
Object.assign(values, options);
|
|
1022
|
+
}
|
|
1023
|
+
else {
|
|
1024
|
+
values = {
|
|
1025
|
+
...(input ?? {}),
|
|
1026
|
+
...(typeof options === "object" ? options : {}),
|
|
1027
|
+
};
|
|
1028
|
+
if (typeof options === "function")
|
|
1029
|
+
callback = options;
|
|
1030
|
+
}
|
|
1031
|
+
const path = values.path || "/";
|
|
1032
|
+
if (INVALID_PATH.test(path))
|
|
1033
|
+
throw coded(new TypeError("Request path contains unescaped characters"), "ERR_UNESCAPED_CHARACTERS");
|
|
1034
|
+
if (AUTHORITY_OVERRIDE.test(path))
|
|
1035
|
+
throw coded(new TypeError("The property 'options.path' must be a path-only request target"), "ERR_INVALID_ARG_VALUE");
|
|
1036
|
+
if (values.hostname != null)
|
|
1037
|
+
validateType(values.hostname, "string", "hostname");
|
|
1038
|
+
if (!values.hostname && values.host != null)
|
|
1039
|
+
validateType(values.host, "string", "host");
|
|
1040
|
+
if (values.maxHeaderSize !== undefined) {
|
|
1041
|
+
validateInteger(values.maxHeaderSize, "maxHeaderSize", 0);
|
|
1042
|
+
unsupportedOption("maxHeaderSize");
|
|
1043
|
+
}
|
|
1044
|
+
if (values.insecureHTTPParser !== undefined)
|
|
1045
|
+
validateType(values.insecureHTTPParser, "boolean", "insecureHTTPParser");
|
|
1046
|
+
for (const key of ["createConnection", "lookup", "socketPath"]) {
|
|
1047
|
+
if (values[key] !== undefined) {
|
|
1048
|
+
validateType(values[key], key === "socketPath" ? "string" : "function", key);
|
|
1049
|
+
unsupportedOption(key);
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
if (values.joinDuplicateHeaders !== undefined)
|
|
1053
|
+
validateType(values.joinDuplicateHeaders, "boolean", "joinDuplicateHeaders");
|
|
1054
|
+
const defaultAgent = values._defaultAgent || globalAgent;
|
|
1055
|
+
const agent = values.agent === false
|
|
1056
|
+
? new defaultAgent.constructor()
|
|
1057
|
+
: (values.agent ?? defaultAgent);
|
|
1058
|
+
if (agent && typeof agent.addRequest !== "function")
|
|
1059
|
+
throw coded(new TypeError('The "options.agent" property must be an Agent-like Object, undefined, or false.'), "ERR_INVALID_ARG_TYPE");
|
|
1060
|
+
this.agent = agent;
|
|
1061
|
+
this.protocol = values.protocol || defaultAgent.protocol;
|
|
1062
|
+
if (this.protocol !== agent.protocol)
|
|
1063
|
+
throw coded(new TypeError(`Protocol "${this.protocol}" not supported. Expected "${agent.protocol}"`), "ERR_INVALID_PROTOCOL");
|
|
1064
|
+
this.port = String(values.port || values.defaultPort || agent.defaultPort || 80);
|
|
1065
|
+
this.host = String(values.hostname || values.host || "localhost");
|
|
1066
|
+
this.path = path;
|
|
1067
|
+
if (values.method != null && typeof values.method !== "string")
|
|
1068
|
+
throw coded(new TypeError('The "options.method" property must be of type string.'), "ERR_INVALID_ARG_TYPE");
|
|
1069
|
+
this.method = (values.method || "GET").toUpperCase();
|
|
1070
|
+
if (!/^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/.test(this.method))
|
|
1071
|
+
throw coded(new TypeError(`Method must be a valid HTTP token ["${this.method}"]`), "ERR_INVALID_HTTP_TOKEN");
|
|
1072
|
+
this.joinDuplicateHeaders = values.joinDuplicateHeaders;
|
|
1073
|
+
if (Array.isArray(values.headers)) {
|
|
1074
|
+
if (values.headers.length % 2)
|
|
1075
|
+
throw coded(new TypeError("The argument 'headers' is invalid"), "ERR_INVALID_ARG_VALUE");
|
|
1076
|
+
for (let i = 0; i < values.headers.length; i += 2)
|
|
1077
|
+
this.setHeader(values.headers[i], values.headers[i + 1]);
|
|
1078
|
+
}
|
|
1079
|
+
else
|
|
1080
|
+
for (const [name, value] of Object.entries(values.headers ?? {}))
|
|
1081
|
+
if (value !== undefined)
|
|
1082
|
+
this.setHeader(name, value);
|
|
1083
|
+
if (!this.hasHeader("host") &&
|
|
1084
|
+
values.setHost !== false &&
|
|
1085
|
+
values.setDefaultHeaders !== false) {
|
|
1086
|
+
const bracketed = this.host.includes(":") && !this.host.startsWith("[")
|
|
1087
|
+
? `[${this.host}]`
|
|
1088
|
+
: this.host;
|
|
1089
|
+
this.setHeader("Host", Number(this.port) === agent.defaultPort
|
|
1090
|
+
? bracketed
|
|
1091
|
+
: `${bracketed}:${this.port}`);
|
|
1092
|
+
}
|
|
1093
|
+
if (values.auth && !this.hasHeader("authorization"))
|
|
1094
|
+
this.setHeader("Authorization", `Basic ${Buffer.from(values.auth).toString("base64")}`);
|
|
1095
|
+
if (values.signal) {
|
|
1096
|
+
if (values.signal.aborted)
|
|
1097
|
+
this.destroy(values.signal.reason);
|
|
1098
|
+
else
|
|
1099
|
+
values.signal.addEventListener("abort", () => this.destroy(values.signal.reason), { once: true });
|
|
1100
|
+
}
|
|
1101
|
+
if (values.timeout !== undefined)
|
|
1102
|
+
this.setTimeout(values.timeout);
|
|
1103
|
+
if (callback)
|
|
1104
|
+
this.once("response", callback);
|
|
1105
|
+
}
|
|
1106
|
+
_implicitHeader() {
|
|
1107
|
+
if (this.hasHeader("content-length"))
|
|
1108
|
+
this._contentLength = Number(this.getHeader("content-length"));
|
|
1109
|
+
this._header = `${this.method} ${this.path} HTTP/1.1\r\n`;
|
|
1110
|
+
}
|
|
1111
|
+
write(chunk, encoding, callback) {
|
|
1112
|
+
return super.write(chunk, encoding, callback);
|
|
1113
|
+
}
|
|
1114
|
+
_write(chunk, encoding, callback) {
|
|
1115
|
+
if (this.method === "GET" || this.method === "HEAD") {
|
|
1116
|
+
callback();
|
|
1117
|
+
return;
|
|
1118
|
+
}
|
|
1119
|
+
try {
|
|
1120
|
+
if (!this.upload) {
|
|
1121
|
+
this.upload = new TransformStream();
|
|
1122
|
+
this.uploadWriter = this.upload.writable.getWriter();
|
|
1123
|
+
}
|
|
1124
|
+
this.#send();
|
|
1125
|
+
void this.uploadWriter.write(Buffer.from(chunk, encoding)).then(() => callback(), (error) => {
|
|
1126
|
+
this.destroy(error);
|
|
1127
|
+
callback(error);
|
|
1128
|
+
});
|
|
1129
|
+
}
|
|
1130
|
+
catch (error) {
|
|
1131
|
+
this.destroy(error);
|
|
1132
|
+
callback(error);
|
|
1133
|
+
}
|
|
1134
|
+
}
|
|
1135
|
+
_final = (callback) => {
|
|
1136
|
+
try {
|
|
1137
|
+
this.#send();
|
|
1138
|
+
if (this.uploadWriter)
|
|
1139
|
+
void this.uploadWriter.close().then(() => callback(), (error) => {
|
|
1140
|
+
this.destroy(error);
|
|
1141
|
+
callback(error);
|
|
1142
|
+
});
|
|
1143
|
+
else
|
|
1144
|
+
callback();
|
|
1145
|
+
}
|
|
1146
|
+
catch (error) {
|
|
1147
|
+
this.destroy(error);
|
|
1148
|
+
callback(error);
|
|
1149
|
+
}
|
|
1150
|
+
};
|
|
1151
|
+
flushHeaders = () => {
|
|
1152
|
+
super.flushHeaders();
|
|
1153
|
+
if (this.method !== "GET" && this.method !== "HEAD" && !this.upload) {
|
|
1154
|
+
this.upload = new TransformStream();
|
|
1155
|
+
this.uploadWriter = this.upload.writable.getWriter();
|
|
1156
|
+
}
|
|
1157
|
+
this.#send();
|
|
1158
|
+
};
|
|
1159
|
+
#send() {
|
|
1160
|
+
if (this.destroyed || this.sent)
|
|
1161
|
+
return;
|
|
1162
|
+
this.sent = true;
|
|
1163
|
+
this.#armTimer();
|
|
1164
|
+
const missingHost = this.host &&
|
|
1165
|
+
!this.getHeader("host") &&
|
|
1166
|
+
this.getHeaderNames().length === 0;
|
|
1167
|
+
let url;
|
|
1168
|
+
if (!missingHost) {
|
|
1169
|
+
if (AUTHORITY_OVERRIDE.test(this.path))
|
|
1170
|
+
throw coded(new TypeError("options.path must be a path-only request target"), "ERR_INVALID_ARG_VALUE");
|
|
1171
|
+
// Some Android WebViews percent-encode host spaces instead of rejecting
|
|
1172
|
+
// them. Preserve the pinned Workers URL validation before network I/O.
|
|
1173
|
+
if (/ |%20/i.test(this.host))
|
|
1174
|
+
throw new TypeError("Invalid URL");
|
|
1175
|
+
url = new URL(`${this.protocol}//${this.host}`);
|
|
1176
|
+
url.port = this.port;
|
|
1177
|
+
if (this.path.length > 0 && this.path !== "/")
|
|
1178
|
+
url = new URL(this.path, url);
|
|
1179
|
+
}
|
|
1180
|
+
const headers = [];
|
|
1181
|
+
for (const [name, value] of Object.values(this[kHeaders] ?? {}))
|
|
1182
|
+
for (const item of Array.isArray(value)
|
|
1183
|
+
? this.joinDuplicateHeaders
|
|
1184
|
+
? [value.join(", ")]
|
|
1185
|
+
: value
|
|
1186
|
+
: [value])
|
|
1187
|
+
headers.push([name, String(item)]);
|
|
1188
|
+
const body = this.upload?.readable ?? null;
|
|
1189
|
+
const response = missingHost
|
|
1190
|
+
? Promise.resolve(new Response(null, {
|
|
1191
|
+
status: 400,
|
|
1192
|
+
statusText: "Bad Request",
|
|
1193
|
+
headers: { connection: "close" },
|
|
1194
|
+
}))
|
|
1195
|
+
: fetch(url, {
|
|
1196
|
+
method: this.method,
|
|
1197
|
+
headers,
|
|
1198
|
+
body,
|
|
1199
|
+
signal: this.abortController.signal,
|
|
1200
|
+
redirect: "manual",
|
|
1201
|
+
encodeResponseBody: "manual",
|
|
1202
|
+
duplex: "half",
|
|
1203
|
+
});
|
|
1204
|
+
void response.then((response) => {
|
|
1205
|
+
if (this.destroyed) {
|
|
1206
|
+
void response.body?.cancel();
|
|
1207
|
+
return;
|
|
1208
|
+
}
|
|
1209
|
+
const incoming = new IncomingMessage();
|
|
1210
|
+
incoming[kSetIncomingFetchResponse](response, {
|
|
1211
|
+
setTimeout: (msecs) => {
|
|
1212
|
+
this.timeout = msecs;
|
|
1213
|
+
this.#armTimer();
|
|
1214
|
+
},
|
|
1215
|
+
touch: () => this.#armTimer(),
|
|
1216
|
+
});
|
|
1217
|
+
this.response = incoming;
|
|
1218
|
+
this._header = [...response.headers]
|
|
1219
|
+
.map(([key, value]) => `${key}: ${value}`)
|
|
1220
|
+
.join("\r\n");
|
|
1221
|
+
incoming.on("error", (error) => {
|
|
1222
|
+
if (!this.destroyed)
|
|
1223
|
+
this.emit("error", error);
|
|
1224
|
+
});
|
|
1225
|
+
incoming.once("close", () => this.#emitClose());
|
|
1226
|
+
this.#armTimer();
|
|
1227
|
+
if (!this.emit("response", incoming))
|
|
1228
|
+
incoming._dump();
|
|
1229
|
+
}, (error) => {
|
|
1230
|
+
if (!this.destroyed)
|
|
1231
|
+
this.destroy(error);
|
|
1232
|
+
});
|
|
1233
|
+
}
|
|
1234
|
+
addTrailers(_headers) {
|
|
1235
|
+
throw notImplemented("addTrailers");
|
|
1236
|
+
}
|
|
1237
|
+
onSocket(_socket) { }
|
|
1238
|
+
setNoDelay(noDelay) {
|
|
1239
|
+
validateBoolean(noDelay, "noDelay");
|
|
1240
|
+
}
|
|
1241
|
+
setSocketKeepAlive(enable, initialDelay) {
|
|
1242
|
+
validateBoolean(enable, "enable");
|
|
1243
|
+
validateNumber(initialDelay, "initialDelay");
|
|
1244
|
+
}
|
|
1245
|
+
clearTimeout(callback) {
|
|
1246
|
+
return this.setTimeout(0, callback);
|
|
1247
|
+
}
|
|
1248
|
+
setTimeout(msecs, callback) {
|
|
1249
|
+
if (!Number.isFinite(msecs) || msecs < 0)
|
|
1250
|
+
throw coded(new RangeError('The value of "msecs" is out of range.'), "ERR_OUT_OF_RANGE");
|
|
1251
|
+
this.timeout = msecs;
|
|
1252
|
+
if (callback)
|
|
1253
|
+
this.once("timeout", callback);
|
|
1254
|
+
this.#armTimer();
|
|
1255
|
+
return this;
|
|
1256
|
+
}
|
|
1257
|
+
#armTimer() {
|
|
1258
|
+
if (this.timer)
|
|
1259
|
+
clearTimeout(this.timer);
|
|
1260
|
+
if (!this.timeout || !this.sent || this.destroyed)
|
|
1261
|
+
return;
|
|
1262
|
+
this.timer = setTimeout(() => {
|
|
1263
|
+
this.emit("timeout");
|
|
1264
|
+
this.response?.emit("timeout");
|
|
1265
|
+
this.destroy(coded(new Error("The operation was aborted"), "ABORT_ERR"));
|
|
1266
|
+
}, this.timeout);
|
|
1267
|
+
}
|
|
1268
|
+
#releaseUpload(error = new Error("Request closed")) {
|
|
1269
|
+
void this.uploadWriter?.abort(error).catch(() => { });
|
|
1270
|
+
this.uploadWriter = undefined;
|
|
1271
|
+
this.upload = undefined;
|
|
1272
|
+
}
|
|
1273
|
+
#emitClose() {
|
|
1274
|
+
if (!this._closed) {
|
|
1275
|
+
this._closed = true;
|
|
1276
|
+
this.destroyed = true;
|
|
1277
|
+
this.#releaseUpload();
|
|
1278
|
+
if (this.timer)
|
|
1279
|
+
clearTimeout(this.timer);
|
|
1280
|
+
this.emit("close");
|
|
1281
|
+
}
|
|
1282
|
+
}
|
|
1283
|
+
abort() {
|
|
1284
|
+
if (!this.aborted) {
|
|
1285
|
+
this.aborted = true;
|
|
1286
|
+
queueMicrotask(() => this.emit("abort"));
|
|
1287
|
+
this.destroy();
|
|
1288
|
+
}
|
|
1289
|
+
}
|
|
1290
|
+
destroy(error) {
|
|
1291
|
+
if (this.destroyed)
|
|
1292
|
+
return this;
|
|
1293
|
+
this.destroyed = true;
|
|
1294
|
+
this.#releaseUpload(error);
|
|
1295
|
+
if (this.timer)
|
|
1296
|
+
clearTimeout(this.timer);
|
|
1297
|
+
if (!this.response && error == null && !this.aborted)
|
|
1298
|
+
error = coded(new Error("socket hang up"), "ECONNRESET");
|
|
1299
|
+
if (error)
|
|
1300
|
+
queueMicrotask(() => this.emit("error", error));
|
|
1301
|
+
if (this.response && !this.response.complete)
|
|
1302
|
+
this.response.destroy(coded(new Error("aborted"), "ECONNRESET"));
|
|
1303
|
+
else
|
|
1304
|
+
this.abortController.abort();
|
|
1305
|
+
queueMicrotask(() => this.#emitClose());
|
|
1306
|
+
return this;
|
|
1307
|
+
}
|
|
1308
|
+
end(chunk, encoding, callback) {
|
|
1309
|
+
this._ended = true;
|
|
1310
|
+
return super.end(chunk, encoding, callback);
|
|
1311
|
+
}
|
|
1312
|
+
}
|
|
1313
|
+
export function request(url, options, callback) {
|
|
1314
|
+
return new ClientRequest(url, options, callback);
|
|
1315
|
+
}
|
|
1316
|
+
export function get(url, options, callback) {
|
|
1317
|
+
const result = request(url, options, callback);
|
|
1318
|
+
result.end();
|
|
1319
|
+
return result;
|
|
1320
|
+
}
|
|
1321
|
+
export function createServer(options, listener) {
|
|
1322
|
+
return new Server(options, listener);
|
|
1323
|
+
}
|
|
1324
|
+
export function setMaxIdleHTTPParsers(max) {
|
|
1325
|
+
if (!Number.isInteger(max) || max < 1)
|
|
1326
|
+
throw coded(new RangeError('The value of "max" is out of range.'), "ERR_OUT_OF_RANGE");
|
|
1327
|
+
throw notImplemented("setMaxIdleHTTPParsers");
|
|
1328
|
+
}
|
|
1329
|
+
export function _connectionListener() {
|
|
1330
|
+
throw notImplemented("_connectionListener");
|
|
1331
|
+
}
|
|
1332
|
+
export const WebSocket = globalThis.WebSocket;
|
|
1333
|
+
export const CloseEvent = globalThis.CloseEvent;
|
|
1334
|
+
export const MessageEvent = globalThis.MessageEvent;
|
|
1335
|
+
export default {
|
|
1336
|
+
validateHeaderName,
|
|
1337
|
+
validateHeaderValue,
|
|
1338
|
+
METHODS,
|
|
1339
|
+
STATUS_CODES,
|
|
1340
|
+
ClientRequest,
|
|
1341
|
+
request,
|
|
1342
|
+
get,
|
|
1343
|
+
OutgoingMessage,
|
|
1344
|
+
Agent,
|
|
1345
|
+
globalAgent,
|
|
1346
|
+
IncomingMessage,
|
|
1347
|
+
Server,
|
|
1348
|
+
ServerResponse,
|
|
1349
|
+
createServer,
|
|
1350
|
+
maxHeaderSize,
|
|
1351
|
+
setMaxIdleHTTPParsers,
|
|
1352
|
+
_connectionListener,
|
|
1353
|
+
WebSocket,
|
|
1354
|
+
CloseEvent,
|
|
1355
|
+
MessageEvent,
|
|
1356
|
+
};
|