nlcurl 0.7.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 +58 -36
- package/dist/cache/store.d.ts.map +1 -1
- package/dist/cache/store.js +58 -46
- package/dist/cache/store.js.map +1 -1
- package/dist/cache/types.d.ts +7 -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 +30 -39
- package/dist/cookies/jar.d.ts.map +1 -1
- package/dist/cookies/jar.js +27 -37
- 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 +17 -14
- 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 +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 +23 -111
- 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 +105 -76
- package/dist/core/session.js.map +1 -1
- package/dist/core/validation.d.ts +44 -43
- package/dist/core/validation.d.ts.map +1 -1
- package/dist/core/validation.js +44 -56
- 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 +20 -18
- package/dist/dns/codec.d.ts.map +1 -1
- package/dist/dns/codec.js +20 -36
- 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 +46 -47
- 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 +158 -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 +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 +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 +31 -49
- package/dist/http/alt-svc.d.ts.map +1 -1
- package/dist/http/alt-svc.js +21 -55
- 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 +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 +5 -7
- package/dist/http/h3/detection.d.ts.map +1 -1
- package/dist/http/h3/detection.js +5 -23
- package/dist/http/h3/detection.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 +16 -28
- package/dist/http/negotiator.js.map +1 -1
- package/dist/http/pool.d.ts +32 -62
- 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 +21 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +21 -2
- 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 +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 +128 -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 +5 -8
- package/dist/proxy/socks.js.map +1 -1
- package/dist/sse/parser.d.ts +14 -37
- package/dist/sse/parser.d.ts.map +1 -1
- package/dist/sse/parser.js +14 -28
- package/dist/sse/parser.js.map +1 -1
- 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 +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 +20 -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 +25 -44
- package/dist/tls/stealth/client-hello.d.ts.map +1 -1
- package/dist/tls/stealth/client-hello.js +17 -28
- 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 +11 -17
- package/dist/tls/stealth/engine.js.map +1 -1
- package/dist/tls/stealth/handshake.d.ts +21 -31
- package/dist/tls/stealth/handshake.d.ts.map +1 -1
- package/dist/tls/stealth/handshake.js +15 -43
- 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 +16 -0
- package/dist/tls/stealth/tls12-handshake.d.ts.map +1 -1
- package/dist/tls/stealth/tls12-handshake.js +8 -0
- package/dist/tls/stealth/tls12-handshake.js.map +1 -1
- package/dist/tls/types.d.ts +42 -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 +33 -53
- package/dist/ws/client.d.ts.map +1 -1
- package/dist/ws/client.js +29 -30
- 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 +18 -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 +62 -62
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parses a No-Vary-Search header value into a structured directive.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} header - The raw No-Vary-Search header value.
|
|
5
|
+
* @returns {NoVarySearchDirective|null} The parsed directive, or `null` if the header is empty.
|
|
6
|
+
*/
|
|
7
|
+
export function parseNoVarySearch(header) {
|
|
8
|
+
if (!header)
|
|
9
|
+
return null;
|
|
10
|
+
const directive = {
|
|
11
|
+
params: false,
|
|
12
|
+
except: [],
|
|
13
|
+
keyOrder: false,
|
|
14
|
+
};
|
|
15
|
+
const parts = header.split(",").map((s) => s.trim());
|
|
16
|
+
for (const part of parts) {
|
|
17
|
+
if (part === "params") {
|
|
18
|
+
directive.params = true;
|
|
19
|
+
}
|
|
20
|
+
else if (part === "key-order") {
|
|
21
|
+
directive.keyOrder = true;
|
|
22
|
+
}
|
|
23
|
+
else if (part.startsWith("params=")) {
|
|
24
|
+
const listStr = part.substring("params=".length).trim();
|
|
25
|
+
const parsed = parseInnerList(listStr);
|
|
26
|
+
if (parsed)
|
|
27
|
+
directive.params = parsed;
|
|
28
|
+
}
|
|
29
|
+
else if (part.startsWith("except=")) {
|
|
30
|
+
const listStr = part.substring("except=".length).trim();
|
|
31
|
+
const parsed = parseInnerList(listStr);
|
|
32
|
+
if (parsed)
|
|
33
|
+
directive.except = parsed;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return directive;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Determines whether two URLs match according to a No-Vary-Search directive.
|
|
40
|
+
*
|
|
41
|
+
* @param {string} cachedUrl - The URL of the cached response.
|
|
42
|
+
* @param {string} requestUrl - The URL of the incoming request.
|
|
43
|
+
* @param {NoVarySearchDirective} directive - The No-Vary-Search directive to apply.
|
|
44
|
+
* @returns {boolean} `true` if the URLs are considered equivalent under the directive.
|
|
45
|
+
*/
|
|
46
|
+
export function urlsMatchWithNoVarySearch(cachedUrl, requestUrl, directive) {
|
|
47
|
+
let cached;
|
|
48
|
+
let request;
|
|
49
|
+
try {
|
|
50
|
+
cached = new URL(cachedUrl);
|
|
51
|
+
request = new URL(requestUrl);
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
if (cached.origin !== request.origin)
|
|
57
|
+
return false;
|
|
58
|
+
if (cached.pathname !== request.pathname)
|
|
59
|
+
return false;
|
|
60
|
+
const cachedParams = new URLSearchParams(cached.search);
|
|
61
|
+
const requestParams = new URLSearchParams(request.search);
|
|
62
|
+
const filteredCached = filterParams(cachedParams, directive);
|
|
63
|
+
const filteredRequest = filterParams(requestParams, directive);
|
|
64
|
+
if (directive.keyOrder) {
|
|
65
|
+
return paramsEqualUnordered(filteredCached, filteredRequest);
|
|
66
|
+
}
|
|
67
|
+
return paramsEqualOrdered(filteredCached, filteredRequest);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Normalizes a URL for cache key generation by applying No-Vary-Search filtering.
|
|
71
|
+
*
|
|
72
|
+
* @param {string} url - The URL to normalize.
|
|
73
|
+
* @param {NoVarySearchDirective} directive - The No-Vary-Search directive to apply.
|
|
74
|
+
* @returns {string} The normalized URL string.
|
|
75
|
+
*/
|
|
76
|
+
export function normalizeUrlForCache(url, directive) {
|
|
77
|
+
let parsed;
|
|
78
|
+
try {
|
|
79
|
+
parsed = new URL(url);
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
return url;
|
|
83
|
+
}
|
|
84
|
+
const params = new URLSearchParams(parsed.search);
|
|
85
|
+
const filtered = filterParams(params, directive);
|
|
86
|
+
if (directive.keyOrder) {
|
|
87
|
+
filtered.sort();
|
|
88
|
+
}
|
|
89
|
+
parsed.search = filtered.toString();
|
|
90
|
+
return parsed.href;
|
|
91
|
+
}
|
|
92
|
+
function filterParams(params, directive) {
|
|
93
|
+
const result = new URLSearchParams();
|
|
94
|
+
if (directive.params === true) {
|
|
95
|
+
for (const [key, value] of params) {
|
|
96
|
+
if (directive.except.includes(key)) {
|
|
97
|
+
result.append(key, value);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
else if (Array.isArray(directive.params)) {
|
|
102
|
+
for (const [key, value] of params) {
|
|
103
|
+
if (!directive.params.includes(key)) {
|
|
104
|
+
result.append(key, value);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
for (const [key, value] of params) {
|
|
110
|
+
result.append(key, value);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return result;
|
|
114
|
+
}
|
|
115
|
+
function paramsEqualUnordered(a, b) {
|
|
116
|
+
const aEntries = [...a.entries()].sort(([k1, v1], [k2, v2]) => (k1 < k2 ? -1 : k1 > k2 ? 1 : v1 < v2 ? -1 : v1 > v2 ? 1 : 0));
|
|
117
|
+
const bEntries = [...b.entries()].sort(([k1, v1], [k2, v2]) => (k1 < k2 ? -1 : k1 > k2 ? 1 : v1 < v2 ? -1 : v1 > v2 ? 1 : 0));
|
|
118
|
+
if (aEntries.length !== bEntries.length)
|
|
119
|
+
return false;
|
|
120
|
+
for (let i = 0; i < aEntries.length; i++) {
|
|
121
|
+
if (aEntries[i][0] !== bEntries[i][0] || aEntries[i][1] !== bEntries[i][1]) {
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return true;
|
|
126
|
+
}
|
|
127
|
+
function paramsEqualOrdered(a, b) {
|
|
128
|
+
const aEntries = [...a.entries()];
|
|
129
|
+
const bEntries = [...b.entries()];
|
|
130
|
+
if (aEntries.length !== bEntries.length)
|
|
131
|
+
return false;
|
|
132
|
+
for (let i = 0; i < aEntries.length; i++) {
|
|
133
|
+
if (aEntries[i][0] !== bEntries[i][0] || aEntries[i][1] !== bEntries[i][1]) {
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
function parseInnerList(str) {
|
|
140
|
+
const match = str.match(/^\(([^)]*)\)/);
|
|
141
|
+
if (!match)
|
|
142
|
+
return null;
|
|
143
|
+
return match[1]
|
|
144
|
+
.split(/\s+/)
|
|
145
|
+
.map((s) => s.replace(/"/g, "").trim())
|
|
146
|
+
.filter(Boolean);
|
|
147
|
+
}
|
|
148
|
+
//# sourceMappingURL=no-vary-search.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-vary-search.js","sourceRoot":"","sources":["../../src/cache/no-vary-search.ts"],"names":[],"mappings":"AASA;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,MAAc;IAC9C,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAC;IAEzB,MAAM,SAAS,GAA0B;QACvC,MAAM,EAAE,KAAK;QACb,MAAM,EAAE,EAAE;QACV,QAAQ,EAAE,KAAK;KAChB,CAAC;IAEF,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;IAErD,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,IAAI,KAAK,QAAQ,EAAE,CAAC;YACtB,SAAS,CAAC,MAAM,GAAG,IAAI,CAAC;QAC1B,CAAC;aAAM,IAAI,IAAI,KAAK,WAAW,EAAE,CAAC;YAChC,SAAS,CAAC,QAAQ,GAAG,IAAI,CAAC;QAC5B,CAAC;aAAM,IAAI,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;YACtC,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,MA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CAAC,CAAC,EAAE,CAAC;YAC/E,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAS,cAAc,CAAC,GAAW;IACjC,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;IACxC,IAAI,CAAC,KAAK;QAAE,OAAO,IAAI,CAAC;IAExB,OAAO,KAAK,CAAC,CAAC,CAAE;SACb,KAAK,CAAC,KAAK,CAAC;SACZ,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;SACtC,MAAM,CAAC,OAAO,CAAC,CAAC;AACrB,CAAC"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parsed Content-Range header fields.
|
|
3
|
+
*/
|
|
4
|
+
export interface ContentRange {
|
|
5
|
+
unit: string;
|
|
6
|
+
start: number;
|
|
7
|
+
end: number;
|
|
8
|
+
total: number;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* A contiguous byte range segment stored in cache.
|
|
12
|
+
*/
|
|
13
|
+
export interface RangeSegment {
|
|
14
|
+
start: number;
|
|
15
|
+
end: number;
|
|
16
|
+
data: Buffer;
|
|
17
|
+
etag?: string;
|
|
18
|
+
storedAt: number;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Represents all cached range segments for a given URL.
|
|
22
|
+
*/
|
|
23
|
+
export interface RangeCacheEntry {
|
|
24
|
+
url: string;
|
|
25
|
+
segments: RangeSegment[];
|
|
26
|
+
totalSize: number;
|
|
27
|
+
etag?: string;
|
|
28
|
+
lastModified?: string;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Parses a Content-Range header value into its component fields.
|
|
32
|
+
*
|
|
33
|
+
* @param {string} header - The raw Content-Range header value.
|
|
34
|
+
* @returns {ContentRange|null} The parsed range, or `null` if the header is malformed.
|
|
35
|
+
*/
|
|
36
|
+
export declare function parseContentRange(header: string): ContentRange | null;
|
|
37
|
+
/**
|
|
38
|
+
* Parses a Range request header into an array of byte ranges.
|
|
39
|
+
*
|
|
40
|
+
* @param {string} header - The raw Range header value (e.g. "bytes=0-499,1000-1499").
|
|
41
|
+
* @returns {Array<[number, number|undefined]>|null} Parsed ranges, or `null` if invalid.
|
|
42
|
+
*/
|
|
43
|
+
export declare function parseRangeHeader(header: string): Array<[number, number | undefined]> | null;
|
|
44
|
+
/**
|
|
45
|
+
* Caches partial HTTP responses (206 Partial Content) and reassembles
|
|
46
|
+
* byte ranges on subsequent lookups.
|
|
47
|
+
*
|
|
48
|
+
* @class
|
|
49
|
+
*/
|
|
50
|
+
export declare class RangeCache {
|
|
51
|
+
private readonly entries;
|
|
52
|
+
private readonly maxEntries;
|
|
53
|
+
private readonly maxSegmentsPerEntry;
|
|
54
|
+
/**
|
|
55
|
+
* Creates a new RangeCache.
|
|
56
|
+
*
|
|
57
|
+
* @param {Object} [config] - Optional cache limits.
|
|
58
|
+
* @param {number} [config.maxEntries=200] - Maximum number of URLs to cache.
|
|
59
|
+
* @param {number} [config.maxSegmentsPerEntry=100] - Maximum segments per URL.
|
|
60
|
+
*/
|
|
61
|
+
constructor(config?: {
|
|
62
|
+
maxEntries?: number;
|
|
63
|
+
maxSegmentsPerEntry?: number;
|
|
64
|
+
});
|
|
65
|
+
/**
|
|
66
|
+
* Stores a range segment for the given URL.
|
|
67
|
+
*
|
|
68
|
+
* @param {string} url - The resource URL.
|
|
69
|
+
* @param {ContentRange} range - The content range descriptor.
|
|
70
|
+
* @param {Buffer} data - The response body bytes for this range.
|
|
71
|
+
* @param {Object} [meta] - Optional metadata.
|
|
72
|
+
* @param {string} [meta.etag] - The entity tag for cache coherence.
|
|
73
|
+
* @param {string} [meta.lastModified] - The Last-Modified date.
|
|
74
|
+
*/
|
|
75
|
+
store(url: string, range: ContentRange, data: Buffer, meta?: {
|
|
76
|
+
etag?: string;
|
|
77
|
+
lastModified?: string;
|
|
78
|
+
}): void;
|
|
79
|
+
/**
|
|
80
|
+
* Looks up cached bytes for a given byte range.
|
|
81
|
+
*
|
|
82
|
+
* @param {string} url - The resource URL.
|
|
83
|
+
* @param {number} start - Start byte offset (inclusive).
|
|
84
|
+
* @param {number} end - End byte offset (inclusive).
|
|
85
|
+
* @returns {Buffer|null} The cached bytes, or `null` on a miss.
|
|
86
|
+
*/
|
|
87
|
+
lookup(url: string, start: number, end: number): Buffer | null;
|
|
88
|
+
/**
|
|
89
|
+
* Checks whether all bytes for a URL have been cached.
|
|
90
|
+
*
|
|
91
|
+
* @param {string} url - The resource URL.
|
|
92
|
+
* @returns {boolean} `true` if the full resource is cached.
|
|
93
|
+
*/
|
|
94
|
+
isComplete(url: string): boolean;
|
|
95
|
+
/**
|
|
96
|
+
* Returns the range cache entry for a URL, if present.
|
|
97
|
+
*
|
|
98
|
+
* @param {string} url - The resource URL.
|
|
99
|
+
* @returns {RangeCacheEntry|undefined} The cached entry.
|
|
100
|
+
*/
|
|
101
|
+
get(url: string): RangeCacheEntry | undefined;
|
|
102
|
+
/**
|
|
103
|
+
* Removes the cache entry for a URL.
|
|
104
|
+
*
|
|
105
|
+
* @param {string} url - The resource URL to evict.
|
|
106
|
+
* @returns {boolean} `true` if an entry was removed.
|
|
107
|
+
*/
|
|
108
|
+
delete(url: string): boolean;
|
|
109
|
+
/**
|
|
110
|
+
* Removes all cached range entries.
|
|
111
|
+
*/
|
|
112
|
+
clear(): void;
|
|
113
|
+
/**
|
|
114
|
+
* Returns the number of URLs with cached ranges.
|
|
115
|
+
*
|
|
116
|
+
* @returns {number} The entry count.
|
|
117
|
+
*/
|
|
118
|
+
get size(): number;
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=range.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"range.d.ts","sourceRoot":"","sources":["../../src/cache/range.ts"],"names":[],"mappings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AE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,YAAY,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI;IA0C5G;;;;;;;OAOG;IACH,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAgB9D;;;;;OAKG;IACH,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAYhC;;;;;OAKG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS;IAI7C;;;;;OAKG;IACH,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAI5B;;OAEG;IACH,KAAK,IAAI,IAAI;IAIb;;;;OAIG;IACH,IAAI,IAAI,IAAI,MAAM,CAEjB;CACF"}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parses a Content-Range header value into its component fields.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} header - The raw Content-Range header value.
|
|
5
|
+
* @returns {ContentRange|null} The parsed range, or `null` if the header is malformed.
|
|
6
|
+
*/
|
|
7
|
+
export function parseContentRange(header) {
|
|
8
|
+
const match = header.match(/^(\w+)\s+(\d+)-(\d+)\/(\d+|\*)/);
|
|
9
|
+
if (!match)
|
|
10
|
+
return null;
|
|
11
|
+
const unit = match[1];
|
|
12
|
+
const start = parseInt(match[2], 10);
|
|
13
|
+
const end = parseInt(match[3], 10);
|
|
14
|
+
const total = match[4] === "*" ? -1 : parseInt(match[4], 10);
|
|
15
|
+
if (start > end)
|
|
16
|
+
return null;
|
|
17
|
+
if (total !== -1 && end >= total)
|
|
18
|
+
return null;
|
|
19
|
+
return { unit, start, end, total };
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Parses a Range request header into an array of byte ranges.
|
|
23
|
+
*
|
|
24
|
+
* @param {string} header - The raw Range header value (e.g. "bytes=0-499,1000-1499").
|
|
25
|
+
* @returns {Array<[number, number|undefined]>|null} Parsed ranges, or `null` if invalid.
|
|
26
|
+
*/
|
|
27
|
+
export function parseRangeHeader(header) {
|
|
28
|
+
const match = header.match(/^bytes=(.+)/);
|
|
29
|
+
if (!match)
|
|
30
|
+
return null;
|
|
31
|
+
const ranges = [];
|
|
32
|
+
const parts = match[1].split(",");
|
|
33
|
+
for (const part of parts) {
|
|
34
|
+
const trimmed = part.trim();
|
|
35
|
+
const dashIdx = trimmed.indexOf("-");
|
|
36
|
+
if (dashIdx === -1)
|
|
37
|
+
return null;
|
|
38
|
+
const startStr = trimmed.substring(0, dashIdx);
|
|
39
|
+
const endStr = trimmed.substring(dashIdx + 1);
|
|
40
|
+
if (startStr === "" && endStr === "")
|
|
41
|
+
return null;
|
|
42
|
+
const start = startStr === "" ? -parseInt(endStr, 10) : parseInt(startStr, 10);
|
|
43
|
+
const end = endStr === "" ? undefined : parseInt(endStr, 10);
|
|
44
|
+
if (Number.isNaN(start))
|
|
45
|
+
return null;
|
|
46
|
+
if (end !== undefined && Number.isNaN(end))
|
|
47
|
+
return null;
|
|
48
|
+
ranges.push([start, end]);
|
|
49
|
+
}
|
|
50
|
+
return ranges.length > 0 ? ranges : null;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Caches partial HTTP responses (206 Partial Content) and reassembles
|
|
54
|
+
* byte ranges on subsequent lookups.
|
|
55
|
+
*
|
|
56
|
+
* @class
|
|
57
|
+
*/
|
|
58
|
+
export class RangeCache {
|
|
59
|
+
entries = new Map();
|
|
60
|
+
maxEntries;
|
|
61
|
+
maxSegmentsPerEntry;
|
|
62
|
+
/**
|
|
63
|
+
* Creates a new RangeCache.
|
|
64
|
+
*
|
|
65
|
+
* @param {Object} [config] - Optional cache limits.
|
|
66
|
+
* @param {number} [config.maxEntries=200] - Maximum number of URLs to cache.
|
|
67
|
+
* @param {number} [config.maxSegmentsPerEntry=100] - Maximum segments per URL.
|
|
68
|
+
*/
|
|
69
|
+
constructor(config) {
|
|
70
|
+
this.maxEntries = config?.maxEntries ?? 200;
|
|
71
|
+
this.maxSegmentsPerEntry = config?.maxSegmentsPerEntry ?? 100;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Stores a range segment for the given URL.
|
|
75
|
+
*
|
|
76
|
+
* @param {string} url - The resource URL.
|
|
77
|
+
* @param {ContentRange} range - The content range descriptor.
|
|
78
|
+
* @param {Buffer} data - The response body bytes for this range.
|
|
79
|
+
* @param {Object} [meta] - Optional metadata.
|
|
80
|
+
* @param {string} [meta.etag] - The entity tag for cache coherence.
|
|
81
|
+
* @param {string} [meta.lastModified] - The Last-Modified date.
|
|
82
|
+
*/
|
|
83
|
+
store(url, range, data, meta) {
|
|
84
|
+
let entry = this.entries.get(url);
|
|
85
|
+
if (entry) {
|
|
86
|
+
if (meta?.etag && entry.etag && meta.etag !== entry.etag) {
|
|
87
|
+
entry.segments = [];
|
|
88
|
+
entry.etag = meta.etag;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
if (this.entries.size >= this.maxEntries) {
|
|
93
|
+
const firstKey = this.entries.keys().next().value;
|
|
94
|
+
if (firstKey)
|
|
95
|
+
this.entries.delete(firstKey);
|
|
96
|
+
}
|
|
97
|
+
entry = {
|
|
98
|
+
url,
|
|
99
|
+
segments: [],
|
|
100
|
+
totalSize: range.total,
|
|
101
|
+
etag: meta?.etag,
|
|
102
|
+
lastModified: meta?.lastModified,
|
|
103
|
+
};
|
|
104
|
+
this.entries.set(url, entry);
|
|
105
|
+
}
|
|
106
|
+
if (range.total !== -1) {
|
|
107
|
+
entry.totalSize = range.total;
|
|
108
|
+
}
|
|
109
|
+
entry.segments = entry.segments.filter((s) => s.end < range.start || s.start > range.end);
|
|
110
|
+
if (entry.segments.length < this.maxSegmentsPerEntry) {
|
|
111
|
+
entry.segments.push({
|
|
112
|
+
start: range.start,
|
|
113
|
+
end: range.end,
|
|
114
|
+
data: Buffer.from(data),
|
|
115
|
+
etag: meta?.etag,
|
|
116
|
+
storedAt: Date.now(),
|
|
117
|
+
});
|
|
118
|
+
entry.segments.sort((a, b) => a.start - b.start);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Looks up cached bytes for a given byte range.
|
|
123
|
+
*
|
|
124
|
+
* @param {string} url - The resource URL.
|
|
125
|
+
* @param {number} start - Start byte offset (inclusive).
|
|
126
|
+
* @param {number} end - End byte offset (inclusive).
|
|
127
|
+
* @returns {Buffer|null} The cached bytes, or `null` on a miss.
|
|
128
|
+
*/
|
|
129
|
+
lookup(url, start, end) {
|
|
130
|
+
const entry = this.entries.get(url);
|
|
131
|
+
if (!entry)
|
|
132
|
+
return null;
|
|
133
|
+
const covering = entry.segments.filter((s) => s.start <= start && s.end >= end);
|
|
134
|
+
if (covering.length > 0) {
|
|
135
|
+
const segment = covering[0];
|
|
136
|
+
const offsetStart = start - segment.start;
|
|
137
|
+
const offsetEnd = end - segment.start + 1;
|
|
138
|
+
return segment.data.subarray(offsetStart, offsetEnd);
|
|
139
|
+
}
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Checks whether all bytes for a URL have been cached.
|
|
144
|
+
*
|
|
145
|
+
* @param {string} url - The resource URL.
|
|
146
|
+
* @returns {boolean} `true` if the full resource is cached.
|
|
147
|
+
*/
|
|
148
|
+
isComplete(url) {
|
|
149
|
+
const entry = this.entries.get(url);
|
|
150
|
+
if (!entry || entry.totalSize <= 0)
|
|
151
|
+
return false;
|
|
152
|
+
let covered = 0;
|
|
153
|
+
for (const segment of entry.segments) {
|
|
154
|
+
if (segment.start > covered)
|
|
155
|
+
return false;
|
|
156
|
+
covered = Math.max(covered, segment.end + 1);
|
|
157
|
+
}
|
|
158
|
+
return covered >= entry.totalSize;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Returns the range cache entry for a URL, if present.
|
|
162
|
+
*
|
|
163
|
+
* @param {string} url - The resource URL.
|
|
164
|
+
* @returns {RangeCacheEntry|undefined} The cached entry.
|
|
165
|
+
*/
|
|
166
|
+
get(url) {
|
|
167
|
+
return this.entries.get(url);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Removes the cache entry for a URL.
|
|
171
|
+
*
|
|
172
|
+
* @param {string} url - The resource URL to evict.
|
|
173
|
+
* @returns {boolean} `true` if an entry was removed.
|
|
174
|
+
*/
|
|
175
|
+
delete(url) {
|
|
176
|
+
return this.entries.delete(url);
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Removes all cached range entries.
|
|
180
|
+
*/
|
|
181
|
+
clear() {
|
|
182
|
+
this.entries.clear();
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Returns the number of URLs with cached ranges.
|
|
186
|
+
*
|
|
187
|
+
* @returns {number} The entry count.
|
|
188
|
+
*/
|
|
189
|
+
get size() {
|
|
190
|
+
return this.entries.size;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
//# sourceMappingURL=range.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"range.js","sourceRoot":"","sources":["../../src/cache/range.ts"],"names":[],"mappings":"AAgCA;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,MAAc;IAC9C,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,gCAAgC,CAAC,CAAC;IAC7D,IAAI,CAAC,KAAK;QAAE,OAAO,IAAI,CAAC;IAExB,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAE,CAAC;IACvB,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAE,EAAE,EAAE,CAAC,CAAC;IACtC,MAAM,GAAG,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAE,EAAE,EAAE,CAAC,CAAC;IACpC,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC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;gBAAE,OAAO,KAAK,CAAC;YAC1C,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;QAC/C,CAAC;QACD,OAAO,OAAO,IAAI,KAAK,CAAC,SAAS,CAAC;IACpC,CAAC;IAED;;;;;OAKG;IACH,GAAG,CAAC,GAAW;QACb,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC/B,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,GAAW;QAChB,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAClC,CAAC;IAED;;OAEG;IACH,KAAK;QACH,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;IACvB,CAAC;IAED;;;;OAIG;IACH,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;IAC3B,CAAC;CACF"}
|
package/dist/cache/store.d.ts
CHANGED
|
@@ -2,15 +2,10 @@ import type { CacheConfig, CacheDirectives, CacheEntry, CacheLookupResult, Cache
|
|
|
2
2
|
import type { NLcURLRequest } from "../core/request.js";
|
|
3
3
|
import { NLcURLResponse } from "../core/response.js";
|
|
4
4
|
/**
|
|
5
|
-
* In-memory HTTP response cache implementing RFC 9111
|
|
5
|
+
* In-memory HTTP response cache implementing RFC 9111 semantics with LRU eviction,
|
|
6
|
+
* Vary-based matching, and conditional revalidation support.
|
|
6
7
|
*
|
|
7
|
-
*
|
|
8
|
-
* - Cache-Control directive parsing and freshness calculation
|
|
9
|
-
* - ETag / Last-Modified conditional request header injection
|
|
10
|
-
* - 304 Not Modified response merging
|
|
11
|
-
* - Vary header support
|
|
12
|
-
* - LRU eviction by entry count and total body size
|
|
13
|
-
* - Range request passthrough (does not cache partial responses by default)
|
|
8
|
+
* @class
|
|
14
9
|
*/
|
|
15
10
|
export declare class CacheStore {
|
|
16
11
|
private readonly entries;
|
|
@@ -18,26 +13,35 @@ export declare class CacheStore {
|
|
|
18
13
|
private readonly maxSize;
|
|
19
14
|
private currentSize;
|
|
20
15
|
private readonly mode;
|
|
21
|
-
/** Monotonic counter for deterministic LRU ordering within the same ms. */
|
|
22
16
|
private accessCounter;
|
|
17
|
+
/**
|
|
18
|
+
* Creates a new CacheStore with the given limits and default mode.
|
|
19
|
+
*
|
|
20
|
+
* @param {CacheConfig} [config] - Cache configuration.
|
|
21
|
+
*/
|
|
23
22
|
constructor(config?: CacheConfig);
|
|
24
23
|
/**
|
|
25
|
-
* Generates a cache key from
|
|
24
|
+
* Generates a deterministic cache key from an HTTP method and URL.
|
|
25
|
+
*
|
|
26
|
+
* @param {string} method - The HTTP method.
|
|
27
|
+
* @param {string} url - The request URL.
|
|
28
|
+
* @returns {string} The cache key.
|
|
26
29
|
*/
|
|
27
30
|
static cacheKey(method: string, url: string): string;
|
|
28
31
|
/**
|
|
29
|
-
* Looks up a
|
|
32
|
+
* Looks up a request in the cache and evaluates freshness.
|
|
30
33
|
*
|
|
31
|
-
* @param req - The
|
|
32
|
-
* @returns
|
|
34
|
+
* @param {NLcURLRequest} req - The request to look up.
|
|
35
|
+
* @returns {CacheLookupResult} Freshness status and the matched entry, if any.
|
|
33
36
|
*/
|
|
34
37
|
lookup(req: NLcURLRequest): CacheLookupResult;
|
|
35
38
|
/**
|
|
36
|
-
*
|
|
37
|
-
*
|
|
39
|
+
* Evaluates a request against the cache and returns instructions for
|
|
40
|
+
* serving, revalidating, or storing the response.
|
|
38
41
|
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
42
|
+
* @param {NLcURLRequest} req - The incoming request.
|
|
43
|
+
* @param {CacheMode} [modeOverride] - Overrides the store's default cache mode.
|
|
44
|
+
* @returns {Object} Evaluation decision with conditional headers and matched entry.
|
|
41
45
|
*/
|
|
42
46
|
evaluate(req: NLcURLRequest, modeOverride?: CacheMode): {
|
|
43
47
|
conditionalHeaders?: Record<string, string>;
|
|
@@ -46,44 +50,62 @@ export declare class CacheStore {
|
|
|
46
50
|
serveCached?: CacheEntry;
|
|
47
51
|
};
|
|
48
52
|
/**
|
|
49
|
-
* Stores a response in the cache
|
|
53
|
+
* Stores a response in the cache, subject to cacheability rules.
|
|
54
|
+
*
|
|
55
|
+
* @param {NLcURLRequest} req - The originating request.
|
|
56
|
+
* @param {NLcURLResponse} response - The response to cache.
|
|
50
57
|
*/
|
|
51
58
|
store(req: NLcURLRequest, response: NLcURLResponse): void;
|
|
52
59
|
/**
|
|
53
|
-
* Merges a 304 Not Modified response with a
|
|
54
|
-
* a
|
|
60
|
+
* Merges a 304 Not Modified response with a stale cache entry, producing
|
|
61
|
+
* a fresh response with updated headers.
|
|
62
|
+
*
|
|
63
|
+
* @param {CacheEntry} entry - The stale cache entry.
|
|
64
|
+
* @param {NLcURLResponse} response304 - The 304 response.
|
|
65
|
+
* @returns {NLcURLResponse} A new response with merged headers and the cached body.
|
|
55
66
|
*/
|
|
56
67
|
mergeNotModified(entry: CacheEntry, response304: NLcURLResponse): NLcURLResponse;
|
|
57
68
|
/**
|
|
58
|
-
* Constructs a full NLcURLResponse from a cache entry
|
|
69
|
+
* Constructs a full NLcURLResponse from a cache entry.
|
|
70
|
+
*
|
|
71
|
+
* @param {CacheEntry} entry - The cache entry to serve.
|
|
72
|
+
* @param {NLcURLRequest} req - The request context.
|
|
73
|
+
* @returns {NLcURLResponse} The reconstituted response.
|
|
59
74
|
*/
|
|
60
75
|
responseFromEntry(entry: CacheEntry, req: NLcURLRequest): NLcURLResponse;
|
|
61
|
-
/** Returns the number of cached entries. */
|
|
62
|
-
get size(): number;
|
|
63
|
-
/** Returns the total byte size of all cached response bodies. */
|
|
64
|
-
get totalSize(): number;
|
|
65
|
-
/** Clears all cached entries. */
|
|
66
|
-
clear(): void;
|
|
67
76
|
/**
|
|
68
|
-
*
|
|
77
|
+
* Returns the number of entries in the cache.
|
|
78
|
+
*
|
|
79
|
+
* @returns {number} The entry count.
|
|
69
80
|
*/
|
|
70
|
-
|
|
81
|
+
get size(): number;
|
|
71
82
|
/**
|
|
72
|
-
*
|
|
83
|
+
* Returns the total size of cached bodies in bytes.
|
|
84
|
+
*
|
|
85
|
+
* @returns {number} Total cached body size.
|
|
73
86
|
*/
|
|
74
|
-
|
|
87
|
+
get totalSize(): number;
|
|
75
88
|
/**
|
|
76
|
-
*
|
|
89
|
+
* Removes all entries from the cache.
|
|
77
90
|
*/
|
|
78
|
-
|
|
91
|
+
clear(): void;
|
|
79
92
|
/**
|
|
80
|
-
*
|
|
81
|
-
*
|
|
93
|
+
* Removes a single cache entry by method and URL.
|
|
94
|
+
*
|
|
95
|
+
* @param {string} method - The HTTP method.
|
|
96
|
+
* @param {string} url - The request URL.
|
|
97
|
+
* @returns {boolean} `true` if an entry was removed.
|
|
82
98
|
*/
|
|
99
|
+
delete(method: string, url: string): boolean;
|
|
100
|
+
private varyMatches;
|
|
101
|
+
private findLRUKey;
|
|
83
102
|
private evictIfNeeded;
|
|
84
103
|
}
|
|
85
104
|
/**
|
|
86
|
-
* Parses a
|
|
105
|
+
* Parses a Cache-Control header value into structured directives.
|
|
106
|
+
*
|
|
107
|
+
* @param {string} value - The raw Cache-Control header value.
|
|
108
|
+
* @returns {CacheDirectives} The parsed directives.
|
|
87
109
|
*/
|
|
88
110
|
export declare function parseCacheControl(value: string): CacheDirectives;
|
|
89
111
|
//# sourceMappingURL=store.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/cache/store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,UAAU,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACzG,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../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