nlcurl 0.7.0 → 0.9.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 +149 -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 +75 -37
- package/dist/cache/store.d.ts.map +1 -1
- package/dist/cache/store.js +217 -85
- package/dist/cache/store.js.map +1 -1
- package/dist/cache/types.d.ts +10 -39
- package/dist/cache/types.d.ts.map +1 -1
- 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 +41 -40
- package/dist/cookies/jar.d.ts.map +1 -1
- package/dist/cookies/jar.js +65 -42
- package/dist/cookies/jar.js.map +1 -1
- package/dist/cookies/parser.d.ts +13 -17
- package/dist/cookies/parser.d.ts.map +1 -1
- package/dist/cookies/parser.js +23 -15
- 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 +61 -0
- package/dist/core/auth.d.ts.map +1 -0
- package/dist/core/auth.js +159 -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 +31 -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 +33 -113
- package/dist/core/request.d.ts.map +1 -1
- package/dist/core/response.d.ts +49 -66
- package/dist/core/response.d.ts.map +1 -1
- package/dist/core/response.js +45 -59
- package/dist/core/response.js.map +1 -1
- package/dist/core/session.d.ts +66 -78
- package/dist/core/session.d.ts.map +1 -1
- package/dist/core/session.js +136 -77
- package/dist/core/session.js.map +1 -1
- package/dist/core/validation.d.ts +58 -43
- package/dist/core/validation.d.ts.map +1 -1
- package/dist/core/validation.js +141 -56
- package/dist/core/validation.js.map +1 -1
- package/dist/dns/cache.d.ts +65 -0
- package/dist/dns/cache.d.ts.map +1 -0
- package/dist/dns/cache.js +119 -0
- package/dist/dns/cache.js.map +1 -0
- package/dist/dns/codec.d.ts +29 -19
- package/dist/dns/codec.d.ts.map +1 -1
- package/dist/dns/codec.js +73 -39
- package/dist/dns/codec.js.map +1 -1
- package/dist/dns/doh-resolver.d.ts +17 -31
- package/dist/dns/doh-resolver.d.ts.map +1 -1
- package/dist/dns/doh-resolver.js +47 -48
- package/dist/dns/doh-resolver.js.map +1 -1
- 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 +166 -0
- package/dist/dns/dot-resolver.js.map +1 -0
- package/dist/dns/https-rr.d.ts +19 -30
- package/dist/dns/https-rr.d.ts.map +1 -1
- package/dist/dns/https-rr.js +22 -40
- package/dist/dns/https-rr.js.map +1 -1
- package/dist/dns/types.d.ts +31 -59
- package/dist/dns/types.d.ts.map +1 -1
- package/dist/dns/types.js +3 -14
- package/dist/dns/types.js.map +1 -1
- 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 +81 -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 +19 -21
- package/dist/hsts/store.d.ts.map +1 -1
- package/dist/hsts/store.js +20 -28
- package/dist/hsts/store.js.map +1 -1
- package/dist/hsts/types.d.ts +10 -14
- package/dist/hsts/types.d.ts.map +1 -1
- package/dist/http/alt-svc.d.ts +27 -52
- package/dist/http/alt-svc.d.ts.map +1 -1
- package/dist/http/alt-svc.js +17 -67
- package/dist/http/alt-svc.js.map +1 -1
- 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 +14 -23
- package/dist/http/h1/client.js.map +1 -1
- package/dist/http/h1/encoder.d.ts +21 -17
- package/dist/http/h1/encoder.d.ts.map +1 -1
- package/dist/http/h1/encoder.js +56 -20
- package/dist/http/h1/encoder.js.map +1 -1
- package/dist/http/h1/parser.d.ts +23 -59
- package/dist/http/h1/parser.d.ts.map +1 -1
- package/dist/http/h1/parser.js +61 -55
- package/dist/http/h1/parser.js.map +1 -1
- package/dist/http/h2/client.d.ts +23 -59
- package/dist/http/h2/client.d.ts.map +1 -1
- package/dist/http/h2/client.js +107 -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 +20 -36
- package/dist/http/h2/hpack.d.ts.map +1 -1
- package/dist/http/h2/hpack.js +41 -36
- package/dist/http/h2/hpack.js.map +1 -1
- package/dist/http/negotiator.d.ts +25 -38
- package/dist/http/negotiator.d.ts.map +1 -1
- package/dist/http/negotiator.js +17 -38
- 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 +24 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +24 -3
- package/dist/index.js.map +1 -1
- package/dist/middleware/circuit-breaker.d.ts +44 -0
- package/dist/middleware/circuit-breaker.d.ts.map +1 -0
- package/dist/middleware/circuit-breaker.js +96 -0
- package/dist/middleware/circuit-breaker.js.map +1 -0
- 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 +11 -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 +129 -0
- package/dist/proxy/auth.js.map +1 -0
- package/dist/proxy/env-proxy.d.ts +5 -15
- package/dist/proxy/env-proxy.d.ts.map +1 -1
- package/dist/proxy/env-proxy.js +5 -23
- package/dist/proxy/env-proxy.js.map +1 -1
- package/dist/proxy/http-proxy.d.ts +12 -19
- package/dist/proxy/http-proxy.d.ts.map +1 -1
- package/dist/proxy/http-proxy.js +5 -8
- 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 +8 -10
- package/dist/proxy/socks.js.map +1 -1
- package/dist/sse/parser.d.ts +16 -37
- package/dist/sse/parser.d.ts.map +1 -1
- package/dist/sse/parser.js +31 -28
- package/dist/sse/parser.js.map +1 -1
- package/dist/tls/constants.d.ts +21 -72
- package/dist/tls/constants.d.ts.map +1 -1
- package/dist/tls/constants.js +21 -72
- 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 +68 -85
- package/dist/tls/ech.d.ts.map +1 -1
- package/dist/tls/ech.js +54 -102
- package/dist/tls/ech.js.map +1 -1
- 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 +10 -17
- package/dist/tls/node-engine.d.ts.map +1 -1
- package/dist/tls/node-engine.js +41 -18
- 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 +5 -4
- package/dist/tls/pin-verification.d.ts.map +1 -1
- package/dist/tls/pin-verification.js +5 -11
- package/dist/tls/pin-verification.js.map +1 -1
- package/dist/tls/session-cache.d.ts +27 -39
- package/dist/tls/session-cache.d.ts.map +1 -1
- package/dist/tls/session-cache.js +20 -24
- package/dist/tls/session-cache.js.map +1 -1
- package/dist/tls/stealth/client-hello.d.ts +26 -45
- package/dist/tls/stealth/client-hello.d.ts.map +1 -1
- package/dist/tls/stealth/client-hello.js +15 -31
- package/dist/tls/stealth/client-hello.js.map +1 -1
- package/dist/tls/stealth/engine.d.ts +10 -15
- package/dist/tls/stealth/engine.d.ts.map +1 -1
- package/dist/tls/stealth/engine.js +98 -18
- package/dist/tls/stealth/engine.js.map +1 -1
- package/dist/tls/stealth/handshake.d.ts +32 -31
- package/dist/tls/stealth/handshake.d.ts.map +1 -1
- package/dist/tls/stealth/handshake.js +74 -47
- package/dist/tls/stealth/handshake.js.map +1 -1
- package/dist/tls/stealth/key-schedule.d.ts +81 -86
- package/dist/tls/stealth/key-schedule.d.ts.map +1 -1
- package/dist/tls/stealth/key-schedule.js +70 -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 +16 -0
- package/dist/tls/stealth/tls12-handshake.d.ts.map +1 -1
- package/dist/tls/stealth/tls12-handshake.js +10 -2
- package/dist/tls/stealth/tls12-handshake.js.map +1 -1
- package/dist/tls/types.d.ts +46 -60
- 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 -30
- package/dist/utils/encoding.d.ts.map +1 -1
- package/dist/utils/encoding.js +15 -46
- package/dist/utils/encoding.js.map +1 -1
- package/dist/utils/happy-eyeballs.d.ts +18 -8
- package/dist/utils/happy-eyeballs.d.ts.map +1 -1
- package/dist/utils/happy-eyeballs.js +19 -27
- 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 -53
- package/dist/ws/client.d.ts.map +1 -1
- package/dist/ws/client.js +96 -38
- package/dist/ws/client.js.map +1 -1
- package/dist/ws/frame.d.ts +24 -41
- package/dist/ws/frame.d.ts.map +1 -1
- package/dist/ws/frame.js +26 -33
- package/dist/ws/frame.js.map +1 -1
- package/dist/ws/permessage-deflate.d.ts +23 -28
- package/dist/ws/permessage-deflate.d.ts.map +1 -1
- package/dist/ws/permessage-deflate.js +18 -26
- package/dist/ws/permessage-deflate.js.map +1 -1
- package/package.json +2 -2
- package/dist/http/h3/detection.d.ts +0 -17
- package/dist/http/h3/detection.d.ts.map +0 -1
- package/dist/http/h3/detection.js +0 -59
- package/dist/http/h3/detection.js.map +0 -1
package/dist/hsts/store.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* In-memory HSTS policy store implementing RFC 6797.
|
|
3
|
-
*
|
|
4
|
-
* Parses `Strict-Transport-Security` response headers, stores per-host policies,
|
|
5
|
-
* and upgrades `http://` URLs to `https://` when an active policy matches.
|
|
6
|
-
*/
|
|
1
|
+
/** Store for HTTP Strict Transport Security policies. */
|
|
7
2
|
export class HSTSStore {
|
|
8
3
|
policies = new Map();
|
|
4
|
+
/**
|
|
5
|
+
* Create a new HSTS store.
|
|
6
|
+
*
|
|
7
|
+
* @param {HSTSConfig} [config] - Optional HSTS configuration with preload entries.
|
|
8
|
+
*/
|
|
9
9
|
constructor(config) {
|
|
10
10
|
if (config?.preload) {
|
|
11
11
|
for (const entry of config.preload) {
|
|
@@ -13,9 +13,6 @@ export class HSTSStore {
|
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
|
-
/**
|
|
17
|
-
* Seeds a preload entry with a very long max-age (20 years).
|
|
18
|
-
*/
|
|
19
16
|
addPreload(entry) {
|
|
20
17
|
const host = canonicalizeHost(entry.host);
|
|
21
18
|
if (!host)
|
|
@@ -27,13 +24,11 @@ export class HSTSStore {
|
|
|
27
24
|
});
|
|
28
25
|
}
|
|
29
26
|
/**
|
|
30
|
-
*
|
|
31
|
-
* Only processes headers received over a secure (HTTPS) connection, as
|
|
32
|
-
* required by RFC 6797 §8.1.
|
|
27
|
+
* Parse a Strict-Transport-Security response header and store the policy.
|
|
33
28
|
*
|
|
34
|
-
* @param host
|
|
35
|
-
* @param value
|
|
36
|
-
* @param isSecure - Whether the response was
|
|
29
|
+
* @param {string} host - Origin hostname.
|
|
30
|
+
* @param {string} value - Raw Strict-Transport-Security header value.
|
|
31
|
+
* @param {boolean} isSecure - Whether the response was delivered over a secure transport.
|
|
37
32
|
*/
|
|
38
33
|
parseHeader(host, value, isSecure) {
|
|
39
34
|
if (!isSecure)
|
|
@@ -61,8 +56,10 @@ export class HSTSStore {
|
|
|
61
56
|
});
|
|
62
57
|
}
|
|
63
58
|
/**
|
|
64
|
-
*
|
|
65
|
-
*
|
|
59
|
+
* Check whether a host has an active HSTS policy.
|
|
60
|
+
*
|
|
61
|
+
* @param {string} host - Hostname to check.
|
|
62
|
+
* @returns {boolean} `true` if the host or a parent domain has an active includeSubDomains policy.
|
|
66
63
|
*/
|
|
67
64
|
isSecure(host) {
|
|
68
65
|
const canonical = canonicalizeHost(host);
|
|
@@ -89,9 +86,10 @@ export class HSTSStore {
|
|
|
89
86
|
return false;
|
|
90
87
|
}
|
|
91
88
|
/**
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
89
|
+
* Upgrade an HTTP URL to HTTPS if an HSTS policy applies.
|
|
90
|
+
*
|
|
91
|
+
* @param {string} urlString - URL to potentially upgrade.
|
|
92
|
+
* @returns {string} The original URL or an HTTPS-upgraded version.
|
|
95
93
|
*/
|
|
96
94
|
upgradeURL(urlString) {
|
|
97
95
|
let parsed;
|
|
@@ -109,23 +107,21 @@ export class HSTSStore {
|
|
|
109
107
|
}
|
|
110
108
|
return urlString;
|
|
111
109
|
}
|
|
112
|
-
/**
|
|
110
|
+
/** Number of active HSTS policies in the store. */
|
|
113
111
|
get size() {
|
|
114
112
|
return this.policies.size;
|
|
115
113
|
}
|
|
116
|
-
/**
|
|
114
|
+
/** Remove all HSTS policies from the store. */
|
|
117
115
|
clear() {
|
|
118
116
|
this.policies.clear();
|
|
119
117
|
}
|
|
120
118
|
}
|
|
121
|
-
/** Lowercases the host and strips a trailing dot. */
|
|
122
119
|
function canonicalizeHost(host) {
|
|
123
120
|
let h = host.toLowerCase().trim();
|
|
124
121
|
if (h.endsWith("."))
|
|
125
122
|
h = h.slice(0, -1);
|
|
126
123
|
return h;
|
|
127
124
|
}
|
|
128
|
-
/** Returns `true` if the string looks like an IPv4 or IPv6 address. */
|
|
129
125
|
function isIPAddress(host) {
|
|
130
126
|
if (host.startsWith("["))
|
|
131
127
|
return true;
|
|
@@ -142,10 +138,6 @@ function isIPAddress(host) {
|
|
|
142
138
|
return true;
|
|
143
139
|
return false;
|
|
144
140
|
}
|
|
145
|
-
/**
|
|
146
|
-
* Parses the STS header value into a case-insensitive directive map.
|
|
147
|
-
* Directive names are lowercased; quoted string values are unquoted.
|
|
148
|
-
*/
|
|
149
141
|
function parseDirectives(value) {
|
|
150
142
|
const directives = new Map();
|
|
151
143
|
const parts = value.split(";");
|
package/dist/hsts/store.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store.js","sourceRoot":"","sources":["../../src/hsts/store.ts"],"names":[],"mappings":"AAEA
|
|
1
|
+
{"version":3,"file":"store.js","sourceRoot":"","sources":["../../src/hsts/store.ts"],"names":[],"mappings":"AAEA,yDAAyD;AACzD,MAAM,OAAO,SAAS;IACH,QAAQ,GAAG,IAAI,GAAG,EAAqB,CAAC;IAEzD;;;;OAIG;IACH,YAAY,MAAmB;QAC7B,IAAI,MAAM,EAAE,OAAO,EAAE,CAAC;YACpB,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;gBACnC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;YACzB,CAAC;QACH,CAAC;IACH,CAAC;IAEO,UAAU,CAAC,KAAuB;QACxC,MAAM,IAAI,GAAG,gBAAgB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC1C,IAAI,CAAC,IAAI;YAAE,OAAO;QAClB,IAAI,CAAC,QAAQ,CAA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Strict Transport Security (RFC 6797).
|
|
3
|
-
*/
|
|
1
|
+
/** Configuration for the HSTS policy store. */
|
|
4
2
|
export interface HSTSConfig {
|
|
5
|
-
/**
|
|
3
|
+
/** Whether HSTS enforcement is enabled. */
|
|
6
4
|
enabled?: boolean;
|
|
7
|
-
/**
|
|
5
|
+
/** Preloaded HSTS entries applied on construction. */
|
|
8
6
|
preload?: HSTSPreloadEntry[];
|
|
9
7
|
}
|
|
10
|
-
/**
|
|
11
|
-
* A preload entry for seeding the HSTS store with known-secure hosts.
|
|
12
|
-
*/
|
|
8
|
+
/** Preloaded HSTS entry for a specific host. */
|
|
13
9
|
export interface HSTSPreloadEntry {
|
|
10
|
+
/** Hostname to apply the HSTS policy to. */
|
|
14
11
|
host: string;
|
|
12
|
+
/** Whether the policy extends to all subdomains. */
|
|
15
13
|
includeSubDomains?: boolean;
|
|
16
14
|
}
|
|
17
|
-
/**
|
|
18
|
-
* Internal representation of a stored HSTS policy for a single host.
|
|
19
|
-
*/
|
|
15
|
+
/** Active HSTS policy entry with expiration. */
|
|
20
16
|
export interface HSTSEntry {
|
|
21
|
-
/**
|
|
17
|
+
/** Canonical hostname the policy applies to. */
|
|
22
18
|
host: string;
|
|
23
|
-
/**
|
|
19
|
+
/** Timestamp in milliseconds when the policy expires. */
|
|
24
20
|
expires: number;
|
|
25
|
-
/** Whether the policy
|
|
21
|
+
/** Whether the policy extends to all subdomains. */
|
|
26
22
|
includeSubDomains: boolean;
|
|
27
23
|
}
|
|
28
24
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/hsts/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/hsts/types.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/hsts/types.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,MAAM,WAAW,UAAU;IACzB,2CAA2C;IAC3C,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,sDAAsD;IACtD,OAAO,CAAC,EAAE,gBAAgB,EAAE,CAAC;CAC9B;AAED,gDAAgD;AAChD,MAAM,WAAW,gBAAgB;IAC/B,4CAA4C;IAC5C,IAAI,EAAE,MAAM,CAAC;IACb,oDAAoD;IACpD,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED,gDAAgD;AAChD,MAAM,WAAW,SAAS;IACxB,gDAAgD;IAChD,IAAI,EAAE,MAAM,CAAC;IACb,yDAAyD;IACzD,OAAO,EAAE,MAAM,CAAC;IAChB,oDAAoD;IACpD,iBAAiB,EAAE,OAAO,CAAC;CAC5B"}
|
package/dist/http/alt-svc.d.ts
CHANGED
|
@@ -1,84 +1,59 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Alt-Svc (Alternative Services) implementation per RFC 7838.
|
|
3
|
-
*
|
|
4
|
-
* Parses `Alt-Svc` response headers and maintains a store of alternative
|
|
5
|
-
* service entries. This is the primary mechanism for HTTP/3 discovery:
|
|
6
|
-
* servers advertise `h3=":443"` in Alt-Svc to indicate QUIC availability.
|
|
7
|
-
*
|
|
8
|
-
* @see https://datatracker.ietf.org/doc/html/rfc7838
|
|
9
|
-
*/
|
|
10
|
-
/**
|
|
11
|
-
* A single alternative service entry parsed from an Alt-Svc header.
|
|
12
|
-
*/
|
|
1
|
+
/** Parsed Alt-Svc header entry. */
|
|
13
2
|
export interface AltSvcEntry {
|
|
14
|
-
/** ALPN protocol identifier (e.g. "
|
|
3
|
+
/** ALPN protocol identifier (e.g. "h2"). */
|
|
15
4
|
alpn: string;
|
|
16
|
-
/**
|
|
5
|
+
/** Alternative authority hostname. */
|
|
17
6
|
host: string;
|
|
7
|
+
/** Alternative authority port. */
|
|
18
8
|
port: number;
|
|
19
|
-
/** Maximum age
|
|
9
|
+
/** Maximum age of the entry in seconds. */
|
|
20
10
|
maxAge: number;
|
|
21
|
-
/** Whether the entry
|
|
11
|
+
/** Whether the entry persists across network changes. */
|
|
22
12
|
persist: boolean;
|
|
23
|
-
/** Timestamp
|
|
13
|
+
/** Timestamp when the entry was stored. */
|
|
24
14
|
storedAt: number;
|
|
25
15
|
}
|
|
26
|
-
/**
|
|
27
|
-
* Configuration for the Alt-Svc store.
|
|
28
|
-
*/
|
|
16
|
+
/** Configuration for {@link AltSvcStore}. */
|
|
29
17
|
export interface AltSvcConfig {
|
|
30
|
-
/** Maximum number of entries across all origins.
|
|
18
|
+
/** Maximum number of entries across all origins. */
|
|
31
19
|
maxEntries?: number;
|
|
32
|
-
/** Whether
|
|
20
|
+
/** Whether Alt-Svc processing is enabled. */
|
|
33
21
|
enabled?: boolean;
|
|
34
22
|
}
|
|
35
|
-
/**
|
|
36
|
-
* In-memory store for Alt-Svc (Alternative Services) per RFC 7838.
|
|
37
|
-
*
|
|
38
|
-
* Tracks alternative service advertisements from HTTP response headers
|
|
39
|
-
* and provides lookup for the best alternative to use for a given origin.
|
|
40
|
-
*
|
|
41
|
-
* Primary use case: HTTP/3 discovery via `h3=":443"` advertisements.
|
|
42
|
-
*/
|
|
23
|
+
/** Store for Alt-Svc (Alternative Services) header entries. */
|
|
43
24
|
export declare class AltSvcStore {
|
|
44
25
|
private readonly entries;
|
|
45
26
|
private readonly maxEntries;
|
|
46
27
|
private totalEntries;
|
|
47
|
-
constructor(config?: AltSvcConfig);
|
|
48
28
|
/**
|
|
49
|
-
*
|
|
50
|
-
* associated with the given origin.
|
|
29
|
+
* Create a new Alt-Svc store.
|
|
51
30
|
*
|
|
52
|
-
* @param
|
|
53
|
-
|
|
31
|
+
* @param {AltSvcConfig} [config] - Store configuration.
|
|
32
|
+
*/
|
|
33
|
+
constructor(config?: AltSvcConfig);
|
|
34
|
+
/**
|
|
35
|
+
* Parse an Alt-Svc response header and store the entries.
|
|
54
36
|
*
|
|
55
|
-
* @
|
|
56
|
-
*
|
|
37
|
+
* @param {string} origin - Request origin (scheme + host + port).
|
|
38
|
+
* @param {string} headerValue - Raw Alt-Svc header value.
|
|
57
39
|
*/
|
|
58
40
|
parseHeader(origin: string, headerValue: string): void;
|
|
59
41
|
/**
|
|
60
|
-
*
|
|
61
|
-
* Prefers h3 over h2. Expired entries are pruned during lookup.
|
|
42
|
+
* Look up the best alternative service for an origin.
|
|
62
43
|
*
|
|
63
|
-
* @param origin
|
|
64
|
-
* @returns
|
|
44
|
+
* @param {string} origin - Request origin to look up.
|
|
45
|
+
* @returns {AltSvcEntry|undefined} Best matching entry, or `undefined` if none.
|
|
65
46
|
*/
|
|
66
47
|
lookup(origin: string): AltSvcEntry | undefined;
|
|
67
48
|
/**
|
|
68
|
-
*
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Removes all alternative service entries for a specific origin.
|
|
49
|
+
* Remove all Alt-Svc entries for an origin.
|
|
50
|
+
*
|
|
51
|
+
* @param {string} origin - Origin to clear.
|
|
73
52
|
*/
|
|
74
53
|
clear(origin: string): void;
|
|
75
|
-
/**
|
|
76
|
-
* Removes all entries from the store.
|
|
77
|
-
*/
|
|
54
|
+
/** Remove all Alt-Svc entries from the store. */
|
|
78
55
|
clearAll(): void;
|
|
79
|
-
/**
|
|
80
|
-
* Returns the total number of stored entries.
|
|
81
|
-
*/
|
|
56
|
+
/** Total number of entries across all origins. */
|
|
82
57
|
get size(): number;
|
|
83
58
|
private evictOldest;
|
|
84
59
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"alt-svc.d.ts","sourceRoot":"","sources":["../../src/http/alt-svc.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"alt-svc.d.ts","sourceRoot":"","sources":["../../src/http/alt-svc.ts"],"names":[],"mappings":"AAAA,mCAAmC;AACnC,MAAM,WAAW,WAAW;IAC1B,4CAA4C;IAC5C,IAAI,EAAE,MAAM,CAAC;IACb,sCAAsC;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,kCAAkC;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,2CAA2C;IAC3C,MAAM,EAAE,MAAM,CAAC;IACf,yDAAyD;IACzD,OAAO,EAAE,OAAO,CAAC;IACjB,2CAA2C;IAC3C,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,6CAA6C;AAC7C,MAAM,WAAW,YAAY;IAC3B,oDAAoD;IACpD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,6CAA6C;IAC7C,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAKD,+DAA+D;AAC/D,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAoC;IAC5D,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,YAAY,CAAK;IAEzB;;;;OAIG;gBACS,MAAM,CAAC,EAAE,YAAY;IAIjC;;;;;OAKG;IACH,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,IAAI;IAyBtD;;;;;OAKG;IACH,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS;IAqB/C;;;;OAIG;IACH,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAQ3B,iDAAiD;IACjD,QAAQ,IAAI,IAAI;IAKhB,kDAAkD;IAClD,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,OAAO,CAAC,WAAW;CAiBpB"}
|
package/dist/http/alt-svc.js
CHANGED
|
@@ -1,38 +1,23 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Alt-Svc (Alternative Services) implementation per RFC 7838.
|
|
3
|
-
*
|
|
4
|
-
* Parses `Alt-Svc` response headers and maintains a store of alternative
|
|
5
|
-
* service entries. This is the primary mechanism for HTTP/3 discovery:
|
|
6
|
-
* servers advertise `h3=":443"` in Alt-Svc to indicate QUIC availability.
|
|
7
|
-
*
|
|
8
|
-
* @see https://datatracker.ietf.org/doc/html/rfc7838
|
|
9
|
-
*/
|
|
10
1
|
const DEFAULT_MAX_AGE = 86400;
|
|
11
2
|
const DEFAULT_MAX_ENTRIES = 1000;
|
|
12
|
-
/**
|
|
13
|
-
* In-memory store for Alt-Svc (Alternative Services) per RFC 7838.
|
|
14
|
-
*
|
|
15
|
-
* Tracks alternative service advertisements from HTTP response headers
|
|
16
|
-
* and provides lookup for the best alternative to use for a given origin.
|
|
17
|
-
*
|
|
18
|
-
* Primary use case: HTTP/3 discovery via `h3=":443"` advertisements.
|
|
19
|
-
*/
|
|
3
|
+
/** Store for Alt-Svc (Alternative Services) header entries. */
|
|
20
4
|
export class AltSvcStore {
|
|
21
5
|
entries = new Map();
|
|
22
6
|
maxEntries;
|
|
23
7
|
totalEntries = 0;
|
|
8
|
+
/**
|
|
9
|
+
* Create a new Alt-Svc store.
|
|
10
|
+
*
|
|
11
|
+
* @param {AltSvcConfig} [config] - Store configuration.
|
|
12
|
+
*/
|
|
24
13
|
constructor(config) {
|
|
25
14
|
this.maxEntries = config?.maxEntries ?? DEFAULT_MAX_ENTRIES;
|
|
26
15
|
}
|
|
27
16
|
/**
|
|
28
|
-
*
|
|
29
|
-
* associated with the given origin.
|
|
17
|
+
* Parse an Alt-Svc response header and store the entries.
|
|
30
18
|
*
|
|
31
|
-
* @param origin
|
|
32
|
-
* @param headerValue
|
|
33
|
-
*
|
|
34
|
-
* @example
|
|
35
|
-
* store.parseHeader("https://example.com:443", 'h3=":443"; ma=86400, h2=":443"');
|
|
19
|
+
* @param {string} origin - Request origin (scheme + host + port).
|
|
20
|
+
* @param {string} headerValue - Raw Alt-Svc header value.
|
|
36
21
|
*/
|
|
37
22
|
parseHeader(origin, headerValue) {
|
|
38
23
|
const trimmed = headerValue.trim();
|
|
@@ -55,11 +40,10 @@ export class AltSvcStore {
|
|
|
55
40
|
this.totalEntries += parsed.length;
|
|
56
41
|
}
|
|
57
42
|
/**
|
|
58
|
-
*
|
|
59
|
-
* Prefers h3 over h2. Expired entries are pruned during lookup.
|
|
43
|
+
* Look up the best alternative service for an origin.
|
|
60
44
|
*
|
|
61
|
-
* @param origin
|
|
62
|
-
* @returns
|
|
45
|
+
* @param {string} origin - Request origin to look up.
|
|
46
|
+
* @returns {AltSvcEntry|undefined} Best matching entry, or `undefined` if none.
|
|
63
47
|
*/
|
|
64
48
|
lookup(origin) {
|
|
65
49
|
const entries = this.entries.get(origin);
|
|
@@ -76,23 +60,12 @@ export class AltSvcStore {
|
|
|
76
60
|
this.totalEntries -= entries.length - valid.length;
|
|
77
61
|
this.entries.set(origin, valid);
|
|
78
62
|
}
|
|
79
|
-
const h3 = valid.find((e) => e.alpn === "h3");
|
|
80
|
-
if (h3)
|
|
81
|
-
return h3;
|
|
82
|
-
const h3Draft = valid.find((e) => e.alpn.startsWith("h3-"));
|
|
83
|
-
if (h3Draft)
|
|
84
|
-
return h3Draft;
|
|
85
63
|
return valid[0];
|
|
86
64
|
}
|
|
87
65
|
/**
|
|
88
|
-
*
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
const entry = this.lookup(origin);
|
|
92
|
-
return entry !== undefined && (entry.alpn === "h3" || entry.alpn.startsWith("h3-"));
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Removes all alternative service entries for a specific origin.
|
|
66
|
+
* Remove all Alt-Svc entries for an origin.
|
|
67
|
+
*
|
|
68
|
+
* @param {string} origin - Origin to clear.
|
|
96
69
|
*/
|
|
97
70
|
clear(origin) {
|
|
98
71
|
const entries = this.entries.get(origin);
|
|
@@ -101,16 +74,12 @@ export class AltSvcStore {
|
|
|
101
74
|
this.entries.delete(origin);
|
|
102
75
|
}
|
|
103
76
|
}
|
|
104
|
-
/**
|
|
105
|
-
* Removes all entries from the store.
|
|
106
|
-
*/
|
|
77
|
+
/** Remove all Alt-Svc entries from the store. */
|
|
107
78
|
clearAll() {
|
|
108
79
|
this.entries.clear();
|
|
109
80
|
this.totalEntries = 0;
|
|
110
81
|
}
|
|
111
|
-
/**
|
|
112
|
-
* Returns the total number of stored entries.
|
|
113
|
-
*/
|
|
82
|
+
/** Total number of entries across all origins. */
|
|
114
83
|
get size() {
|
|
115
84
|
return this.totalEntries;
|
|
116
85
|
}
|
|
@@ -130,17 +99,6 @@ export class AltSvcStore {
|
|
|
130
99
|
}
|
|
131
100
|
}
|
|
132
101
|
}
|
|
133
|
-
/**
|
|
134
|
-
* Parses an Alt-Svc header value into structured entries.
|
|
135
|
-
*
|
|
136
|
-
* Format: `protocol="host:port"; ma=86400; persist=1, ...`
|
|
137
|
-
*
|
|
138
|
-
* Per RFC 7838 §3:
|
|
139
|
-
* - `protocol` is the ALPN protocol identifier
|
|
140
|
-
* - The quoted value is the authority `host:port`
|
|
141
|
-
* - `ma` is max-age in seconds (default 24h)
|
|
142
|
-
* - `persist` indicates whether to retain across network changes
|
|
143
|
-
*/
|
|
144
102
|
function parseAltSvcHeader(value, origin, now) {
|
|
145
103
|
const entries = [];
|
|
146
104
|
const originUrl = new URL(origin);
|
|
@@ -154,9 +112,6 @@ function parseAltSvcHeader(value, origin, now) {
|
|
|
154
112
|
}
|
|
155
113
|
return entries;
|
|
156
114
|
}
|
|
157
|
-
/**
|
|
158
|
-
* Splits Alt-Svc header by commas, respecting quoted strings.
|
|
159
|
-
*/
|
|
160
115
|
function splitAltSvc(value) {
|
|
161
116
|
const parts = [];
|
|
162
117
|
let current = "";
|
|
@@ -178,11 +133,6 @@ function splitAltSvc(value) {
|
|
|
178
133
|
parts.push(current);
|
|
179
134
|
return parts;
|
|
180
135
|
}
|
|
181
|
-
/**
|
|
182
|
-
* Parses a single Alt-Svc alternative entry.
|
|
183
|
-
*
|
|
184
|
-
* Format: `h3=":443"; ma=86400; persist=1`
|
|
185
|
-
*/
|
|
186
136
|
function parseSingleAltSvc(alt, defaultHost, defaultPort, now) {
|
|
187
137
|
const match = alt.match(/^([a-zA-Z0-9-]+)="([^"]*)"/);
|
|
188
138
|
if (!match)
|
package/dist/http/alt-svc.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"alt-svc.js","sourceRoot":"","sources":["../../src/http/alt-svc.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4
|
+
uri: string;
|
|
5
|
+
/** Link relation type (e.g. "preload"). */
|
|
6
|
+
rel?: string;
|
|
7
|
+
/** Destination type for the resource (e.g. "script", "style"). */
|
|
8
|
+
as?: string;
|
|
9
|
+
/** MIME type of the linked resource. */
|
|
10
|
+
type?: string;
|
|
11
|
+
/** Whether the resource requires CORS. */
|
|
12
|
+
crossorigin?: boolean;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Parse a Link header into an array of early hints.
|
|
16
|
+
*
|
|
17
|
+
* @param {string} linkHeader - Raw Link header value.
|
|
18
|
+
* @returns {EarlyHint[]} Array of parsed early hint objects.
|
|
19
|
+
*/
|
|
20
|
+
export declare function parseLinkHeader(linkHeader: string): EarlyHint[];
|
|
21
|
+
/** Callback invoked when 103 Early Hints are received. */
|
|
22
|
+
export type EarlyHintsCallback = (hints: EarlyHint[]) => void;
|
|
23
|
+
//# sourceMappingURL=early-hints.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"early-hints.d.ts","sourceRoot":"","sources":["../../src/http/early-hints.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAC9D,MAAM,WAAW,SAAS;IACxB,2BAA2B;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,2CAA2C;IAC3C,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,kEAAkE;IAClE,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,wCAAwC;IACxC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,0CAA0C;IAC1C,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,EAAE,CA6B/D;AAED,0DAA0D;AAC1D,MAAM,MAAM,kBAAkB,GAAG,CAAC,KAAK,EAAE,SAAS,EAAE,KAAK,IAAI,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse a Link header into an array of early hints.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} linkHeader - Raw Link header value.
|
|
5
|
+
* @returns {EarlyHint[]} Array of parsed early hint objects.
|
|
6
|
+
*/
|
|
7
|
+
export function parseLinkHeader(linkHeader) {
|
|
8
|
+
const hints = [];
|
|
9
|
+
const parts = linkHeader.split(",");
|
|
10
|
+
for (const part of parts) {
|
|
11
|
+
const trimmed = part.trim();
|
|
12
|
+
const uriMatch = /^<([^>]+)>/.exec(trimmed);
|
|
13
|
+
if (!uriMatch)
|
|
14
|
+
continue;
|
|
15
|
+
const hint = { uri: uriMatch[1] };
|
|
16
|
+
const params = trimmed.substring(uriMatch[0].length);
|
|
17
|
+
const relMatch = /;\s*rel\s*=\s*"?([^";]+)"?/i.exec(params);
|
|
18
|
+
if (relMatch)
|
|
19
|
+
hint.rel = relMatch[1].trim();
|
|
20
|
+
const asMatch = /;\s*as\s*=\s*"?([^";]+)"?/i.exec(params);
|
|
21
|
+
if (asMatch)
|
|
22
|
+
hint.as = asMatch[1].trim();
|
|
23
|
+
const typeMatch = /;\s*type\s*=\s*"?([^";]+)"?/i.exec(params);
|
|
24
|
+
if (typeMatch)
|
|
25
|
+
hint.type = typeMatch[1].trim();
|
|
26
|
+
if (/;\s*crossorigin/i.test(params)) {
|
|
27
|
+
hint.crossorigin = true;
|
|
28
|
+
}
|
|
29
|
+
hints.push(hint);
|
|
30
|
+
}
|
|
31
|
+
return hints;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=early-hints.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"early-hints.js","sourceRoot":"","sources":["../../src/http/early-hints.ts"],"names":[],"mappings":"AAcA;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,UAAkB;IAChD,MAAM,KAAK,GAAgB,EAAE,CAAC;IAE9B,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACpC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QAC5B,MAAM,QAAQ,GAAG,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC5C,IAAI,CAAC,QAAQ;YAAE,SAAS;QAExB,MAAM,IAAI,GAAc,EAAE,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAE,EAAE,CAAC;QAE9C,MAAM,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;QACrD,MAAM,QAAQ,GAAG,6BAA6B,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC5D,IAAI,QAAQ;YAAE,IAAI,CAAC,GAAG,GAAG,QAAQ,CAAC,CAAC,CAAE,CAAC,IAAI,EAAE,CAAC;QAE7C,MAAM,OAAO,GAAG,4BAA4B,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC1D,IAAI,OAAO;YAAE,IAAI,CAAC,EAAE,GAAG,OAAO,CAAC,CAAC,CAAE,CAAC,IAAI,EAAE,CAAC;QAE1C,MAAM,SAAS,GAAG,8BAA8B,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC9D,IAAI,SAAS;YAAE,IAAI,CAAC,IAAI,GAAG,SAAS,CAAC,CAAC,CAAE,CAAC,IAAI,EAAE,CAAC;QAEhD,IAAI,kBAAkB,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;YACpC,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QAC1B,CAAC;QAED,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACnB,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/dist/http/form-data.d.ts
CHANGED
|
@@ -1,58 +1,40 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Represents a single form field value. Either a string or a file descriptor.
|
|
3
|
-
*/
|
|
1
|
+
/** File attachment for multipart form-data encoding. */
|
|
4
2
|
export interface FormFile {
|
|
5
|
-
/**
|
|
3
|
+
/** Raw file content. */
|
|
6
4
|
data: Buffer;
|
|
7
|
-
/**
|
|
5
|
+
/** Name of the file. */
|
|
8
6
|
filename: string;
|
|
9
|
-
/**
|
|
7
|
+
/** MIME content type (defaults to application/octet-stream). */
|
|
10
8
|
contentType?: string;
|
|
11
9
|
}
|
|
10
|
+
/** A form field value — either a plain string or a file attachment. */
|
|
12
11
|
export type FormValue = string | FormFile;
|
|
13
|
-
/**
|
|
14
|
-
* Builds a `multipart/form-data` request body per RFC 7578.
|
|
15
|
-
*
|
|
16
|
-
* Generates a cryptographically random boundary and serializes all fields
|
|
17
|
-
* into a single `Buffer` suitable for use as a request body. The
|
|
18
|
-
* corresponding `Content-Type` header (including the boundary parameter)
|
|
19
|
-
* is available via {@link FormData.contentType}.
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* ```ts
|
|
23
|
-
* const form = new FormData();
|
|
24
|
-
* form.append("username", "alice");
|
|
25
|
-
* form.append("avatar", { data: avatarBuffer, filename: "avatar.png", contentType: "image/png" });
|
|
26
|
-
*
|
|
27
|
-
* const response = await post("https://example.com/upload", form);
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
12
|
+
/** Multipart form-data encoder for HTTP request bodies. */
|
|
30
13
|
export declare class FormData {
|
|
31
14
|
private readonly fields;
|
|
32
15
|
private readonly boundary;
|
|
16
|
+
/** Create a new FormData instance with a random boundary. */
|
|
33
17
|
constructor();
|
|
34
18
|
/**
|
|
35
|
-
*
|
|
19
|
+
* Append a field to the form.
|
|
36
20
|
*
|
|
37
|
-
* @param {string}
|
|
38
|
-
* @param {FormValue} value -
|
|
39
|
-
* @returns {this}
|
|
21
|
+
* @param {string} name - Field name.
|
|
22
|
+
* @param {FormValue} value - String value or file attachment.
|
|
23
|
+
* @returns {this} This instance for chaining.
|
|
40
24
|
*/
|
|
41
25
|
append(name: string, value: FormValue): this;
|
|
42
|
-
/**
|
|
43
|
-
* Returns the `Content-Type` header value including the boundary parameter.
|
|
44
|
-
* Must be set on the request for the server to parse the body correctly.
|
|
45
|
-
*/
|
|
26
|
+
/** Content-Type header value including the boundary parameter. */
|
|
46
27
|
get contentType(): string;
|
|
47
28
|
/**
|
|
48
|
-
*
|
|
29
|
+
* Return the multipart boundary string.
|
|
30
|
+
*
|
|
31
|
+
* @returns {string} The boundary delimiter.
|
|
49
32
|
*/
|
|
50
33
|
getBoundary(): string;
|
|
51
34
|
/**
|
|
52
|
-
*
|
|
53
|
-
* `multipart/form-data` format per RFC 7578.
|
|
35
|
+
* Encode all fields into a multipart form-data buffer.
|
|
54
36
|
*
|
|
55
|
-
* @returns {Buffer}
|
|
37
|
+
* @returns {Buffer} Wire-format multipart body.
|
|
56
38
|
*/
|
|
57
39
|
encode(): Buffer;
|
|
58
40
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"form-data.d.ts","sourceRoot":"","sources":["../../src/http/form-data.ts"],"names":[],"mappings":"AAEA
|
|
1
|
+
{"version":3,"file":"form-data.d.ts","sourceRoot":"","sources":["../../src/http/form-data.ts"],"names":[],"mappings":"AAEA,wDAAwD;AACxD,MAAM,WAAW,QAAQ;IACvB,wBAAwB;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,wBAAwB;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,gEAAgE;IAChE,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,uEAAuE;AACvE,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,QAAQ,CAAC;AAE1C,2DAA2D;AAC3D,qBAAa,QAAQ;IACnB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAiD;IACxE,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAElC,6DAA6D;;IAK7D;;;;;;OAMG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,GAAG,IAAI;IAK5C,kEAAkE;IAClE,IAAI,WAAW,IAAI,MAAM,CAExB;IAED;;;;OAIG;IACH,WAAW,IAAI,MAAM;IAIrB;;;;OAIG;IACH,MAAM,IAAI,MAAM;CA2BjB"}
|