repocairn 0.1.3 → 0.1.4
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 +6 -0
- package/dist/graphify-source.d.ts +17 -0
- package/dist/graphify-source.js +87 -0
- package/dist/graphify-source.js.map +1 -0
- package/dist/index-command.js +3 -1
- package/dist/index-command.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/indexer.d.ts +1 -0
- package/dist/indexer.js +1 -1
- package/dist/indexer.js.map +1 -1
- package/dist/signals.d.ts +13 -0
- package/dist/signals.js +84 -0
- package/dist/signals.js.map +1 -0
- package/node_modules/body-parser/node_modules/content-type/README.md +2 -0
- package/node_modules/body-parser/node_modules/content-type/dist/index.d.ts +20 -0
- package/node_modules/body-parser/node_modules/content-type/dist/index.js +20 -14
- package/node_modules/body-parser/node_modules/content-type/dist/index.js.map +1 -1
- package/node_modules/body-parser/node_modules/content-type/package.json +1 -1
- package/node_modules/eventsource-parser/dist/index.cjs +2 -2
- package/node_modules/eventsource-parser/dist/index.cjs.map +1 -1
- package/node_modules/eventsource-parser/dist/index.js +2 -2
- package/node_modules/eventsource-parser/dist/index.js.map +1 -1
- package/node_modules/eventsource-parser/package.json +1 -1
- package/node_modules/eventsource-parser/src/parse.ts +4 -2
- package/node_modules/express-rate-limit/dist/index.cjs +6 -1
- package/node_modules/express-rate-limit/dist/index.mjs +6 -1
- package/node_modules/express-rate-limit/package.json +6 -6
- package/node_modules/fast-uri/index.js +37 -1
- package/node_modules/fast-uri/package.json +1 -1
- package/node_modules/fast-uri/test/security.test.js +136 -0
- package/node_modules/hono/dist/cjs/client/client.js +3 -3
- package/node_modules/hono/dist/cjs/client/utils.js +1 -1
- package/node_modules/hono/dist/cjs/context.js +32 -13
- package/node_modules/hono/dist/cjs/helper/proxy/index.js +4 -0
- package/node_modules/hono/dist/cjs/hono-base.js +3 -2
- package/node_modules/hono/dist/cjs/jsx/base.js +27 -23
- package/node_modules/hono/dist/cjs/jsx/hooks/index.js +16 -13
- package/node_modules/hono/dist/cjs/jsx/intrinsic-element/components.js +1 -1
- package/node_modules/hono/dist/cjs/middleware/cache/index.js +103 -8
- package/node_modules/hono/dist/cjs/middleware/compress/index.js +5 -0
- package/node_modules/hono/dist/cjs/middleware/cors/index.js +17 -14
- package/node_modules/hono/dist/cjs/middleware/csrf/index.js +1 -1
- package/node_modules/hono/dist/cjs/middleware/etag/digest.js +47 -1
- package/node_modules/hono/dist/cjs/middleware/etag/index.js +6 -3
- package/node_modules/hono/dist/cjs/middleware/jwk/jwk.js +9 -4
- package/node_modules/hono/dist/cjs/middleware/jwt/jwt.js +9 -4
- package/node_modules/hono/dist/cjs/middleware/language/language.js +10 -6
- package/node_modules/hono/dist/cjs/middleware/method-not-allowed/index.js +90 -0
- package/node_modules/hono/dist/cjs/middleware/pretty-json/index.js +3 -1
- package/node_modules/hono/dist/cjs/middleware/secure-headers/secure-headers.js +6 -3
- package/node_modules/hono/dist/cjs/request.js +6 -8
- package/node_modules/hono/dist/cjs/router/linear-router/router.js +7 -2
- package/node_modules/hono/dist/cjs/router/pattern-router/router.js +3 -9
- package/node_modules/hono/dist/cjs/router/reg-exp-router/node.js +55 -56
- package/node_modules/hono/dist/cjs/router/reg-exp-router/router.js +64 -85
- package/node_modules/hono/dist/cjs/router/reg-exp-router/trie.js +13 -5
- package/node_modules/hono/dist/cjs/router/trie-router/node.js +44 -68
- package/node_modules/hono/dist/cjs/router/trie-router/router.js +3 -11
- package/node_modules/hono/dist/cjs/router.js +1 -1
- package/node_modules/hono/dist/cjs/utils/cookie.js +3 -2
- package/node_modules/hono/dist/cjs/utils/ipaddr.js +5 -3
- package/node_modules/hono/dist/cjs/utils/stream.js +5 -2
- package/node_modules/hono/dist/cjs/utils/url.js +9 -9
- package/node_modules/hono/dist/client/client.js +3 -3
- package/node_modules/hono/dist/client/utils.js +1 -1
- package/node_modules/hono/dist/context.js +32 -13
- package/node_modules/hono/dist/helper/proxy/index.js +4 -0
- package/node_modules/hono/dist/hono-base.js +3 -2
- package/node_modules/hono/dist/jsx/base.js +27 -23
- package/node_modules/hono/dist/jsx/hooks/index.js +16 -13
- package/node_modules/hono/dist/jsx/intrinsic-element/components.js +1 -1
- package/node_modules/hono/dist/middleware/cache/index.js +103 -8
- package/node_modules/hono/dist/middleware/compress/index.js +5 -0
- package/node_modules/hono/dist/middleware/cors/index.js +17 -14
- package/node_modules/hono/dist/middleware/csrf/index.js +1 -1
- package/node_modules/hono/dist/middleware/etag/digest.js +47 -1
- package/node_modules/hono/dist/middleware/etag/index.js +6 -3
- package/node_modules/hono/dist/middleware/jwk/jwk.js +9 -4
- package/node_modules/hono/dist/middleware/jwt/jwt.js +9 -4
- package/node_modules/hono/dist/middleware/language/language.js +10 -6
- package/node_modules/hono/dist/middleware/method-not-allowed/index.js +68 -0
- package/node_modules/hono/dist/middleware/pretty-json/index.js +3 -1
- package/node_modules/hono/dist/middleware/secure-headers/secure-headers.js +6 -3
- package/node_modules/hono/dist/request.js +7 -9
- package/node_modules/hono/dist/router/linear-router/router.js +7 -2
- package/node_modules/hono/dist/router/pattern-router/router.js +3 -9
- package/node_modules/hono/dist/router/reg-exp-router/node.js +55 -56
- package/node_modules/hono/dist/router/reg-exp-router/router.js +64 -85
- package/node_modules/hono/dist/router/reg-exp-router/trie.js +13 -5
- package/node_modules/hono/dist/router/trie-router/node.js +44 -68
- package/node_modules/hono/dist/router/trie-router/router.js +3 -11
- package/node_modules/hono/dist/router.js +1 -1
- package/node_modules/hono/dist/types/client/types.d.ts +1 -1
- package/node_modules/hono/dist/types/context.d.ts +4 -0
- package/node_modules/hono/dist/types/hono-base.d.ts +4 -3
- package/node_modules/hono/dist/types/jsx/base.d.ts +4 -2
- package/node_modules/hono/dist/types/jsx/dom/index.d.ts +5 -5
- package/node_modules/hono/dist/types/jsx/dom/intrinsic-element/components.d.ts +2 -2
- package/node_modules/hono/dist/types/jsx/dom/server.d.ts +5 -5
- package/node_modules/hono/dist/types/jsx/hooks/index.d.ts +8 -6
- package/node_modules/hono/dist/types/jsx/index.d.ts +5 -5
- package/node_modules/hono/dist/types/middleware/cache/index.d.ts +6 -4
- package/node_modules/hono/dist/types/middleware/cors/index.d.ts +1 -1
- package/node_modules/hono/dist/types/middleware/jsx-renderer/index.d.ts +2 -2
- package/node_modules/hono/dist/types/middleware/jwk/jwk.d.ts +2 -0
- package/node_modules/hono/dist/types/middleware/jwt/jwt.d.ts +2 -0
- package/node_modules/hono/dist/types/middleware/method-not-allowed/index.d.ts +49 -0
- package/node_modules/hono/dist/types/middleware/secure-headers/permissions-policy.d.ts +3 -3
- package/node_modules/hono/dist/types/router/reg-exp-router/node.d.ts +1 -1
- package/node_modules/hono/dist/types/router/reg-exp-router/trie.d.ts +2 -1
- package/node_modules/hono/dist/types/router/trie-router/node.d.ts +1 -2
- package/node_modules/hono/dist/types/router/trie-router/router.d.ts +0 -1
- package/node_modules/hono/dist/types/router.d.ts +1 -1
- package/node_modules/hono/dist/types/utils/headers.d.ts +2 -2
- package/node_modules/hono/dist/types/utils/url.d.ts +1 -0
- package/node_modules/hono/dist/utils/cookie.js +4 -3
- package/node_modules/hono/dist/utils/ipaddr.js +5 -3
- package/node_modules/hono/dist/utils/stream.js +5 -2
- package/node_modules/hono/dist/utils/url.js +7 -8
- package/node_modules/hono/package.json +10 -3
- package/node_modules/ip-address/README.md +163 -149
- package/node_modules/ip-address/dist/address-error.d.ts +11 -0
- package/node_modules/ip-address/dist/address-error.js.map +1 -1
- package/node_modules/ip-address/dist/common.d.ts +6 -0
- package/node_modules/ip-address/dist/common.js +17 -1
- package/node_modules/ip-address/dist/common.js.map +1 -1
- package/node_modules/ip-address/dist/ipv4.d.ts +22 -6
- package/node_modules/ip-address/dist/ipv4.js +25 -18
- package/node_modules/ip-address/dist/ipv4.js.map +1 -1
- package/node_modules/ip-address/dist/ipv6.d.ts +19 -5
- package/node_modules/ip-address/dist/ipv6.js +61 -33
- package/node_modules/ip-address/dist/ipv6.js.map +1 -1
- package/node_modules/ip-address/package.json +5 -3
- package/node_modules/jose/README.md +13 -13
- package/node_modules/jose/dist/types/index.d.ts +6 -5
- package/node_modules/jose/dist/types/jwe/compact/decrypt.d.ts +17 -11
- package/node_modules/jose/dist/types/jwe/compact/encrypt.d.ts +8 -19
- package/node_modules/jose/dist/types/jwe/flattened/decrypt.d.ts +17 -11
- package/node_modules/jose/dist/types/jwe/flattened/encrypt.d.ts +8 -19
- package/node_modules/jose/dist/types/jwe/general/decrypt.d.ts +18 -13
- package/node_modules/jose/dist/types/jwe/general/encrypt.d.ts +21 -21
- package/node_modules/jose/dist/types/jwk/embedded.d.ts +8 -12
- package/node_modules/jose/dist/types/jwk/thumbprint.d.ts +0 -15
- package/node_modules/jose/dist/types/jwks/local.d.ts +12 -21
- package/node_modules/jose/dist/types/jwks/remote.d.ts +34 -165
- package/node_modules/jose/dist/types/jws/compact/sign.d.ts +2 -13
- package/node_modules/jose/dist/types/jws/compact/verify.d.ts +17 -13
- package/node_modules/jose/dist/types/jws/flattened/sign.d.ts +2 -13
- package/node_modules/jose/dist/types/jws/flattened/verify.d.ts +17 -13
- package/node_modules/jose/dist/types/jws/general/sign.d.ts +16 -17
- package/node_modules/jose/dist/types/jws/general/verify.d.ts +18 -15
- package/node_modules/jose/dist/types/jwt/decrypt.d.ts +17 -11
- package/node_modules/jose/dist/types/jwt/encrypt.d.ts +11 -34
- package/node_modules/jose/dist/types/jwt/sign.d.ts +2 -13
- package/node_modules/jose/dist/types/jwt/unsecured.d.ts +4 -13
- package/node_modules/jose/dist/types/jwt/verify.d.ts +14 -13
- package/node_modules/jose/dist/types/key/export.d.ts +0 -14
- package/node_modules/jose/dist/types/key/generate_key_pair.d.ts +7 -14
- package/node_modules/jose/dist/types/key/generate_secret.d.ts +16 -14
- package/node_modules/jose/dist/types/key/import.d.ts +18 -28
- package/node_modules/jose/dist/types/types.d.ts +243 -224
- package/node_modules/jose/dist/types/util/base64url.d.ts +11 -4
- package/node_modules/jose/dist/types/util/decode_jwt.d.ts +1 -9
- package/node_modules/jose/dist/types/util/decode_protected_header.d.ts +0 -8
- package/node_modules/jose/dist/types/util/errors.d.ts +128 -121
- package/node_modules/jose/dist/webapi/jwe/compact/decrypt.js +4 -22
- package/node_modules/jose/dist/webapi/jwe/flattened/decrypt.js +5 -153
- package/node_modules/jose/dist/webapi/jwe/flattened/encrypt.js +16 -111
- package/node_modules/jose/dist/webapi/jwe/general/decrypt.js +23 -3
- package/node_modules/jose/dist/webapi/jwe/general/encrypt.js +70 -82
- package/node_modules/jose/dist/webapi/jwk/embedded.js +5 -3
- package/node_modules/jose/dist/webapi/jwks/local.js +32 -73
- package/node_modules/jose/dist/webapi/jwks/remote.js +19 -28
- package/node_modules/jose/dist/webapi/jws/compact/sign.js +5 -2
- package/node_modules/jose/dist/webapi/jws/compact/verify.js +4 -16
- package/node_modules/jose/dist/webapi/jws/flattened/sign.js +7 -65
- package/node_modules/jose/dist/webapi/jws/flattened/verify.js +3 -89
- package/node_modules/jose/dist/webapi/jws/general/sign.js +19 -15
- package/node_modules/jose/dist/webapi/jws/general/verify.js +29 -9
- package/node_modules/jose/dist/webapi/jwt/decrypt.js +5 -5
- package/node_modules/jose/dist/webapi/jwt/sign.js +2 -3
- package/node_modules/jose/dist/webapi/jwt/unsecured.js +4 -3
- package/node_modules/jose/dist/webapi/jwt/verify.js +6 -6
- package/node_modules/jose/dist/webapi/key/export.js +37 -4
- package/node_modules/jose/dist/webapi/key/generate_key_pair.js +33 -82
- package/node_modules/jose/dist/webapi/key/generate_secret.js +2 -2
- package/node_modules/jose/dist/webapi/key/import.js +8 -8
- package/node_modules/jose/dist/webapi/lib/asn1.js +53 -122
- package/node_modules/jose/dist/webapi/lib/buffer_utils.js +1 -0
- package/node_modules/jose/dist/webapi/lib/content_encryption.js +34 -109
- package/node_modules/jose/dist/webapi/lib/crypto_key.js +18 -126
- package/node_modules/jose/dist/webapi/lib/helpers.js +23 -0
- package/node_modules/jose/dist/webapi/lib/invalid_key_input.js +0 -1
- package/node_modules/jose/dist/webapi/lib/jwe_algorithms.js +107 -0
- package/node_modules/jose/dist/webapi/lib/jwe_decrypt.js +186 -0
- package/node_modules/jose/dist/webapi/lib/jwe_encrypt.js +114 -0
- package/node_modules/jose/dist/webapi/lib/jwk_to_key.js +8 -98
- package/node_modules/jose/dist/webapi/lib/jws_algorithms.js +73 -0
- package/node_modules/jose/dist/webapi/lib/jws_sign.js +74 -0
- package/node_modules/jose/dist/webapi/lib/jws_verify.js +107 -0
- package/node_modules/jose/dist/webapi/lib/jwt_claims_set.js +68 -109
- package/node_modules/jose/dist/webapi/lib/key.js +132 -0
- package/node_modules/jose/dist/webapi/lib/key_algorithm.js +10 -0
- package/node_modules/jose/dist/webapi/lib/key_descriptor.js +7 -0
- package/node_modules/jose/dist/webapi/lib/key_management.js +162 -92
- package/node_modules/jose/dist/webapi/lib/options.js +48 -0
- package/node_modules/jose/dist/webapi/lib/signing.js +14 -56
- package/node_modules/jose/dist/webapi/lib/type_checks.js +13 -18
- package/node_modules/jose/dist/webapi/util/base64url.js +13 -4
- package/node_modules/jose/dist/webapi/util/decode_jwt.js +2 -2
- package/node_modules/jose/dist/webapi/util/decode_protected_header.js +5 -15
- package/node_modules/jose/dist/webapi/util/errors.js +1 -1
- package/node_modules/jose/package.json +2 -4
- package/node_modules/type-is/node_modules/content-type/README.md +2 -0
- package/node_modules/type-is/node_modules/content-type/dist/index.d.ts +20 -0
- package/node_modules/type-is/node_modules/content-type/dist/index.js +20 -14
- package/node_modules/type-is/node_modules/content-type/dist/index.js.map +1 -1
- package/node_modules/type-is/node_modules/content-type/package.json +1 -1
- package/package.json +5 -3
- package/node_modules/jose/dist/webapi/lib/aesgcmkw.js +0 -15
- package/node_modules/jose/dist/webapi/lib/aeskw.js +0 -25
- package/node_modules/jose/dist/webapi/lib/check_key_type.js +0 -122
- package/node_modules/jose/dist/webapi/lib/ecdhes.js +0 -52
- package/node_modules/jose/dist/webapi/lib/key_to_jwk.js +0 -34
- package/node_modules/jose/dist/webapi/lib/normalize_key.js +0 -166
- package/node_modules/jose/dist/webapi/lib/pbes2kw.js +0 -42
- package/node_modules/jose/dist/webapi/lib/rsaes.js +0 -24
- package/node_modules/jose/dist/webapi/lib/validate_algorithms.js +0 -10
- package/node_modules/jose/dist/webapi/lib/validate_crit.js +0 -33
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
// src/middleware/cache/index.ts
|
|
2
|
+
import { cloneRawRequest } from "../../request.js";
|
|
3
|
+
import { sha256 } from "../../utils/crypto.js";
|
|
2
4
|
var defaultCacheableStatusCodes = [200];
|
|
5
|
+
var defaultMaxQueryBodySize = 64 * 1024;
|
|
6
|
+
var cacheKeyPath = "/.hono/cache";
|
|
7
|
+
var cacheKeyParameter = "__hono_cache_key";
|
|
8
|
+
var cacheMethodKeyParameter = "__hono_cache_method";
|
|
9
|
+
var queryDigestKeyParameter = "__hono_query_digest";
|
|
10
|
+
var cacheVaryKeyParameter = "__hono_cache_vary";
|
|
11
|
+
var queryRepresentationMetadataHeaders = [
|
|
12
|
+
"content-type",
|
|
13
|
+
"content-encoding",
|
|
14
|
+
"content-language",
|
|
15
|
+
"content-location"
|
|
16
|
+
];
|
|
3
17
|
var shouldSkipCacheControl = (cacheControl) => !!cacheControl && /(?:^|,\s*)(?:private|no-(?:store|cache))(?:\s*(?:=|,|$))/i.test(cacheControl);
|
|
4
18
|
var parseVaryDirectives = (vary) => {
|
|
5
19
|
if (vary == null) {
|
|
@@ -7,17 +21,86 @@ var parseVaryDirectives = (vary) => {
|
|
|
7
21
|
}
|
|
8
22
|
return (Array.isArray(vary) ? vary : vary.split(",")).map((directive) => directive.trim().toLowerCase()).filter(Boolean);
|
|
9
23
|
};
|
|
24
|
+
var createCacheKey = (key, requestUrl, request, varyHeaders) => {
|
|
25
|
+
const url = new URL(cacheKeyPath, requestUrl);
|
|
26
|
+
url.searchParams.append(cacheKeyParameter, key.split("#", 1)[0]);
|
|
27
|
+
url.searchParams.append(cacheMethodKeyParameter, request.method);
|
|
28
|
+
if (request.method === "QUERY") {
|
|
29
|
+
url.searchParams.append(queryDigestKeyParameter, request.digest);
|
|
30
|
+
}
|
|
31
|
+
for (const header of varyHeaders) {
|
|
32
|
+
url.searchParams.append(cacheVaryKeyParameter, JSON.stringify(header));
|
|
33
|
+
}
|
|
34
|
+
return url.href;
|
|
35
|
+
};
|
|
10
36
|
var shouldSkipCache = (res, optionsVaryDirectives, responseVary) => responseVary.length && (!optionsVaryDirectives || responseVary.some((name) => !optionsVaryDirectives.has(name))) || shouldSkipCacheControl(res.headers.get("Cache-Control")) || res.headers.has("Set-Cookie");
|
|
37
|
+
var reportCacheNotAvailable = (onCacheNotAvailable, reason) => {
|
|
38
|
+
if (onCacheNotAvailable === false) {
|
|
39
|
+
} else if (onCacheNotAvailable) {
|
|
40
|
+
onCacheNotAvailable(reason);
|
|
41
|
+
} else {
|
|
42
|
+
console.log(reason);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
var createQueryDigest = async (c, maxQueryBodySize) => {
|
|
46
|
+
if (!globalThis.crypto?.subtle) {
|
|
47
|
+
return void 0;
|
|
48
|
+
}
|
|
49
|
+
if (c.req.raw.bodyUsed && Object.keys(c.req.bodyCache)[0] === "formData") {
|
|
50
|
+
return void 0;
|
|
51
|
+
}
|
|
52
|
+
try {
|
|
53
|
+
const requestHeaders = c.req.raw.headers;
|
|
54
|
+
const metadata = new TextEncoder().encode(
|
|
55
|
+
JSON.stringify(
|
|
56
|
+
queryRepresentationMetadataHeaders.map((header) => [header, requestHeaders.get(header)])
|
|
57
|
+
)
|
|
58
|
+
);
|
|
59
|
+
const body = (await cloneRawRequest(c.req)).body;
|
|
60
|
+
const chunks = [];
|
|
61
|
+
let bodySize = 0;
|
|
62
|
+
if (body) {
|
|
63
|
+
const reader = body.getReader();
|
|
64
|
+
for (; ; ) {
|
|
65
|
+
const { done, value } = await reader.read();
|
|
66
|
+
if (done) {
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
bodySize += value.byteLength;
|
|
70
|
+
if (bodySize > maxQueryBodySize) {
|
|
71
|
+
void reader.cancel().catch(() => {
|
|
72
|
+
});
|
|
73
|
+
return void 0;
|
|
74
|
+
}
|
|
75
|
+
chunks.push(value);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const data = new Uint8Array(metadata.byteLength + bodySize);
|
|
79
|
+
data.set(metadata);
|
|
80
|
+
let offset = metadata.byteLength;
|
|
81
|
+
for (const chunk of chunks) {
|
|
82
|
+
data.set(chunk, offset);
|
|
83
|
+
offset += chunk.byteLength;
|
|
84
|
+
}
|
|
85
|
+
return await sha256(data) ?? void 0;
|
|
86
|
+
} catch {
|
|
87
|
+
return void 0;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
11
90
|
var cache = (options) => {
|
|
12
91
|
if (!globalThis.caches) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
console.log("Cache Middleware is not enabled because caches is not defined.");
|
|
18
|
-
}
|
|
92
|
+
reportCacheNotAvailable(
|
|
93
|
+
options.onCacheNotAvailable,
|
|
94
|
+
"Cache Middleware is not enabled because caches is not defined."
|
|
95
|
+
);
|
|
19
96
|
return async (_c, next) => await next();
|
|
20
97
|
}
|
|
98
|
+
if (!globalThis.crypto?.subtle) {
|
|
99
|
+
reportCacheNotAvailable(
|
|
100
|
+
options.onCacheNotAvailable,
|
|
101
|
+
"Cache Middleware cannot cache QUERY requests because Web Crypto is not available."
|
|
102
|
+
);
|
|
103
|
+
}
|
|
21
104
|
if (options.wait === void 0) {
|
|
22
105
|
options.wait = false;
|
|
23
106
|
}
|
|
@@ -32,6 +115,7 @@ var cache = (options) => {
|
|
|
32
115
|
const cacheableStatusCodes = new Set(
|
|
33
116
|
options.cacheableStatusCodes ?? defaultCacheableStatusCodes
|
|
34
117
|
);
|
|
118
|
+
const maxQueryBodySize = options.maxQueryBodySize ?? defaultMaxQueryBodySize;
|
|
35
119
|
const addHeader = (c, responseVary) => {
|
|
36
120
|
if (cacheControlDirectives) {
|
|
37
121
|
const existingDirectives = c.res.headers.get("Cache-Control")?.split(",").map((d) => d.trim().split("=", 1)[0].toLowerCase()) ?? [];
|
|
@@ -60,20 +144,31 @@ var cache = (options) => {
|
|
|
60
144
|
}
|
|
61
145
|
};
|
|
62
146
|
return async function cache2(c, next) {
|
|
63
|
-
if (c.req.method !== "GET" || c.req.raw.headers.has("Authorization")) {
|
|
147
|
+
if (c.req.method !== "GET" && c.req.method !== "QUERY" || c.req.raw.headers.has("Authorization")) {
|
|
64
148
|
await next();
|
|
65
149
|
return;
|
|
66
150
|
}
|
|
151
|
+
let cacheKeyRequest = { method: "GET" };
|
|
152
|
+
if (c.req.method === "QUERY") {
|
|
153
|
+
const digest = await createQueryDigest(c, maxQueryBodySize);
|
|
154
|
+
if (digest === void 0) {
|
|
155
|
+
await next();
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
cacheKeyRequest = { method: "QUERY", digest };
|
|
159
|
+
}
|
|
67
160
|
let key = c.req.url;
|
|
68
161
|
if (options.keyGenerator) {
|
|
69
162
|
key = await options.keyGenerator(c);
|
|
70
163
|
}
|
|
164
|
+
const varyHeaders = [];
|
|
71
165
|
if (varyDirectives) {
|
|
72
166
|
for (const directive of varyDirectives) {
|
|
73
167
|
const value = c.req.raw.headers.get(directive) ?? "";
|
|
74
|
-
|
|
168
|
+
varyHeaders.push([directive, value]);
|
|
75
169
|
}
|
|
76
170
|
}
|
|
171
|
+
key = createCacheKey(key, c.req.url, cacheKeyRequest, varyHeaders);
|
|
77
172
|
const cacheName = typeof options.cacheName === "function" ? await options.cacheName(c) : options.cacheName;
|
|
78
173
|
const cache3 = await caches.open(cacheName);
|
|
79
174
|
const response = await cache3.match(key);
|
|
@@ -21,6 +21,7 @@ var selectEncoding = (header, candidates) => {
|
|
|
21
21
|
}
|
|
22
22
|
return best?.encoding;
|
|
23
23
|
};
|
|
24
|
+
var varyAcceptEncodingRegExp = /(?:^|,)\s*accept-encoding\s*(?:,|$)/i;
|
|
24
25
|
var compress = (options) => {
|
|
25
26
|
const threshold = options?.threshold ?? 1024;
|
|
26
27
|
const candidates = options?.encoding ? [options.encoding] : ENCODING_TYPES;
|
|
@@ -44,6 +45,10 @@ var compress = (options) => {
|
|
|
44
45
|
!shouldTransform(ctx.res)) {
|
|
45
46
|
return;
|
|
46
47
|
}
|
|
48
|
+
const current = ctx.res.headers.get("Vary");
|
|
49
|
+
if (current !== "*" && !(current && varyAcceptEncodingRegExp.test(current))) {
|
|
50
|
+
ctx.header("Vary", current ? `${current}, Accept-Encoding` : "Accept-Encoding");
|
|
51
|
+
}
|
|
47
52
|
const accepted = ctx.req.header("Accept-Encoding");
|
|
48
53
|
const encoding = selectEncoding(accepted, candidates);
|
|
49
54
|
if (!encoding || !ctx.res.body) {
|
|
@@ -2,11 +2,13 @@
|
|
|
2
2
|
var cors = (options) => {
|
|
3
3
|
const opts = {
|
|
4
4
|
origin: "*",
|
|
5
|
-
allowMethods: ["GET", "HEAD", "PUT", "POST", "DELETE", "PATCH"],
|
|
5
|
+
allowMethods: ["GET", "HEAD", "PUT", "POST", "DELETE", "PATCH", "QUERY"],
|
|
6
6
|
allowHeaders: [],
|
|
7
7
|
exposeHeaders: [],
|
|
8
8
|
...options
|
|
9
9
|
};
|
|
10
|
+
const exposeHeadersStr = opts.exposeHeaders?.length ? opts.exposeHeaders.join(",") : void 0;
|
|
11
|
+
const allowHeadersStr = opts.allowHeaders?.length ? opts.allowHeaders.join(",") : void 0;
|
|
10
12
|
const findAllowOrigin = ((optsOrigin) => {
|
|
11
13
|
if (typeof optsOrigin === "string") {
|
|
12
14
|
if (optsOrigin === "*") {
|
|
@@ -22,11 +24,12 @@ var cors = (options) => {
|
|
|
22
24
|
})(opts.origin);
|
|
23
25
|
const findAllowMethods = ((optsAllowMethods) => {
|
|
24
26
|
if (typeof optsAllowMethods === "function") {
|
|
25
|
-
return optsAllowMethods;
|
|
27
|
+
return async (origin, c) => (await optsAllowMethods(origin, c)).join(",");
|
|
26
28
|
} else if (Array.isArray(optsAllowMethods)) {
|
|
27
|
-
|
|
29
|
+
const methodsStr = optsAllowMethods.join(",");
|
|
30
|
+
return () => methodsStr;
|
|
28
31
|
} else {
|
|
29
|
-
return () =>
|
|
32
|
+
return () => "";
|
|
30
33
|
}
|
|
31
34
|
})(opts.allowMethods);
|
|
32
35
|
return async function cors2(c, next) {
|
|
@@ -40,29 +43,29 @@ var cors = (options) => {
|
|
|
40
43
|
if (opts.credentials) {
|
|
41
44
|
set("Access-Control-Allow-Credentials", "true");
|
|
42
45
|
}
|
|
43
|
-
if (
|
|
44
|
-
set("Access-Control-Expose-Headers",
|
|
46
|
+
if (exposeHeadersStr) {
|
|
47
|
+
set("Access-Control-Expose-Headers", exposeHeadersStr);
|
|
45
48
|
}
|
|
46
49
|
if (c.req.method === "OPTIONS") {
|
|
47
50
|
if (opts.origin !== "*") {
|
|
48
|
-
|
|
51
|
+
c.res.headers.append("Vary", "Origin");
|
|
49
52
|
}
|
|
50
53
|
if (opts.maxAge != null) {
|
|
51
54
|
set("Access-Control-Max-Age", opts.maxAge.toString());
|
|
52
55
|
}
|
|
53
56
|
const allowMethods = await findAllowMethods(c.req.header("origin") || "", c);
|
|
54
|
-
if (allowMethods
|
|
55
|
-
set("Access-Control-Allow-Methods", allowMethods
|
|
57
|
+
if (allowMethods) {
|
|
58
|
+
set("Access-Control-Allow-Methods", allowMethods);
|
|
56
59
|
}
|
|
57
|
-
let
|
|
58
|
-
if (!
|
|
60
|
+
let headersStr = allowHeadersStr;
|
|
61
|
+
if (!headersStr) {
|
|
59
62
|
const requestHeaders = c.req.header("Access-Control-Request-Headers");
|
|
60
63
|
if (requestHeaders) {
|
|
61
|
-
|
|
64
|
+
headersStr = requestHeaders.split(",").map((h) => h.trim()).join(",");
|
|
62
65
|
}
|
|
63
66
|
}
|
|
64
|
-
if (
|
|
65
|
-
set("Access-Control-Allow-Headers",
|
|
67
|
+
if (headersStr) {
|
|
68
|
+
set("Access-Control-Allow-Headers", headersStr);
|
|
66
69
|
c.res.headers.append("Vary", "Access-Control-Request-Headers");
|
|
67
70
|
}
|
|
68
71
|
c.res.headers.delete("Content-Length");
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { HTTPException } from "../../http-exception.js";
|
|
3
3
|
var secFetchSiteValues = ["same-origin", "same-site", "none", "cross-site"];
|
|
4
4
|
var isSecFetchSite = (value) => secFetchSiteValues.includes(value);
|
|
5
|
-
var isSafeMethodRe = /^(GET|HEAD)$/;
|
|
5
|
+
var isSafeMethodRe = /^(GET|HEAD|OPTIONS)$/;
|
|
6
6
|
var isRequestedByFormElementRe = /^\b(application\/x-www-form-urlencoded|multipart\/form-data|text\/plain)\b/i;
|
|
7
7
|
var csrf = (options) => {
|
|
8
8
|
const originHandler = ((optsOrigin) => {
|
|
@@ -10,18 +10,64 @@ var mergeBuffers = (buffer1, buffer2) => {
|
|
|
10
10
|
merged.set(buffer2, buffer1.byteLength);
|
|
11
11
|
return merged;
|
|
12
12
|
};
|
|
13
|
+
var CHUNK_SIZE = 256 * 1024;
|
|
13
14
|
var generateDigest = async (stream, generator) => {
|
|
14
15
|
if (!stream) {
|
|
15
16
|
return null;
|
|
16
17
|
}
|
|
17
18
|
let result = void 0;
|
|
19
|
+
let chunk;
|
|
20
|
+
let chunkLength = 0;
|
|
21
|
+
const digest = async (body) => {
|
|
22
|
+
result = await generator(mergeBuffers(result, body));
|
|
23
|
+
};
|
|
18
24
|
const reader = stream.getReader();
|
|
19
25
|
for (; ; ) {
|
|
20
26
|
const { value, done } = await reader.read();
|
|
21
27
|
if (done) {
|
|
22
28
|
break;
|
|
23
29
|
}
|
|
24
|
-
|
|
30
|
+
let offset = 0;
|
|
31
|
+
while (offset < value.byteLength) {
|
|
32
|
+
const remaining = value.byteLength - offset;
|
|
33
|
+
if (chunkLength === 0 && remaining >= CHUNK_SIZE) {
|
|
34
|
+
await digest(value.subarray(offset, offset + CHUNK_SIZE));
|
|
35
|
+
offset += CHUNK_SIZE;
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
const requiredLength = chunkLength + remaining;
|
|
39
|
+
if (requiredLength < CHUNK_SIZE) {
|
|
40
|
+
if (!chunk) {
|
|
41
|
+
chunk = value.slice(offset);
|
|
42
|
+
} else {
|
|
43
|
+
if (chunk.byteLength < requiredLength) {
|
|
44
|
+
const nextChunk = new Uint8Array(
|
|
45
|
+
new ArrayBuffer(Math.min(CHUNK_SIZE, Math.max(requiredLength, chunk.byteLength * 2)))
|
|
46
|
+
);
|
|
47
|
+
nextChunk.set(chunk.subarray(0, chunkLength));
|
|
48
|
+
chunk = nextChunk;
|
|
49
|
+
}
|
|
50
|
+
chunk.set(value.subarray(offset), chunkLength);
|
|
51
|
+
}
|
|
52
|
+
chunkLength = requiredLength;
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
const length = CHUNK_SIZE - chunkLength;
|
|
56
|
+
if (chunk?.byteLength !== CHUNK_SIZE) {
|
|
57
|
+
const nextChunk = new Uint8Array(new ArrayBuffer(CHUNK_SIZE));
|
|
58
|
+
if (chunk) {
|
|
59
|
+
nextChunk.set(chunk.subarray(0, chunkLength));
|
|
60
|
+
}
|
|
61
|
+
chunk = nextChunk;
|
|
62
|
+
}
|
|
63
|
+
chunk.set(value.subarray(offset, offset + length), chunkLength);
|
|
64
|
+
await digest(chunk);
|
|
65
|
+
chunkLength = 0;
|
|
66
|
+
offset += length;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (chunk && chunkLength > 0) {
|
|
70
|
+
await digest(chunk.subarray(0, chunkLength));
|
|
25
71
|
}
|
|
26
72
|
if (!result) {
|
|
27
73
|
return null;
|
|
@@ -32,6 +32,9 @@ var etag = (options) => {
|
|
|
32
32
|
return async function etag2(c, next) {
|
|
33
33
|
const ifNoneMatch = c.req.header("If-None-Match") ?? null;
|
|
34
34
|
await next();
|
|
35
|
+
if (!(c.req.method === "GET" || c.req.method === "HEAD" || c.req.method === "QUERY") || !c.res.ok) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
35
38
|
const res = c.res;
|
|
36
39
|
let etag3 = res.headers.get("ETag");
|
|
37
40
|
if (!etag3) {
|
|
@@ -48,7 +51,7 @@ var etag = (options) => {
|
|
|
48
51
|
}
|
|
49
52
|
etag3 = weak ? `W/"${hash}"` : `"${hash}"`;
|
|
50
53
|
}
|
|
51
|
-
const matched = ifNoneMatch === "*"
|
|
54
|
+
const matched = ifNoneMatch === "*" || etagMatches(etag3, ifNoneMatch);
|
|
52
55
|
if (matched) {
|
|
53
56
|
c.res = new Response(null, {
|
|
54
57
|
status: 304,
|
|
@@ -57,11 +60,11 @@ var etag = (options) => {
|
|
|
57
60
|
ETag: etag3
|
|
58
61
|
}
|
|
59
62
|
});
|
|
60
|
-
c.res.headers.
|
|
63
|
+
for (const key of Array.from(c.res.headers.keys())) {
|
|
61
64
|
if (retainedHeaders.indexOf(key.toLowerCase()) === -1) {
|
|
62
65
|
c.res.headers.delete(key);
|
|
63
66
|
}
|
|
64
|
-
}
|
|
67
|
+
}
|
|
65
68
|
} else {
|
|
66
69
|
c.res.headers.set("ETag", etag3);
|
|
67
70
|
}
|
|
@@ -24,7 +24,8 @@ var jwk = (options, init) => {
|
|
|
24
24
|
res: unauthorizedResponse({
|
|
25
25
|
ctx,
|
|
26
26
|
error: "invalid_request",
|
|
27
|
-
errDescription
|
|
27
|
+
errDescription,
|
|
28
|
+
realm: options.realm
|
|
28
29
|
})
|
|
29
30
|
});
|
|
30
31
|
} else {
|
|
@@ -62,7 +63,8 @@ var jwk = (options, init) => {
|
|
|
62
63
|
res: unauthorizedResponse({
|
|
63
64
|
ctx,
|
|
64
65
|
error: "invalid_request",
|
|
65
|
-
errDescription
|
|
66
|
+
errDescription,
|
|
67
|
+
realm: options.realm
|
|
66
68
|
})
|
|
67
69
|
});
|
|
68
70
|
}
|
|
@@ -89,7 +91,8 @@ var jwk = (options, init) => {
|
|
|
89
91
|
ctx,
|
|
90
92
|
error: "invalid_token",
|
|
91
93
|
statusText: "Unauthorized",
|
|
92
|
-
errDescription: "token verification failure"
|
|
94
|
+
errDescription: "token verification failure",
|
|
95
|
+
realm: options.realm
|
|
93
96
|
}),
|
|
94
97
|
cause
|
|
95
98
|
});
|
|
@@ -99,11 +102,13 @@ var jwk = (options, init) => {
|
|
|
99
102
|
};
|
|
100
103
|
};
|
|
101
104
|
function unauthorizedResponse(opts) {
|
|
105
|
+
const realm = (opts.realm ?? opts.ctx.req.url).replace(/"/g, '\\"');
|
|
106
|
+
const errDescription = opts.errDescription.replace(/"/g, '\\"');
|
|
102
107
|
return new Response("Unauthorized", {
|
|
103
108
|
status: 401,
|
|
104
109
|
statusText: opts.statusText,
|
|
105
110
|
headers: {
|
|
106
|
-
"WWW-Authenticate": `Bearer realm="${
|
|
111
|
+
"WWW-Authenticate": `Bearer realm="${realm}",error="${opts.error}",error_description="${errDescription}"`
|
|
107
112
|
}
|
|
108
113
|
});
|
|
109
114
|
}
|
|
@@ -27,7 +27,8 @@ var jwt = (options) => {
|
|
|
27
27
|
res: unauthorizedResponse({
|
|
28
28
|
ctx,
|
|
29
29
|
error: "invalid_request",
|
|
30
|
-
errDescription
|
|
30
|
+
errDescription,
|
|
31
|
+
realm: options.realm
|
|
31
32
|
})
|
|
32
33
|
});
|
|
33
34
|
} else {
|
|
@@ -62,7 +63,8 @@ var jwt = (options) => {
|
|
|
62
63
|
res: unauthorizedResponse({
|
|
63
64
|
ctx,
|
|
64
65
|
error: "invalid_request",
|
|
65
|
-
errDescription
|
|
66
|
+
errDescription,
|
|
67
|
+
realm: options.realm
|
|
66
68
|
})
|
|
67
69
|
});
|
|
68
70
|
}
|
|
@@ -83,7 +85,8 @@ var jwt = (options) => {
|
|
|
83
85
|
ctx,
|
|
84
86
|
error: "invalid_token",
|
|
85
87
|
statusText: "Unauthorized",
|
|
86
|
-
errDescription: "token verification failure"
|
|
88
|
+
errDescription: "token verification failure",
|
|
89
|
+
realm: options.realm
|
|
87
90
|
}),
|
|
88
91
|
cause
|
|
89
92
|
});
|
|
@@ -93,11 +96,13 @@ var jwt = (options) => {
|
|
|
93
96
|
};
|
|
94
97
|
};
|
|
95
98
|
function unauthorizedResponse(opts) {
|
|
99
|
+
const realm = (opts.realm ?? opts.ctx.req.url).replace(/"/g, '\\"');
|
|
100
|
+
const errDescription = opts.errDescription.replace(/"/g, '\\"');
|
|
96
101
|
return new Response("Unauthorized", {
|
|
97
102
|
status: 401,
|
|
98
103
|
statusText: opts.statusText,
|
|
99
104
|
headers: {
|
|
100
|
-
"WWW-Authenticate": `Bearer realm="${
|
|
105
|
+
"WWW-Authenticate": `Bearer realm="${realm}",error="${opts.error}",error_description="${errDescription}"`
|
|
101
106
|
}
|
|
102
107
|
});
|
|
103
108
|
}
|
|
@@ -39,14 +39,18 @@ var normalizeLanguage = (lang, options) => {
|
|
|
39
39
|
if (exactIndex !== -1) {
|
|
40
40
|
return options.supportedLanguages[exactIndex];
|
|
41
41
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const
|
|
46
|
-
if (
|
|
47
|
-
|
|
42
|
+
let longestMatchIndex = -1;
|
|
43
|
+
let longestMatchLength = -1;
|
|
44
|
+
for (let i = 0; i < compSupported.length; i++) {
|
|
45
|
+
const candidate = compSupported[i];
|
|
46
|
+
if (candidate.length < compLang.length && candidate.length > longestMatchLength && compLang.startsWith(candidate) && compLang[candidate.length] === "-") {
|
|
47
|
+
longestMatchIndex = i;
|
|
48
|
+
longestMatchLength = candidate.length;
|
|
48
49
|
}
|
|
49
50
|
}
|
|
51
|
+
if (longestMatchIndex !== -1) {
|
|
52
|
+
return options.supportedLanguages[longestMatchIndex];
|
|
53
|
+
}
|
|
50
54
|
return void 0;
|
|
51
55
|
} catch {
|
|
52
56
|
return void 0;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// src/middleware/method-not-allowed/index.ts
|
|
2
|
+
import { basePath, matchedRoutes } from "../../helper/route/index.js";
|
|
3
|
+
import { METHOD_NAME_ALL } from "../../router.js";
|
|
4
|
+
import { TrieRouter } from "../../router/trie-router/index.js";
|
|
5
|
+
var methodNotAllowed = (options) => {
|
|
6
|
+
let methodRouter;
|
|
7
|
+
return async function methodNotAllowed2(c, next) {
|
|
8
|
+
const routeIndex = c.req.routeIndex;
|
|
9
|
+
await next();
|
|
10
|
+
if (c.res.status !== 404) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
if (c.error) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
if (!methodRouter) {
|
|
17
|
+
const methodsByPath = /* @__PURE__ */ new Map();
|
|
18
|
+
for (const route of options.app.routes) {
|
|
19
|
+
if (route.method === METHOD_NAME_ALL || route.method === "HEAD") {
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
const methods2 = methodsByPath.get(route.path) ?? /* @__PURE__ */ new Set();
|
|
23
|
+
methods2.add(route.method);
|
|
24
|
+
if (route.method === "GET") {
|
|
25
|
+
methods2.add("HEAD");
|
|
26
|
+
}
|
|
27
|
+
methodsByPath.set(route.path, methods2);
|
|
28
|
+
}
|
|
29
|
+
methodRouter = new TrieRouter();
|
|
30
|
+
for (const [path, methods2] of methodsByPath) {
|
|
31
|
+
methodRouter.add(METHOD_NAME_ALL, path, [...methods2]);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
let requestPath = c.req.path;
|
|
35
|
+
const routes = matchedRoutes(c);
|
|
36
|
+
const currentRoute = routes[routeIndex];
|
|
37
|
+
const sourceRoute = options.app.routes.find((route) => route.handler === methodNotAllowed2);
|
|
38
|
+
if (currentRoute && sourceRoute) {
|
|
39
|
+
const currentBasePathParts = basePath(c, routeIndex).split("/").filter(Boolean);
|
|
40
|
+
const sourceBasePathLength = sourceRoute.basePath.split("/").filter(Boolean).length;
|
|
41
|
+
const mountBasePathParts = currentBasePathParts.slice(
|
|
42
|
+
0,
|
|
43
|
+
currentBasePathParts.length - sourceBasePathLength
|
|
44
|
+
);
|
|
45
|
+
if (mountBasePathParts.length > 0) {
|
|
46
|
+
const mountBasePath = `/${mountBasePathParts.join("/")}`;
|
|
47
|
+
requestPath = c.req.path.slice(mountBasePath.length) || "/";
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
const allowedMethods = /* @__PURE__ */ new Set();
|
|
51
|
+
for (const [methods2] of methodRouter.match(METHOD_NAME_ALL, requestPath)[0]) {
|
|
52
|
+
for (const method of methods2) {
|
|
53
|
+
allowedMethods.add(method);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (allowedMethods.size === 0 || allowedMethods.has(c.req.method)) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
c.res.headers.delete("Allow");
|
|
60
|
+
c.res.headers.delete("Content-Length");
|
|
61
|
+
const methods = [...allowedMethods];
|
|
62
|
+
const allow = methods.join(", ");
|
|
63
|
+
c.res = options.onMethodNotAllowed ? await options.onMethodNotAllowed(c, methods) : c.text("Method Not Allowed", 405, { Allow: allow });
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
export {
|
|
67
|
+
methodNotAllowed
|
|
68
|
+
};
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
// src/middleware/pretty-json/index.ts
|
|
2
|
+
var jsonContentTypeRegex = /^application\/(?:[a-z0-9._-]+\+)?json(?=$|[;\s])/i;
|
|
2
3
|
var prettyJSON = (options) => {
|
|
3
4
|
const targetQuery = options?.query ?? "pretty";
|
|
4
5
|
return async function prettyJSON2(c, next) {
|
|
5
6
|
const pretty = options?.force || c.req.query(targetQuery) || c.req.query(targetQuery) === "";
|
|
6
7
|
await next();
|
|
7
|
-
|
|
8
|
+
const contentType = c.res.headers.get("Content-Type");
|
|
9
|
+
if (pretty && contentType && jsonContentTypeRegex.test(contentType)) {
|
|
8
10
|
const obj = await c.res.json();
|
|
9
11
|
c.res = new Response(JSON.stringify(obj, null, options?.space ?? 2), c.res);
|
|
10
12
|
}
|
|
@@ -137,14 +137,17 @@ function getPermissionsPolicyDirectives(policy) {
|
|
|
137
137
|
return Object.entries(policy).map(([directive, value]) => {
|
|
138
138
|
const kebabDirective = camelToKebab(directive);
|
|
139
139
|
if (typeof value === "boolean") {
|
|
140
|
-
return `${kebabDirective}=${value ? "*" : "
|
|
140
|
+
return `${kebabDirective}=${value ? "*" : "()"}`;
|
|
141
141
|
}
|
|
142
142
|
if (Array.isArray(value)) {
|
|
143
143
|
if (value.length === 0) {
|
|
144
144
|
return `${kebabDirective}=()`;
|
|
145
145
|
}
|
|
146
|
-
if (value.length === 1 &&
|
|
147
|
-
return `${kebabDirective}
|
|
146
|
+
if (value.length === 1 && value[0] === "*") {
|
|
147
|
+
return `${kebabDirective}=*`;
|
|
148
|
+
}
|
|
149
|
+
if (value.length === 1 && value[0] === "none") {
|
|
150
|
+
return `${kebabDirective}=()`;
|
|
148
151
|
}
|
|
149
152
|
const allowlist = value.map((item) => ["self", "src"].includes(item) ? item : `"${item}"`);
|
|
150
153
|
return `${kebabDirective}=(${allowlist.join(" ")})`;
|
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
import { HTTPException } from "./http-exception.js";
|
|
3
3
|
import { GET_MATCH_RESULT } from "./request/constants.js";
|
|
4
4
|
import { parseBody } from "./utils/body.js";
|
|
5
|
-
import {
|
|
6
|
-
var tryDecodeURIComponent = (str) => tryDecode(str, decodeURIComponent_);
|
|
5
|
+
import { getQueryParam, getQueryParams, tryDecodeURIComponent } from "./utils/url.js";
|
|
7
6
|
var HonoRequest = class {
|
|
8
7
|
/**
|
|
9
8
|
* `.raw` can get the raw Request object.
|
|
@@ -42,7 +41,6 @@ var HonoRequest = class {
|
|
|
42
41
|
this.raw = request;
|
|
43
42
|
this.path = path;
|
|
44
43
|
this.#matchResult = matchResult;
|
|
45
|
-
this.#validatedData = {};
|
|
46
44
|
}
|
|
47
45
|
param(key) {
|
|
48
46
|
return key ? this.#getDecodedParam(key) : this.#getAllDecodedParams();
|
|
@@ -50,7 +48,7 @@ var HonoRequest = class {
|
|
|
50
48
|
#getDecodedParam(key) {
|
|
51
49
|
const paramKey = this.#matchResult[0][this.routeIndex][1][key];
|
|
52
50
|
const param = this.#getParamValue(paramKey);
|
|
53
|
-
return param &&
|
|
51
|
+
return param && tryDecodeURIComponent(param);
|
|
54
52
|
}
|
|
55
53
|
#getAllDecodedParams() {
|
|
56
54
|
const decoded = {};
|
|
@@ -58,7 +56,7 @@ var HonoRequest = class {
|
|
|
58
56
|
for (const key of keys) {
|
|
59
57
|
const value = this.#getParamValue(this.#matchResult[0][this.routeIndex][1][key]);
|
|
60
58
|
if (value !== void 0) {
|
|
61
|
-
decoded[key] =
|
|
59
|
+
decoded[key] = tryDecodeURIComponent(value);
|
|
62
60
|
}
|
|
63
61
|
}
|
|
64
62
|
return decoded;
|
|
@@ -91,8 +89,7 @@ var HonoRequest = class {
|
|
|
91
89
|
if (cachedBody) {
|
|
92
90
|
return cachedBody;
|
|
93
91
|
}
|
|
94
|
-
const anyCachedKey
|
|
95
|
-
if (anyCachedKey) {
|
|
92
|
+
for (const anyCachedKey in bodyCache) {
|
|
96
93
|
return bodyCache[anyCachedKey].then((body) => {
|
|
97
94
|
if (anyCachedKey === "json") {
|
|
98
95
|
body = JSON.stringify(body);
|
|
@@ -195,10 +192,11 @@ var HonoRequest = class {
|
|
|
195
192
|
* @param data - The validated data to add.
|
|
196
193
|
*/
|
|
197
194
|
addValidatedData(target, data) {
|
|
198
|
-
|
|
195
|
+
;
|
|
196
|
+
(this.#validatedData ??= {})[target] = data;
|
|
199
197
|
}
|
|
200
198
|
valid(target) {
|
|
201
|
-
return this.#validatedData[target];
|
|
199
|
+
return this.#validatedData?.[target];
|
|
202
200
|
}
|
|
203
201
|
/**
|
|
204
202
|
* `.url()` can get the request url strings.
|
|
@@ -29,7 +29,8 @@ var LinearRouter = class {
|
|
|
29
29
|
}
|
|
30
30
|
} else if (hasStar && !hasLabel) {
|
|
31
31
|
const endsWithStar = routePath.charCodeAt(routePath.length - 1) === 42;
|
|
32
|
-
const
|
|
32
|
+
const endsWithSlashStar = routePath.endsWith("/*");
|
|
33
|
+
const parts = (endsWithStar ? routePath.slice(0, endsWithSlashStar ? -2 : -1) : routePath).split(splitByStarRe);
|
|
33
34
|
const lastIndex = parts.length - 1;
|
|
34
35
|
for (let j = 0, pos = 0, len2 = parts.length; j < len2; j++) {
|
|
35
36
|
const part = parts[j];
|
|
@@ -39,7 +40,11 @@ var LinearRouter = class {
|
|
|
39
40
|
}
|
|
40
41
|
pos += part.length;
|
|
41
42
|
if (j === lastIndex) {
|
|
42
|
-
if (
|
|
43
|
+
if (endsWithSlashStar) {
|
|
44
|
+
if (pos !== path.length && path.charCodeAt(pos) !== 47) {
|
|
45
|
+
continue ROUTES_LOOP;
|
|
46
|
+
}
|
|
47
|
+
} else if (!endsWithStar && pos !== path.length && !(pos === path.length - 1 && path.charCodeAt(pos) === 47)) {
|
|
43
48
|
continue ROUTES_LOOP;
|
|
44
49
|
}
|
|
45
50
|
} else {
|