nlcurl 0.6.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +143 -140
- package/dist/cache/groups.d.ts +75 -0
- package/dist/cache/groups.d.ts.map +1 -0
- package/dist/cache/groups.js +118 -0
- package/dist/cache/groups.js.map +1 -0
- package/dist/cache/no-vary-search.d.ts +33 -0
- package/dist/cache/no-vary-search.d.ts.map +1 -0
- package/dist/cache/no-vary-search.js +148 -0
- package/dist/cache/no-vary-search.js.map +1 -0
- package/dist/cache/range.d.ts +120 -0
- package/dist/cache/range.d.ts.map +1 -0
- package/dist/cache/range.js +193 -0
- package/dist/cache/range.js.map +1 -0
- package/dist/cache/store.d.ts +111 -0
- package/dist/cache/store.d.ts.map +1 -0
- package/dist/cache/store.js +414 -0
- package/dist/cache/store.js.map +1 -0
- package/dist/cache/types.d.ts +69 -0
- package/dist/cache/types.d.ts.map +1 -0
- package/dist/cache/types.js +2 -0
- package/dist/cache/types.js.map +1 -0
- package/dist/cli/args.d.ts +4 -37
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +3 -4
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/index.d.ts +0 -5
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +1 -6
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/output.d.ts +14 -20
- package/dist/cli/output.d.ts.map +1 -1
- package/dist/cli/output.js +14 -20
- package/dist/cli/output.js.map +1 -1
- package/dist/cookies/jar.d.ts +33 -31
- package/dist/cookies/jar.d.ts.map +1 -1
- package/dist/cookies/jar.js +69 -33
- package/dist/cookies/jar.js.map +1 -1
- package/dist/cookies/parser.d.ts +14 -16
- package/dist/cookies/parser.d.ts.map +1 -1
- package/dist/cookies/parser.js +30 -13
- package/dist/cookies/parser.js.map +1 -1
- package/dist/cookies/psl-data.d.ts +1 -1
- package/dist/cookies/psl-data.js +1 -1
- package/dist/cookies/public-suffix.d.ts +5 -27
- package/dist/cookies/public-suffix.d.ts.map +1 -1
- package/dist/cookies/public-suffix.js +5 -37
- package/dist/cookies/public-suffix.js.map +1 -1
- package/dist/core/auth.d.ts +30 -0
- package/dist/core/auth.d.ts.map +1 -0
- package/dist/core/auth.js +34 -0
- package/dist/core/auth.js.map +1 -0
- package/dist/core/client.d.ts +28 -40
- package/dist/core/client.d.ts.map +1 -1
- package/dist/core/client.js +34 -41
- package/dist/core/client.js.map +1 -1
- package/dist/core/errors.d.ts +64 -88
- package/dist/core/errors.d.ts.map +1 -1
- package/dist/core/errors.js +64 -88
- package/dist/core/errors.js.map +1 -1
- package/dist/core/request.d.ts +63 -85
- package/dist/core/request.d.ts.map +1 -1
- package/dist/core/response.d.ts +64 -59
- package/dist/core/response.d.ts.map +1 -1
- package/dist/core/response.js +70 -52
- package/dist/core/response.js.map +1 -1
- package/dist/core/session.d.ts +81 -70
- package/dist/core/session.d.ts.map +1 -1
- package/dist/core/session.js +198 -71
- package/dist/core/session.js.map +1 -1
- package/dist/core/validation.d.ts +44 -42
- package/dist/core/validation.d.ts.map +1 -1
- package/dist/core/validation.js +47 -58
- package/dist/core/validation.js.map +1 -1
- package/dist/dns/cache.d.ts +59 -0
- package/dist/dns/cache.d.ts.map +1 -0
- package/dist/dns/cache.js +99 -0
- package/dist/dns/cache.js.map +1 -0
- package/dist/dns/codec.d.ts +39 -0
- package/dist/dns/codec.d.ts.map +1 -0
- package/dist/dns/codec.js +238 -0
- package/dist/dns/codec.js.map +1 -0
- package/dist/dns/doh-resolver.d.ts +38 -0
- package/dist/dns/doh-resolver.d.ts.map +1 -0
- package/dist/dns/doh-resolver.js +191 -0
- package/dist/dns/doh-resolver.js.map +1 -0
- package/dist/dns/dot-resolver.d.ts +89 -0
- package/dist/dns/dot-resolver.d.ts.map +1 -0
- package/dist/dns/dot-resolver.js +158 -0
- package/dist/dns/dot-resolver.js.map +1 -0
- package/dist/dns/https-rr.d.ts +40 -0
- package/dist/dns/https-rr.d.ts.map +1 -0
- package/dist/dns/https-rr.js +109 -0
- package/dist/dns/https-rr.js.map +1 -0
- package/dist/dns/types.d.ts +82 -0
- package/dist/dns/types.d.ts.map +1 -0
- package/dist/dns/types.js +23 -0
- package/dist/dns/types.js.map +1 -0
- package/dist/fingerprints/akamai.d.ts +3 -11
- package/dist/fingerprints/akamai.d.ts.map +1 -1
- package/dist/fingerprints/akamai.js +3 -11
- package/dist/fingerprints/akamai.js.map +1 -1
- package/dist/fingerprints/database.d.ts +6 -14
- package/dist/fingerprints/database.d.ts.map +1 -1
- package/dist/fingerprints/database.js +6 -14
- package/dist/fingerprints/database.js.map +1 -1
- package/dist/fingerprints/extensions.d.ts +56 -71
- package/dist/fingerprints/extensions.d.ts.map +1 -1
- package/dist/fingerprints/extensions.js +58 -71
- package/dist/fingerprints/extensions.js.map +1 -1
- package/dist/fingerprints/ja3.d.ts +12 -30
- package/dist/fingerprints/ja3.d.ts.map +1 -1
- package/dist/fingerprints/ja3.js +12 -30
- package/dist/fingerprints/ja3.js.map +1 -1
- package/dist/fingerprints/ja4.d.ts +18 -0
- package/dist/fingerprints/ja4.d.ts.map +1 -0
- package/dist/fingerprints/ja4.js +83 -0
- package/dist/fingerprints/ja4.js.map +1 -0
- package/dist/fingerprints/profiles/chrome.d.ts +18 -21
- package/dist/fingerprints/profiles/chrome.d.ts.map +1 -1
- package/dist/fingerprints/profiles/chrome.js +35 -31
- package/dist/fingerprints/profiles/chrome.js.map +1 -1
- package/dist/fingerprints/profiles/edge.d.ts +7 -10
- package/dist/fingerprints/profiles/edge.d.ts.map +1 -1
- package/dist/fingerprints/profiles/edge.js +7 -10
- package/dist/fingerprints/profiles/edge.js.map +1 -1
- package/dist/fingerprints/profiles/firefox.d.ts +8 -11
- package/dist/fingerprints/profiles/firefox.d.ts.map +1 -1
- package/dist/fingerprints/profiles/firefox.js +8 -11
- package/dist/fingerprints/profiles/firefox.js.map +1 -1
- package/dist/fingerprints/profiles/safari.d.ts +11 -14
- package/dist/fingerprints/profiles/safari.d.ts.map +1 -1
- package/dist/fingerprints/profiles/safari.js +11 -14
- package/dist/fingerprints/profiles/safari.js.map +1 -1
- package/dist/fingerprints/profiles/tor.d.ts +5 -8
- package/dist/fingerprints/profiles/tor.d.ts.map +1 -1
- package/dist/fingerprints/profiles/tor.js +5 -8
- package/dist/fingerprints/profiles/tor.js.map +1 -1
- package/dist/fingerprints/types.d.ts +42 -73
- package/dist/fingerprints/types.d.ts.map +1 -1
- package/dist/hsts/store.d.ts +39 -0
- package/dist/hsts/store.d.ts.map +1 -0
- package/dist/hsts/store.js +163 -0
- package/dist/hsts/store.js.map +1 -0
- package/dist/hsts/types.d.ts +24 -0
- package/dist/hsts/types.d.ts.map +1 -0
- package/dist/hsts/types.js +2 -0
- package/dist/hsts/types.js.map +1 -0
- package/dist/http/alt-svc.d.ts +67 -0
- package/dist/http/alt-svc.d.ts.map +1 -0
- package/dist/http/alt-svc.js +186 -0
- package/dist/http/alt-svc.js.map +1 -0
- package/dist/http/early-hints.d.ts +23 -0
- package/dist/http/early-hints.d.ts.map +1 -0
- package/dist/http/early-hints.js +33 -0
- package/dist/http/early-hints.js.map +1 -0
- package/dist/http/form-data.d.ts +17 -35
- package/dist/http/form-data.d.ts.map +1 -1
- package/dist/http/form-data.js +12 -34
- package/dist/http/form-data.js.map +1 -1
- package/dist/http/h1/client.d.ts +14 -26
- package/dist/http/h1/client.d.ts.map +1 -1
- package/dist/http/h1/client.js +29 -22
- package/dist/http/h1/client.js.map +1 -1
- package/dist/http/h1/encoder.d.ts +10 -17
- package/dist/http/h1/encoder.d.ts.map +1 -1
- package/dist/http/h1/encoder.js +10 -17
- package/dist/http/h1/encoder.js.map +1 -1
- package/dist/http/h1/parser.d.ts +22 -59
- package/dist/http/h1/parser.d.ts.map +1 -1
- package/dist/http/h1/parser.js +15 -47
- package/dist/http/h1/parser.js.map +1 -1
- package/dist/http/h2/client.d.ts +18 -59
- package/dist/http/h2/client.d.ts.map +1 -1
- package/dist/http/h2/client.js +29 -64
- package/dist/http/h2/client.js.map +1 -1
- package/dist/http/h2/frames.d.ts +53 -84
- package/dist/http/h2/frames.d.ts.map +1 -1
- package/dist/http/h2/frames.js +48 -76
- package/dist/http/h2/frames.js.map +1 -1
- package/dist/http/h2/hpack.d.ts +16 -35
- package/dist/http/h2/hpack.d.ts.map +1 -1
- package/dist/http/h2/hpack.js +16 -35
- package/dist/http/h2/hpack.js.map +1 -1
- package/dist/http/h3/detection.d.ts +15 -0
- package/dist/http/h3/detection.d.ts.map +1 -0
- package/dist/http/h3/detection.js +41 -0
- package/dist/http/h3/detection.js.map +1 -0
- package/dist/http/negotiator.d.ts +43 -33
- package/dist/http/negotiator.d.ts.map +1 -1
- package/dist/http/negotiator.js +99 -41
- package/dist/http/negotiator.js.map +1 -1
- package/dist/http/pool.d.ts +34 -64
- package/dist/http/pool.d.ts.map +1 -1
- package/dist/http/pool.js +22 -41
- package/dist/http/pool.js.map +1 -1
- package/dist/http/resumable-upload.d.ts +76 -0
- package/dist/http/resumable-upload.d.ts.map +1 -0
- package/dist/http/resumable-upload.js +104 -0
- package/dist/http/resumable-upload.js.map +1 -0
- package/dist/http/trailers.d.ts +29 -0
- package/dist/http/trailers.d.ts.map +1 -0
- package/dist/http/trailers.js +57 -0
- package/dist/http/trailers.js.map +1 -0
- package/dist/index.d.ts +36 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +32 -1
- package/dist/index.js.map +1 -1
- package/dist/middleware/interceptor.d.ts +13 -32
- package/dist/middleware/interceptor.d.ts.map +1 -1
- package/dist/middleware/interceptor.js +11 -16
- package/dist/middleware/interceptor.js.map +1 -1
- package/dist/middleware/rate-limiter.d.ts +8 -17
- package/dist/middleware/rate-limiter.d.ts.map +1 -1
- package/dist/middleware/rate-limiter.js +15 -12
- package/dist/middleware/rate-limiter.js.map +1 -1
- package/dist/middleware/retry-after.d.ts +15 -0
- package/dist/middleware/retry-after.d.ts.map +1 -0
- package/dist/middleware/retry-after.js +36 -0
- package/dist/middleware/retry-after.js.map +1 -0
- package/dist/middleware/retry.d.ts +9 -18
- package/dist/middleware/retry.d.ts.map +1 -1
- package/dist/middleware/retry.js +12 -9
- package/dist/middleware/retry.js.map +1 -1
- package/dist/proxy/auth.d.ts +73 -0
- package/dist/proxy/auth.d.ts.map +1 -0
- package/dist/proxy/auth.js +128 -0
- package/dist/proxy/auth.js.map +1 -0
- package/dist/proxy/env-proxy.d.ts +11 -0
- package/dist/proxy/env-proxy.d.ts.map +1 -0
- package/dist/proxy/env-proxy.js +56 -0
- package/dist/proxy/env-proxy.js.map +1 -0
- package/dist/proxy/http-proxy.d.ts +13 -18
- package/dist/proxy/http-proxy.d.ts.map +1 -1
- package/dist/proxy/http-proxy.js +24 -14
- package/dist/proxy/http-proxy.js.map +1 -1
- package/dist/proxy/socks.d.ts +13 -20
- package/dist/proxy/socks.d.ts.map +1 -1
- package/dist/proxy/socks.js +6 -9
- package/dist/proxy/socks.js.map +1 -1
- package/dist/sse/parser.d.ts +47 -0
- package/dist/sse/parser.d.ts.map +1 -0
- package/dist/sse/parser.js +139 -0
- package/dist/sse/parser.js.map +1 -0
- package/dist/tls/constants.d.ts +15 -74
- package/dist/tls/constants.d.ts.map +1 -1
- package/dist/tls/constants.js +15 -74
- package/dist/tls/constants.js.map +1 -1
- package/dist/tls/ct.d.ts +78 -0
- package/dist/tls/ct.d.ts.map +1 -0
- package/dist/tls/ct.js +175 -0
- package/dist/tls/ct.js.map +1 -0
- package/dist/tls/early-data.d.ts +45 -0
- package/dist/tls/early-data.d.ts.map +1 -0
- package/dist/tls/early-data.js +46 -0
- package/dist/tls/early-data.js.map +1 -0
- package/dist/tls/ech.d.ts +130 -0
- package/dist/tls/ech.d.ts.map +1 -0
- package/dist/tls/ech.js +353 -0
- package/dist/tls/ech.js.map +1 -0
- package/dist/tls/keylog.d.ts +34 -0
- package/dist/tls/keylog.d.ts.map +1 -0
- package/dist/tls/keylog.js +64 -0
- package/dist/tls/keylog.js.map +1 -0
- package/dist/tls/node-engine.d.ts +15 -14
- package/dist/tls/node-engine.d.ts.map +1 -1
- package/dist/tls/node-engine.js +54 -14
- package/dist/tls/node-engine.js.map +1 -1
- package/dist/tls/ocsp.d.ts +55 -0
- package/dist/tls/ocsp.d.ts.map +1 -0
- package/dist/tls/ocsp.js +131 -0
- package/dist/tls/ocsp.js.map +1 -0
- package/dist/tls/pin-verification.d.ts +10 -0
- package/dist/tls/pin-verification.d.ts.map +1 -0
- package/dist/tls/pin-verification.js +28 -0
- package/dist/tls/pin-verification.js.map +1 -0
- package/dist/tls/session-cache.d.ts +58 -0
- package/dist/tls/session-cache.d.ts.map +1 -0
- package/dist/tls/session-cache.js +76 -0
- package/dist/tls/session-cache.js.map +1 -0
- package/dist/tls/stealth/client-hello.d.ts +34 -32
- package/dist/tls/stealth/client-hello.d.ts.map +1 -1
- package/dist/tls/stealth/client-hello.js +116 -11
- package/dist/tls/stealth/client-hello.js.map +1 -1
- package/dist/tls/stealth/engine.d.ts +5 -15
- package/dist/tls/stealth/engine.d.ts.map +1 -1
- package/dist/tls/stealth/engine.js +163 -47
- package/dist/tls/stealth/engine.js.map +1 -1
- package/dist/tls/stealth/handshake.d.ts +23 -32
- package/dist/tls/stealth/handshake.d.ts.map +1 -1
- package/dist/tls/stealth/handshake.js +112 -27
- package/dist/tls/stealth/handshake.js.map +1 -1
- package/dist/tls/stealth/key-schedule.d.ts +59 -86
- package/dist/tls/stealth/key-schedule.d.ts.map +1 -1
- package/dist/tls/stealth/key-schedule.js +46 -58
- package/dist/tls/stealth/key-schedule.js.map +1 -1
- package/dist/tls/stealth/record-layer.d.ts +52 -75
- package/dist/tls/stealth/record-layer.d.ts.map +1 -1
- package/dist/tls/stealth/record-layer.js +47 -63
- package/dist/tls/stealth/record-layer.js.map +1 -1
- package/dist/tls/stealth/tls12-handshake.d.ts +30 -0
- package/dist/tls/stealth/tls12-handshake.d.ts.map +1 -0
- package/dist/tls/stealth/tls12-handshake.js +470 -0
- package/dist/tls/stealth/tls12-handshake.js.map +1 -0
- package/dist/tls/types.d.ts +46 -48
- package/dist/tls/types.d.ts.map +1 -1
- package/dist/utils/buffer-reader.d.ts +26 -81
- package/dist/utils/buffer-reader.d.ts.map +1 -1
- package/dist/utils/buffer-reader.js +26 -81
- package/dist/utils/buffer-reader.js.map +1 -1
- package/dist/utils/buffer-writer.d.ts +30 -66
- package/dist/utils/buffer-writer.d.ts.map +1 -1
- package/dist/utils/buffer-writer.js +30 -66
- package/dist/utils/buffer-writer.js.map +1 -1
- package/dist/utils/compression.d.ts +18 -0
- package/dist/utils/compression.d.ts.map +1 -0
- package/dist/utils/compression.js +34 -0
- package/dist/utils/compression.js.map +1 -0
- package/dist/utils/dictionary-transport.d.ts +97 -0
- package/dist/utils/dictionary-transport.d.ts.map +1 -0
- package/dist/utils/dictionary-transport.js +171 -0
- package/dist/utils/dictionary-transport.js.map +1 -0
- package/dist/utils/encoding.d.ts +12 -28
- package/dist/utils/encoding.d.ts.map +1 -1
- package/dist/utils/encoding.js +77 -40
- package/dist/utils/encoding.js.map +1 -1
- package/dist/utils/happy-eyeballs.d.ts +20 -7
- package/dist/utils/happy-eyeballs.d.ts.map +1 -1
- package/dist/utils/happy-eyeballs.js +57 -25
- package/dist/utils/happy-eyeballs.js.map +1 -1
- package/dist/utils/logger.d.ts +54 -81
- package/dist/utils/logger.d.ts.map +1 -1
- package/dist/utils/logger.js +92 -64
- package/dist/utils/logger.js.map +1 -1
- package/dist/utils/tcp-fast-open.d.ts +30 -0
- package/dist/utils/tcp-fast-open.d.ts.map +1 -0
- package/dist/utils/tcp-fast-open.js +36 -0
- package/dist/utils/tcp-fast-open.js.map +1 -0
- package/dist/utils/url.d.ts +18 -25
- package/dist/utils/url.d.ts.map +1 -1
- package/dist/utils/url.js +18 -25
- package/dist/utils/url.js.map +1 -1
- package/dist/ws/client.d.ts +35 -52
- package/dist/ws/client.d.ts.map +1 -1
- package/dist/ws/client.js +92 -37
- package/dist/ws/client.js.map +1 -1
- package/dist/ws/frame.d.ts +27 -42
- package/dist/ws/frame.d.ts.map +1 -1
- package/dist/ws/frame.js +25 -37
- package/dist/ws/frame.js.map +1 -1
- package/dist/ws/permessage-deflate.d.ts +53 -0
- package/dist/ws/permessage-deflate.d.ts.map +1 -0
- package/dist/ws/permessage-deflate.js +140 -0
- package/dist/ws/permessage-deflate.js.map +1 -0
- package/package.json +62 -62
package/dist/http/pool.d.ts
CHANGED
|
@@ -1,109 +1,79 @@
|
|
|
1
1
|
import type { TLSSocket } from "../tls/types.js";
|
|
2
2
|
import { H2Client } from "./h2/client.js";
|
|
3
3
|
import type { H2Profile } from "../fingerprints/types.js";
|
|
4
|
-
/**
|
|
5
|
-
* Represents a single pooled connection entry, holding the TLS socket,
|
|
6
|
-
* protocol version, and lifecycle timestamps.
|
|
7
|
-
*
|
|
8
|
-
* @typedef {Object} PoolEntry
|
|
9
|
-
* @property {string} origin - Origin key in `protocol://hostname:port` form.
|
|
10
|
-
* @property {TLSSocket} socket - The underlying TLS (or TCP) socket.
|
|
11
|
-
* @property {'h1'|'h2'} protocol - Negotiated HTTP protocol version.
|
|
12
|
-
* @property {H2Client} [h2Client] - HTTP/2 client instance when `protocol === 'h2'`.
|
|
13
|
-
* @property {number} createdAt - Unix timestamp (ms) when the connection was established.
|
|
14
|
-
* @property {number} lastUsed - Unix timestamp (ms) when the connection was last checked out.
|
|
15
|
-
* @property {boolean} busy - `true` while an HTTP/1.1 request is in flight.
|
|
16
|
-
*/
|
|
4
|
+
/** A pooled connection entry. */
|
|
17
5
|
export interface PoolEntry {
|
|
6
|
+
/** Origin key (scheme + host + port). */
|
|
18
7
|
origin: string;
|
|
8
|
+
/** Underlying TLS socket. */
|
|
19
9
|
socket: TLSSocket;
|
|
20
|
-
protocol
|
|
10
|
+
/** Negotiated HTTP protocol version. */
|
|
11
|
+
protocol: "h1" | "h2" | "h3";
|
|
12
|
+
/** HTTP/2 multiplexing client, if this is an h2 connection. */
|
|
21
13
|
h2Client?: H2Client;
|
|
14
|
+
/** Timestamp when the connection was created. */
|
|
22
15
|
createdAt: number;
|
|
16
|
+
/** Timestamp when the connection was last used. */
|
|
23
17
|
lastUsed: number;
|
|
18
|
+
/** Whether the connection is currently in use. */
|
|
24
19
|
busy: boolean;
|
|
25
20
|
}
|
|
26
|
-
/**
|
|
27
|
-
* Configuration options for the {@link ConnectionPool}.
|
|
28
|
-
*
|
|
29
|
-
* @typedef {Object} PoolOptions
|
|
30
|
-
* @property {number} [maxConnectionsPerOrigin=6] - Maximum simultaneous connections to a single origin.
|
|
31
|
-
* @property {number} [maxTotalConnections=64] - Maximum total connections across all origins.
|
|
32
|
-
* @property {number} [idleTimeout=60000] - Milliseconds of inactivity before a connection is evicted.
|
|
33
|
-
* @property {number} [maxAge=300000] - Maximum lifetime of a connection in milliseconds.
|
|
34
|
-
*/
|
|
21
|
+
/** Connection pool configuration. */
|
|
35
22
|
export interface PoolOptions {
|
|
23
|
+
/** Maximum connections per origin. */
|
|
36
24
|
maxConnectionsPerOrigin?: number;
|
|
25
|
+
/** Maximum total connections across all origins. */
|
|
37
26
|
maxTotalConnections?: number;
|
|
27
|
+
/** Idle timeout in milliseconds before connections are closed. */
|
|
38
28
|
idleTimeout?: number;
|
|
29
|
+
/** Maximum connection age in milliseconds. */
|
|
39
30
|
maxAge?: number;
|
|
40
31
|
}
|
|
41
|
-
/**
|
|
42
|
-
* Maintains a pool of reusable TLS connections, keyed by origin, supporting
|
|
43
|
-
* both HTTP/1.1 (exclusive per-request access) and HTTP/2 (multiplexed)
|
|
44
|
-
* connections. Idle and expired connections are evicted automatically on a
|
|
45
|
-
* 30-second timer.
|
|
46
|
-
*/
|
|
32
|
+
/** HTTP connection pool with idle eviction and per-origin limits. */
|
|
47
33
|
export declare class ConnectionPool {
|
|
48
34
|
private readonly options;
|
|
49
35
|
private readonly connections;
|
|
50
36
|
private totalConnections;
|
|
51
37
|
private cleanupTimer;
|
|
52
38
|
/**
|
|
53
|
-
*
|
|
39
|
+
* Create a new connection pool.
|
|
54
40
|
*
|
|
55
|
-
* @param {PoolOptions} [options
|
|
41
|
+
* @param {PoolOptions} [options] - Pool configuration.
|
|
56
42
|
*/
|
|
57
43
|
constructor(options?: PoolOptions);
|
|
58
44
|
/**
|
|
59
|
-
*
|
|
60
|
-
* any live connection (multiplexing); for HTTP/1.1 returns a non-busy,
|
|
61
|
-
* non-expired connection and marks it busy.
|
|
45
|
+
* Get an available connection for the given origin.
|
|
62
46
|
*
|
|
63
|
-
* @param {string} origin - Origin
|
|
64
|
-
* @returns {PoolEntry|undefined} A
|
|
47
|
+
* @param {string} origin - Origin to look up.
|
|
48
|
+
* @returns {PoolEntry|undefined} A pool entry, or `undefined` if none is available.
|
|
65
49
|
*/
|
|
66
50
|
get(origin: string): PoolEntry | undefined;
|
|
67
51
|
/**
|
|
68
|
-
*
|
|
69
|
-
* the per-origin limit, the oldest entry for that origin is evicted. If the
|
|
70
|
-
* total connection limit has been reached, the globally least-recently-used
|
|
71
|
-
* idle connection is evicted first.
|
|
52
|
+
* Add a new connection to the pool.
|
|
72
53
|
*
|
|
73
|
-
* @param {string}
|
|
74
|
-
* @param {TLSSocket}
|
|
75
|
-
* @param {
|
|
76
|
-
* @param {H2Profile}
|
|
77
|
-
* @param {Array<[string,string]>} [defaultHeaders] - Default headers
|
|
78
|
-
* @returns {PoolEntry} The
|
|
54
|
+
* @param {string} origin - Origin key.
|
|
55
|
+
* @param {TLSSocket} socket - TLS socket.
|
|
56
|
+
* @param {"h1"|"h2"|"h3"} protocol - Negotiated protocol.
|
|
57
|
+
* @param {H2Profile} [h2Profile] - Optional HTTP/2 profile for h2 connections.
|
|
58
|
+
* @param {Array<[string, string]>} [defaultHeaders] - Default headers for h2 connections.
|
|
59
|
+
* @returns {PoolEntry} The created pool entry.
|
|
79
60
|
*/
|
|
80
|
-
put(origin: string, socket: TLSSocket, protocol: "h1" | "h2", h2Profile?: H2Profile, defaultHeaders?: Array<[string, string]>): PoolEntry;
|
|
61
|
+
put(origin: string, socket: TLSSocket, protocol: "h1" | "h2" | "h3", h2Profile?: H2Profile, defaultHeaders?: Array<[string, string]>): PoolEntry;
|
|
81
62
|
/**
|
|
82
|
-
*
|
|
83
|
-
* completed. Updates the `lastUsed` timestamp.
|
|
63
|
+
* Mark a connection as idle and available for reuse.
|
|
84
64
|
*
|
|
85
|
-
* @param {PoolEntry} entry -
|
|
65
|
+
* @param {PoolEntry} entry - Pool entry to release.
|
|
86
66
|
*/
|
|
87
67
|
release(entry: PoolEntry): void;
|
|
88
68
|
/**
|
|
89
|
-
*
|
|
90
|
-
* Typically called when a connection error has occurred or the server
|
|
91
|
-
* sent a `Connection: close` header.
|
|
69
|
+
* Remove a connection from the pool and destroy its socket.
|
|
92
70
|
*
|
|
93
|
-
* @param {PoolEntry} entry -
|
|
71
|
+
* @param {PoolEntry} entry - Pool entry to remove.
|
|
94
72
|
*/
|
|
95
73
|
remove(entry: PoolEntry): void;
|
|
96
|
-
/**
|
|
97
|
-
* Destroys all pooled connections and stops the idle-eviction timer.
|
|
98
|
-
* The pool must not be used after this call.
|
|
99
|
-
*/
|
|
74
|
+
/** Close all pooled connections and stop the cleanup timer. */
|
|
100
75
|
close(): void;
|
|
101
|
-
/**
|
|
102
|
-
* Returns the total number of connections (both idle and busy) currently held
|
|
103
|
-
* in the pool across all origins.
|
|
104
|
-
*
|
|
105
|
-
* @returns {number} Total pooled connection count.
|
|
106
|
-
*/
|
|
76
|
+
/** Total number of connections across all origins. */
|
|
107
77
|
get size(): number;
|
|
108
78
|
private isExpired;
|
|
109
79
|
private evictIdle;
|
package/dist/http/pool.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pool.d.ts","sourceRoot":"","sources":["../../src/http/pool.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,
|
|
1
|
+
{"version":3,"file":"pool.d.ts","sourceRoot":"","sources":["../../src/http/pool.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MA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AAE,SAAS,EAAE,cAAc,CAAC,EAAE,KAAK,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GAAG,SAAS;IAsChJ;;;;OAIG;IACH,OAAO,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI;IAK/B;;;;OAIG;IACH,MAAM,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI;IAe9B,+DAA+D;IAC/D,KAAK,IAAI,IAAI;IAgBb,sDAAsD;IACtD,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,OAAO,CAAC,SAAS;IAMjB,OAAO,CAAC,SAAS;IAkBjB,OAAO,CAAC,WAAW;CAiBpB"}
|
package/dist/http/pool.js
CHANGED
|
@@ -5,36 +5,31 @@ const DEFAULT_POOL_OPTIONS = {
|
|
|
5
5
|
idleTimeout: 60_000,
|
|
6
6
|
maxAge: 300_000,
|
|
7
7
|
};
|
|
8
|
-
/**
|
|
9
|
-
* Maintains a pool of reusable TLS connections, keyed by origin, supporting
|
|
10
|
-
* both HTTP/1.1 (exclusive per-request access) and HTTP/2 (multiplexed)
|
|
11
|
-
* connections. Idle and expired connections are evicted automatically on a
|
|
12
|
-
* 30-second timer.
|
|
13
|
-
*/
|
|
8
|
+
/** HTTP connection pool with idle eviction and per-origin limits. */
|
|
14
9
|
export class ConnectionPool {
|
|
15
10
|
options;
|
|
16
11
|
connections = new Map();
|
|
17
12
|
totalConnections = 0;
|
|
18
13
|
cleanupTimer;
|
|
19
14
|
/**
|
|
20
|
-
*
|
|
15
|
+
* Create a new connection pool.
|
|
21
16
|
*
|
|
22
|
-
* @param {PoolOptions} [options
|
|
17
|
+
* @param {PoolOptions} [options] - Pool configuration.
|
|
23
18
|
*/
|
|
24
19
|
constructor(options = {}) {
|
|
25
20
|
this.options = { ...DEFAULT_POOL_OPTIONS, ...options };
|
|
26
|
-
this.cleanupTimer = setInterval(() =>
|
|
21
|
+
this.cleanupTimer = setInterval(() => {
|
|
22
|
+
this.evictIdle();
|
|
23
|
+
}, 30_000);
|
|
27
24
|
if (this.cleanupTimer.unref) {
|
|
28
25
|
this.cleanupTimer.unref();
|
|
29
26
|
}
|
|
30
27
|
}
|
|
31
28
|
/**
|
|
32
|
-
*
|
|
33
|
-
* any live connection (multiplexing); for HTTP/1.1 returns a non-busy,
|
|
34
|
-
* non-expired connection and marks it busy.
|
|
29
|
+
* Get an available connection for the given origin.
|
|
35
30
|
*
|
|
36
|
-
* @param {string} origin - Origin
|
|
37
|
-
* @returns {PoolEntry|undefined} A
|
|
31
|
+
* @param {string} origin - Origin to look up.
|
|
32
|
+
* @returns {PoolEntry|undefined} A pool entry, or `undefined` if none is available.
|
|
38
33
|
*/
|
|
39
34
|
get(origin) {
|
|
40
35
|
const entries = this.connections.get(origin);
|
|
@@ -58,17 +53,14 @@ export class ConnectionPool {
|
|
|
58
53
|
return undefined;
|
|
59
54
|
}
|
|
60
55
|
/**
|
|
61
|
-
*
|
|
62
|
-
* the per-origin limit, the oldest entry for that origin is evicted. If the
|
|
63
|
-
* total connection limit has been reached, the globally least-recently-used
|
|
64
|
-
* idle connection is evicted first.
|
|
56
|
+
* Add a new connection to the pool.
|
|
65
57
|
*
|
|
66
|
-
* @param {string}
|
|
67
|
-
* @param {TLSSocket}
|
|
68
|
-
* @param {
|
|
69
|
-
* @param {H2Profile}
|
|
70
|
-
* @param {Array<[string,string]>} [defaultHeaders] - Default headers
|
|
71
|
-
* @returns {PoolEntry} The
|
|
58
|
+
* @param {string} origin - Origin key.
|
|
59
|
+
* @param {TLSSocket} socket - TLS socket.
|
|
60
|
+
* @param {"h1"|"h2"|"h3"} protocol - Negotiated protocol.
|
|
61
|
+
* @param {H2Profile} [h2Profile] - Optional HTTP/2 profile for h2 connections.
|
|
62
|
+
* @param {Array<[string, string]>} [defaultHeaders] - Default headers for h2 connections.
|
|
63
|
+
* @returns {PoolEntry} The created pool entry.
|
|
72
64
|
*/
|
|
73
65
|
put(origin, socket, protocol, h2Profile, defaultHeaders) {
|
|
74
66
|
if (this.totalConnections >= this.options.maxTotalConnections) {
|
|
@@ -102,21 +94,18 @@ export class ConnectionPool {
|
|
|
102
94
|
return entry;
|
|
103
95
|
}
|
|
104
96
|
/**
|
|
105
|
-
*
|
|
106
|
-
* completed. Updates the `lastUsed` timestamp.
|
|
97
|
+
* Mark a connection as idle and available for reuse.
|
|
107
98
|
*
|
|
108
|
-
* @param {PoolEntry} entry -
|
|
99
|
+
* @param {PoolEntry} entry - Pool entry to release.
|
|
109
100
|
*/
|
|
110
101
|
release(entry) {
|
|
111
102
|
entry.busy = false;
|
|
112
103
|
entry.lastUsed = Date.now();
|
|
113
104
|
}
|
|
114
105
|
/**
|
|
115
|
-
*
|
|
116
|
-
* Typically called when a connection error has occurred or the server
|
|
117
|
-
* sent a `Connection: close` header.
|
|
106
|
+
* Remove a connection from the pool and destroy its socket.
|
|
118
107
|
*
|
|
119
|
-
* @param {PoolEntry} entry -
|
|
108
|
+
* @param {PoolEntry} entry - Pool entry to remove.
|
|
120
109
|
*/
|
|
121
110
|
remove(entry) {
|
|
122
111
|
const entries = this.connections.get(entry.origin);
|
|
@@ -132,10 +121,7 @@ export class ConnectionPool {
|
|
|
132
121
|
}
|
|
133
122
|
entry.socket.destroyTLS();
|
|
134
123
|
}
|
|
135
|
-
/**
|
|
136
|
-
* Destroys all pooled connections and stops the idle-eviction timer.
|
|
137
|
-
* The pool must not be used after this call.
|
|
138
|
-
*/
|
|
124
|
+
/** Close all pooled connections and stop the cleanup timer. */
|
|
139
125
|
close() {
|
|
140
126
|
if (this.cleanupTimer) {
|
|
141
127
|
clearInterval(this.cleanupTimer);
|
|
@@ -151,12 +137,7 @@ export class ConnectionPool {
|
|
|
151
137
|
this.connections.clear();
|
|
152
138
|
this.totalConnections = 0;
|
|
153
139
|
}
|
|
154
|
-
/**
|
|
155
|
-
* Returns the total number of connections (both idle and busy) currently held
|
|
156
|
-
* in the pool across all origins.
|
|
157
|
-
*
|
|
158
|
-
* @returns {number} Total pooled connection count.
|
|
159
|
-
*/
|
|
140
|
+
/** Total number of connections across all origins. */
|
|
160
141
|
get size() {
|
|
161
142
|
return this.totalConnections;
|
|
162
143
|
}
|
package/dist/http/pool.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pool.js","sourceRoot":"","sources":["../../src/http/pool.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"pool.js","sourceRoot":"","sources":["../../src/http/pool.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAiC1C,MAAM,oBAAoB,GAA0B;IAClD,uBAAuB,EAAE,CAAC;IAC1B,mBAAmB,EAAE,EAAE;IACvB,WAAW,EAAE,MAAM;IACnB,MAAM,EAAE,OAAO;CAChB,CAAC;AAEF,qEAAqE;AACrE,MAAM,OAAO,cAAc;IACR,OAAO,CAAwB;IAC/B,WAAW,GAAG,IAAI,GAAG,EAAuB,CAAC;IACtD,gBAAgB,GAAG,CAAC,CAAC;IACrB,YAAY,CAA6C;IAEjE;;;;OAIG;IACH,YAAY,UAAuB,EAAE;QACnC,IAAI,CAAC,OAAO,GAAG,EAAE,GAAG,oBAAoB,EAAE,GAAG,OAAO,EAAE,CAAC;QACvD,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC,GAAG,EAAE;YACnC,IAAI,CAAC,SAAS,EAAE,CAAC;QACnB,CAAC,EAAE,MAAM,CAAC,CAAC;QACX,IAAI,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,CAAC;YAC5B,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,CAAC;QAC5B,CAAC;IACH,CAAC;IAED;;;;;OAKG;IACH,GAAG,CAAC,MAAc;QAChB,MAAM,OAAO,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAC7C,IAAI,CAAC,OAAO;YAAE,OAAO,SAAS,CAAC;QAE/B,MAAM,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|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/** State of a resumable upload session. */
|
|
2
|
+
export interface UploadSession {
|
|
3
|
+
/** Server-assigned upload URL. */
|
|
4
|
+
uploadUrl: string;
|
|
5
|
+
/** Number of bytes already uploaded. */
|
|
6
|
+
offset: number;
|
|
7
|
+
/** Total size of the upload in bytes. */
|
|
8
|
+
totalSize: number;
|
|
9
|
+
/** Whether the upload has been completed. */
|
|
10
|
+
complete: boolean;
|
|
11
|
+
/** Timestamp when the session was created. */
|
|
12
|
+
createdAt: number;
|
|
13
|
+
}
|
|
14
|
+
/** Configuration for resumable upload operations. */
|
|
15
|
+
export interface ResumableUploadConfig {
|
|
16
|
+
/** Size of each upload chunk in bytes. */
|
|
17
|
+
chunkSize?: number;
|
|
18
|
+
/** Maximum number of retry attempts per chunk. */
|
|
19
|
+
maxRetries?: number;
|
|
20
|
+
/** Progress callback invoked after each chunk. */
|
|
21
|
+
onProgress?: (offset: number, total: number) => void;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Build headers for initiating a new resumable upload.
|
|
25
|
+
*
|
|
26
|
+
* @param {number} totalSize - Total upload size in bytes.
|
|
27
|
+
* @param {string} [contentType] - MIME type of the upload content.
|
|
28
|
+
* @returns {Record<string, string>} Header record for the upload creation request.
|
|
29
|
+
*/
|
|
30
|
+
export declare function buildUploadCreationHeaders(totalSize: number, contentType?: string): Record<string, string>;
|
|
31
|
+
/**
|
|
32
|
+
* Build headers for resuming an upload at a given offset.
|
|
33
|
+
*
|
|
34
|
+
* @param {number} offset - Byte offset to resume from.
|
|
35
|
+
* @param {number} chunkSize - Size of the chunk being sent.
|
|
36
|
+
* @param {boolean} isLast - Whether this is the final chunk.
|
|
37
|
+
* @returns {Record<string, string>} Header record for the resume request.
|
|
38
|
+
*/
|
|
39
|
+
export declare function buildUploadResumeHeaders(offset: number, chunkSize: number, isLast: boolean): Record<string, string>;
|
|
40
|
+
/**
|
|
41
|
+
* Build headers for querying the current upload offset.
|
|
42
|
+
*
|
|
43
|
+
* @returns {Record<string, string>} Header record for the offset query request.
|
|
44
|
+
*/
|
|
45
|
+
export declare function buildUploadOffsetHeaders(): Record<string, string>;
|
|
46
|
+
/**
|
|
47
|
+
* Parse the upload offset from response headers.
|
|
48
|
+
*
|
|
49
|
+
* @param {Record<string, string>} headers - Response headers.
|
|
50
|
+
* @returns {number} Byte offset, or -1 if not present or invalid.
|
|
51
|
+
*/
|
|
52
|
+
export declare function parseUploadOffset(headers: Record<string, string>): number;
|
|
53
|
+
/**
|
|
54
|
+
* Check whether the upload is marked as complete in response headers.
|
|
55
|
+
*
|
|
56
|
+
* @param {Record<string, string>} headers - Response headers.
|
|
57
|
+
* @returns {boolean} `true` if the upload-complete header is "?1".
|
|
58
|
+
*/
|
|
59
|
+
export declare function isUploadComplete(headers: Record<string, string>): boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Split a buffer into offset-chunk pairs for resumable upload.
|
|
62
|
+
*
|
|
63
|
+
* @param {Buffer} data - Data to split.
|
|
64
|
+
* @param {number} [chunkSize] - Maximum chunk size in bytes.
|
|
65
|
+
* @returns {Array<[number, Buffer]>} Array of [offset, chunk] tuples.
|
|
66
|
+
*/
|
|
67
|
+
export declare function splitIntoChunks(data: Buffer, chunkSize?: number): Array<[number, Buffer]>;
|
|
68
|
+
/**
|
|
69
|
+
* Extract the upload URL from response headers.
|
|
70
|
+
*
|
|
71
|
+
* @param {Record<string, string>} headers - Response headers.
|
|
72
|
+
* @param {string} requestUrl - Original request URL for resolving relative locations.
|
|
73
|
+
* @returns {string | null} Absolute upload URL, or `null` if not present.
|
|
74
|
+
*/
|
|
75
|
+
export declare function parseUploadUrl(headers: Record<string, string>, requestUrl: string): string | null;
|
|
76
|
+
//# sourceMappingURL=resumable-upload.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resumable-upload.d.ts","sourceRoot":"","sources":["../../src/http/resumable-upload.ts"],"names":[],"mappings":"AAAA,2CAA2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CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAUzF;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAQjG"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
const DEFAULT_CHUNK_SIZE = 5 * 1024 * 1024;
|
|
2
|
+
const UPLOAD_CONTENT_TYPE = "application/partial-upload";
|
|
3
|
+
/**
|
|
4
|
+
* Build headers for initiating a new resumable upload.
|
|
5
|
+
*
|
|
6
|
+
* @param {number} totalSize - Total upload size in bytes.
|
|
7
|
+
* @param {string} [contentType] - MIME type of the upload content.
|
|
8
|
+
* @returns {Record<string, string>} Header record for the upload creation request.
|
|
9
|
+
*/
|
|
10
|
+
export function buildUploadCreationHeaders(totalSize, contentType) {
|
|
11
|
+
return {
|
|
12
|
+
"upload-complete": "?0",
|
|
13
|
+
"upload-draft-interop-version": "7",
|
|
14
|
+
"content-type": contentType ?? "application/octet-stream",
|
|
15
|
+
"content-length": String(totalSize),
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Build headers for resuming an upload at a given offset.
|
|
20
|
+
*
|
|
21
|
+
* @param {number} offset - Byte offset to resume from.
|
|
22
|
+
* @param {number} chunkSize - Size of the chunk being sent.
|
|
23
|
+
* @param {boolean} isLast - Whether this is the final chunk.
|
|
24
|
+
* @returns {Record<string, string>} Header record for the resume request.
|
|
25
|
+
*/
|
|
26
|
+
export function buildUploadResumeHeaders(offset, chunkSize, isLast) {
|
|
27
|
+
return {
|
|
28
|
+
"upload-offset": String(offset),
|
|
29
|
+
"upload-complete": isLast ? "?1" : "?0",
|
|
30
|
+
"upload-draft-interop-version": "7",
|
|
31
|
+
"content-type": UPLOAD_CONTENT_TYPE,
|
|
32
|
+
"content-length": String(chunkSize),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Build headers for querying the current upload offset.
|
|
37
|
+
*
|
|
38
|
+
* @returns {Record<string, string>} Header record for the offset query request.
|
|
39
|
+
*/
|
|
40
|
+
export function buildUploadOffsetHeaders() {
|
|
41
|
+
return {
|
|
42
|
+
"upload-draft-interop-version": "7",
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Parse the upload offset from response headers.
|
|
47
|
+
*
|
|
48
|
+
* @param {Record<string, string>} headers - Response headers.
|
|
49
|
+
* @returns {number} Byte offset, or -1 if not present or invalid.
|
|
50
|
+
*/
|
|
51
|
+
export function parseUploadOffset(headers) {
|
|
52
|
+
const val = headers["upload-offset"];
|
|
53
|
+
if (!val)
|
|
54
|
+
return -1;
|
|
55
|
+
const offset = parseInt(val, 10);
|
|
56
|
+
return Number.isFinite(offset) && offset >= 0 ? offset : -1;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Check whether the upload is marked as complete in response headers.
|
|
60
|
+
*
|
|
61
|
+
* @param {Record<string, string>} headers - Response headers.
|
|
62
|
+
* @returns {boolean} `true` if the upload-complete header is "?1".
|
|
63
|
+
*/
|
|
64
|
+
export function isUploadComplete(headers) {
|
|
65
|
+
const val = headers["upload-complete"];
|
|
66
|
+
return val === "?1";
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Split a buffer into offset-chunk pairs for resumable upload.
|
|
70
|
+
*
|
|
71
|
+
* @param {Buffer} data - Data to split.
|
|
72
|
+
* @param {number} [chunkSize] - Maximum chunk size in bytes.
|
|
73
|
+
* @returns {Array<[number, Buffer]>} Array of [offset, chunk] tuples.
|
|
74
|
+
*/
|
|
75
|
+
export function splitIntoChunks(data, chunkSize) {
|
|
76
|
+
const size = chunkSize ?? DEFAULT_CHUNK_SIZE;
|
|
77
|
+
const chunks = [];
|
|
78
|
+
let offset = 0;
|
|
79
|
+
while (offset < data.length) {
|
|
80
|
+
const end = Math.min(offset + size, data.length);
|
|
81
|
+
chunks.push([offset, data.subarray(offset, end)]);
|
|
82
|
+
offset = end;
|
|
83
|
+
}
|
|
84
|
+
return chunks;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Extract the upload URL from response headers.
|
|
88
|
+
*
|
|
89
|
+
* @param {Record<string, string>} headers - Response headers.
|
|
90
|
+
* @param {string} requestUrl - Original request URL for resolving relative locations.
|
|
91
|
+
* @returns {string | null} Absolute upload URL, or `null` if not present.
|
|
92
|
+
*/
|
|
93
|
+
export function parseUploadUrl(headers, requestUrl) {
|
|
94
|
+
const location = headers["location"];
|
|
95
|
+
if (!location)
|
|
96
|
+
return null;
|
|
97
|
+
try {
|
|
98
|
+
return new URL(location, requestUrl).href;
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=resumable-upload.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resumable-upload.js","sourceRoot":"","sources":["../../src/http/resumable-upload.ts"],"names":[],"mappings":"AAwBA,MAAM,kBAAkB,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;AAC3C,MAAM,mBAAmB,GAAG,4BAA4B,CAAC;AAEzD;;;;;;GAMG;AACH,MAAM,UAAU,0BAA0B,CAAC,SAAiB,EAAE,WAAoB;IAChF,OAAO;QACL,iBAAiB,EAAE,IAAI;QACvB,8BAA8B,EAAE,GAAG;QACnC,cAAc,EAAE,WAAW,IAAI,0BAA0B;QACzD,gBAAgB,EAAE,MAAM,CAAC,SAAS,CAAC;KACpC,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,wBAAwB,CAAC,MAAc,EAAE,SAAiB,EAAE,MAAe;IACzF,OAAO;QACL,eAAe,EAAE,MAAM,CAAC,MAAM,CAAC;QAC/B,iBAAiB,EAAE,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI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MAAM,GAAG,GAAG,CAAC;IACf,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAAC,OAA+B,EAAE,UAAkB;IAChF,MAAM,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IACrC,IAAI,CAAC,QAAQ;QAAE,OAAO,IAAI,CAAC;IAC3B,IAAI,CAAC;QACH,OAAO,IAAI,GAAG,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC,IAAI,CAAC;IAC5C,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check whether a header name is allowed as an HTTP trailer field.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} name - Header field name.
|
|
5
|
+
* @returns {boolean} `true` if the name is not in the forbidden trailer fields set.
|
|
6
|
+
*/
|
|
7
|
+
export declare function isValidTrailerField(name: string): boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Serialize trailer fields into a wire-format buffer.
|
|
10
|
+
*
|
|
11
|
+
* @param {Record<string, string>} trailers - Key-value pairs of trailer fields.
|
|
12
|
+
* @returns {Buffer} CRLF-delimited buffer of valid trailer fields.
|
|
13
|
+
*/
|
|
14
|
+
export declare function serializeTrailers(trailers: Record<string, string>): Buffer;
|
|
15
|
+
/**
|
|
16
|
+
* Parse trailer field data into a key-value record.
|
|
17
|
+
*
|
|
18
|
+
* @param {Buffer} data - Raw trailer data buffer.
|
|
19
|
+
* @returns {Record<string, string>} Parsed trailer fields keyed by lowercase name.
|
|
20
|
+
*/
|
|
21
|
+
export declare function parseTrailers(data: Buffer): Record<string, string>;
|
|
22
|
+
/**
|
|
23
|
+
* Build a Trailer header value listing the trailer field names.
|
|
24
|
+
*
|
|
25
|
+
* @param {string[]} fieldNames - Trailer field names to advertise.
|
|
26
|
+
* @returns {string} Comma-separated string of valid trailer field names.
|
|
27
|
+
*/
|
|
28
|
+
export declare function buildTrailerHeader(fieldNames: string[]): string;
|
|
29
|
+
//# sourceMappingURL=trailers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trailers.d.ts","sourceRoot":"","sources":["../../src/http/trailers.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEzD;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAQ1E;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAclE;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,MAAM,CAE/D"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
const FORBIDDEN_TRAILER_FIELDS = new Set(["transfer-encoding", "content-length", "host", "cache-control", "expect", "max-forwards", "pragma", "range", "te", "authorization", "content-encoding", "content-range", "content-type", "trailer", "set-cookie"]);
|
|
2
|
+
/**
|
|
3
|
+
* Check whether a header name is allowed as an HTTP trailer field.
|
|
4
|
+
*
|
|
5
|
+
* @param {string} name - Header field name.
|
|
6
|
+
* @returns {boolean} `true` if the name is not in the forbidden trailer fields set.
|
|
7
|
+
*/
|
|
8
|
+
export function isValidTrailerField(name) {
|
|
9
|
+
return !FORBIDDEN_TRAILER_FIELDS.has(name.toLowerCase());
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Serialize trailer fields into a wire-format buffer.
|
|
13
|
+
*
|
|
14
|
+
* @param {Record<string, string>} trailers - Key-value pairs of trailer fields.
|
|
15
|
+
* @returns {Buffer} CRLF-delimited buffer of valid trailer fields.
|
|
16
|
+
*/
|
|
17
|
+
export function serializeTrailers(trailers) {
|
|
18
|
+
const lines = [];
|
|
19
|
+
for (const [name, value] of Object.entries(trailers)) {
|
|
20
|
+
if (isValidTrailerField(name)) {
|
|
21
|
+
lines.push(`${name}: ${value}`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return Buffer.from(lines.join("\r\n") + "\r\n", "ascii");
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Parse trailer field data into a key-value record.
|
|
28
|
+
*
|
|
29
|
+
* @param {Buffer} data - Raw trailer data buffer.
|
|
30
|
+
* @returns {Record<string, string>} Parsed trailer fields keyed by lowercase name.
|
|
31
|
+
*/
|
|
32
|
+
export function parseTrailers(data) {
|
|
33
|
+
const trailers = {};
|
|
34
|
+
const text = data.toString("ascii");
|
|
35
|
+
const lines = text.split("\r\n");
|
|
36
|
+
for (const line of lines) {
|
|
37
|
+
const colonIdx = line.indexOf(":");
|
|
38
|
+
if (colonIdx < 0)
|
|
39
|
+
continue;
|
|
40
|
+
const name = line.substring(0, colonIdx).trim().toLowerCase();
|
|
41
|
+
const value = line.substring(colonIdx + 1).trim();
|
|
42
|
+
if (name && isValidTrailerField(name)) {
|
|
43
|
+
trailers[name] = value;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return trailers;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Build a Trailer header value listing the trailer field names.
|
|
50
|
+
*
|
|
51
|
+
* @param {string[]} fieldNames - Trailer field names to advertise.
|
|
52
|
+
* @returns {string} Comma-separated string of valid trailer field names.
|
|
53
|
+
*/
|
|
54
|
+
export function buildTrailerHeader(fieldNames) {
|
|
55
|
+
return fieldNames.filter(isValidTrailerField).join(", ");
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=trailers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trailers.js","sourceRoot":"","sources":["../../src/http/trailers.ts"],"names":[],"mappings":"AAAA,MAAM,wBAAwB,GAAG,IAAI,GA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