@orchestraai/agent-tools 0.10.16 → 0.10.17
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/.agents/plugins/marketplace.json +1 -1
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/.codex-plugin/plugin.json +1 -1
- package/.cursor-plugin/plugin.json +1 -1
- package/.devin/adapter.json +1 -1
- package/.hermes/adapter.json +1 -1
- package/.opencode/adapter.json +1 -1
- package/dist/commands/claude-setup.d.ts +1 -1
- package/dist/runtime/conversation/command-guard.js +1023 -63
- package/dist/runtime/conversation/command-guard.js.map +1 -1
- package/dist/runtime/conversation/shell-parse.d.ts +42 -0
- package/dist/runtime/conversation/shell-parse.js +517 -0
- package/dist/runtime/conversation/shell-parse.js.map +1 -0
- package/docs/security.md +11 -2
- package/node_modules/@hono/node-server/dist/index.cjs +63 -17
- package/node_modules/@hono/node-server/dist/index.mjs +63 -17
- package/node_modules/@hono/node-server/dist/serve-static.cjs +1 -1
- package/node_modules/@hono/node-server/dist/serve-static.mjs +1 -1
- package/node_modules/@hono/node-server/package.json +1 -1
- package/node_modules/cross-spawn/README.md +19 -3
- package/node_modules/cross-spawn/lib/parse.js +38 -10
- package/node_modules/cross-spawn/lib/util/escape.js +84 -25
- package/node_modules/cross-spawn/lib/util/readShebang.js +8 -2
- package/node_modules/cross-spawn/lib/util/resolveCommand.js +8 -1
- package/node_modules/cross-spawn/package.json +21 -24
- package/node_modules/hono/README.md +2 -3
- package/node_modules/hono/dist/adapter/aws-lambda/handler.js +2 -2
- package/node_modules/hono/dist/adapter/bun/websocket.js +19 -4
- package/node_modules/hono/dist/adapter/lambda-edge/handler.js +5 -1
- package/node_modules/hono/dist/cjs/adapter/aws-lambda/handler.js +2 -2
- package/node_modules/hono/dist/cjs/adapter/bun/websocket.js +19 -4
- package/node_modules/hono/dist/cjs/adapter/lambda-edge/handler.js +5 -1
- package/node_modules/hono/dist/cjs/client/fetch-result-please.js +1 -1
- package/node_modules/hono/dist/cjs/client/utils.js +9 -5
- package/node_modules/hono/dist/cjs/context.js +1 -1
- package/node_modules/hono/dist/cjs/helper/accepts/accepts.js +7 -1
- package/node_modules/hono/dist/cjs/helper/css/common.js +11 -8
- package/node_modules/hono/dist/cjs/helper/css/index.js +1 -1
- package/node_modules/hono/dist/cjs/helper/proxy/index.js +2 -0
- package/node_modules/hono/dist/cjs/helper/route/index.js +3 -1
- package/node_modules/hono/dist/cjs/helper/ssg/ssg.js +5 -3
- package/node_modules/hono/dist/cjs/helper/streaming/sse.js +6 -2
- package/node_modules/hono/dist/cjs/hono-base.js +9 -10
- package/node_modules/hono/dist/cjs/hono.js +0 -1
- package/node_modules/hono/dist/cjs/jsx/base.js +51 -32
- package/node_modules/hono/dist/cjs/jsx/components.js +2 -2
- package/node_modules/hono/dist/cjs/jsx/constants.js +2 -0
- package/node_modules/hono/dist/cjs/jsx/context.js +15 -2
- package/node_modules/hono/dist/cjs/jsx/dom/components.js +1 -1
- package/node_modules/hono/dist/cjs/jsx/dom/hooks/index.js +38 -8
- package/node_modules/hono/dist/cjs/jsx/dom/intrinsic-element/components.js +8 -5
- package/node_modules/hono/dist/cjs/jsx/dom/render.js +9 -3
- package/node_modules/hono/dist/cjs/jsx/jsx-runtime.js +13 -17
- package/node_modules/hono/dist/cjs/middleware/basic-auth/index.js +3 -1
- package/node_modules/hono/dist/cjs/middleware/bearer-auth/index.js +9 -1
- package/node_modules/hono/dist/cjs/middleware/body-limit/index.js +9 -10
- package/node_modules/hono/dist/cjs/middleware/combine/index.js +4 -0
- package/node_modules/hono/dist/cjs/middleware/compress/index.js +2 -3
- package/node_modules/hono/dist/cjs/middleware/csrf/index.js +2 -2
- package/node_modules/hono/dist/cjs/middleware/etag/index.js +3 -1
- package/node_modules/hono/dist/cjs/middleware/jwk/jwk.js +2 -2
- package/node_modules/hono/dist/cjs/middleware/jwt/jwt.js +2 -2
- package/node_modules/hono/dist/cjs/middleware/method-not-allowed/index.js +1 -1
- package/node_modules/hono/dist/cjs/middleware/method-override/index.js +35 -12
- package/node_modules/hono/dist/cjs/middleware/mount/index.js +5 -4
- package/node_modules/hono/dist/cjs/middleware/pretty-json/index.js +1 -0
- package/node_modules/hono/dist/cjs/middleware/request-id/request-id.js +3 -3
- package/node_modules/hono/dist/cjs/middleware/secure-headers/secure-headers.js +6 -3
- package/node_modules/hono/dist/cjs/middleware/serve-static/index.js +4 -2
- package/node_modules/hono/dist/cjs/middleware/timing/timing.js +4 -3
- package/node_modules/hono/dist/cjs/router/reg-exp-router/node.js +13 -11
- package/node_modules/hono/dist/cjs/router/reg-exp-router/prepared-router.js +4 -4
- package/node_modules/hono/dist/cjs/router/reg-exp-router/router.js +39 -51
- package/node_modules/hono/dist/cjs/router/reg-exp-router/trie.js +15 -5
- package/node_modules/hono/dist/cjs/router/trie-router/node.js +6 -4
- package/node_modules/hono/dist/cjs/utils/body.js +2 -1
- package/node_modules/hono/dist/cjs/utils/cookie.js +3 -3
- package/node_modules/hono/dist/cjs/utils/html.js +5 -0
- package/node_modules/hono/dist/cjs/utils/jwt/jwt.js +8 -5
- package/node_modules/hono/dist/cjs/utils/mime.js +3 -2
- package/node_modules/hono/dist/cjs/utils/mount.js +59 -0
- package/node_modules/hono/dist/cjs/utils/url.js +23 -11
- package/node_modules/hono/dist/cjs/validator/validator.js +5 -5
- package/node_modules/hono/dist/client/fetch-result-please.js +1 -1
- package/node_modules/hono/dist/client/utils.js +9 -5
- package/node_modules/hono/dist/context.js +1 -1
- package/node_modules/hono/dist/helper/accepts/accepts.js +7 -1
- package/node_modules/hono/dist/helper/css/common.js +11 -8
- package/node_modules/hono/dist/helper/css/index.js +1 -1
- package/node_modules/hono/dist/helper/proxy/index.js +2 -0
- package/node_modules/hono/dist/helper/route/index.js +3 -1
- package/node_modules/hono/dist/helper/ssg/ssg.js +5 -3
- package/node_modules/hono/dist/helper/streaming/sse.js +6 -2
- package/node_modules/hono/dist/hono-base.js +9 -10
- package/node_modules/hono/dist/hono.js +0 -1
- package/node_modules/hono/dist/jsx/base.js +51 -34
- package/node_modules/hono/dist/jsx/components.js +2 -2
- package/node_modules/hono/dist/jsx/constants.js +2 -1
- package/node_modules/hono/dist/jsx/context.js +15 -2
- package/node_modules/hono/dist/jsx/dom/components.js +2 -2
- package/node_modules/hono/dist/jsx/dom/hooks/index.js +39 -9
- package/node_modules/hono/dist/jsx/dom/intrinsic-element/components.js +8 -5
- package/node_modules/hono/dist/jsx/dom/render.js +9 -3
- package/node_modules/hono/dist/jsx/jsx-runtime.js +15 -19
- package/node_modules/hono/dist/middleware/basic-auth/index.js +3 -1
- package/node_modules/hono/dist/middleware/bearer-auth/index.js +9 -1
- package/node_modules/hono/dist/middleware/body-limit/index.js +9 -10
- package/node_modules/hono/dist/middleware/combine/index.js +4 -0
- package/node_modules/hono/dist/middleware/compress/index.js +2 -3
- package/node_modules/hono/dist/middleware/csrf/index.js +2 -2
- package/node_modules/hono/dist/middleware/etag/index.js +3 -1
- package/node_modules/hono/dist/middleware/jwk/jwk.js +2 -2
- package/node_modules/hono/dist/middleware/jwt/jwt.js +2 -2
- package/node_modules/hono/dist/middleware/method-not-allowed/index.js +1 -1
- package/node_modules/hono/dist/middleware/method-override/index.js +35 -12
- package/node_modules/hono/dist/middleware/mount/index.js +5 -4
- package/node_modules/hono/dist/middleware/pretty-json/index.js +1 -0
- package/node_modules/hono/dist/middleware/request-id/request-id.js +3 -3
- package/node_modules/hono/dist/middleware/secure-headers/secure-headers.js +6 -3
- package/node_modules/hono/dist/middleware/serve-static/index.js +4 -2
- package/node_modules/hono/dist/middleware/timing/timing.js +4 -3
- package/node_modules/hono/dist/router/reg-exp-router/node.js +13 -11
- package/node_modules/hono/dist/router/reg-exp-router/prepared-router.js +5 -5
- package/node_modules/hono/dist/router/reg-exp-router/router.js +40 -52
- package/node_modules/hono/dist/router/reg-exp-router/trie.js +15 -5
- package/node_modules/hono/dist/router/trie-router/node.js +6 -4
- package/node_modules/hono/dist/types/adapter/aws-lambda/conninfo.d.ts +1 -1
- package/node_modules/hono/dist/types/adapter/bun/conninfo.d.ts +1 -1
- package/node_modules/hono/dist/types/adapter/bun/ssg.d.ts +1 -1
- package/node_modules/hono/dist/types/adapter/cloudflare-pages/conninfo.d.ts +1 -1
- package/node_modules/hono/dist/types/adapter/cloudflare-workers/conninfo.d.ts +1 -1
- package/node_modules/hono/dist/types/adapter/deno/conninfo.d.ts +1 -1
- package/node_modules/hono/dist/types/adapter/deno/ssg.d.ts +1 -1
- package/node_modules/hono/dist/types/adapter/lambda-edge/conninfo.d.ts +1 -1
- package/node_modules/hono/dist/types/adapter/netlify/conninfo.d.ts +1 -1
- package/node_modules/hono/dist/types/adapter/vercel/conninfo.d.ts +1 -1
- package/node_modules/hono/dist/types/helper/accepts/accepts.d.ts +5 -0
- package/node_modules/hono/dist/types/helper/factory/index.d.ts +1 -1
- package/node_modules/hono/dist/types/helper/ssg/ssg.d.ts +6 -1
- package/node_modules/hono/dist/types/helper/streaming/sse.d.ts +1 -1
- package/node_modules/hono/dist/types/helper/streaming/stream.d.ts +1 -1
- package/node_modules/hono/dist/types/helper/streaming/text.d.ts +1 -1
- package/node_modules/hono/dist/types/helper/testing/index.d.ts +2 -1
- package/node_modules/hono/dist/types/helper/websocket/index.d.ts +13 -3
- package/node_modules/hono/dist/types/hono-base.d.ts +23 -9
- package/node_modules/hono/dist/types/index.d.ts +1 -1
- package/node_modules/hono/dist/types/jsx/base.d.ts +6 -3
- package/node_modules/hono/dist/types/jsx/components.d.ts +2 -2
- package/node_modules/hono/dist/types/jsx/constants.d.ts +1 -0
- package/node_modules/hono/dist/types/jsx/context.d.ts +2 -2
- package/node_modules/hono/dist/types/jsx/dom/components.d.ts +2 -2
- package/node_modules/hono/dist/types/jsx/dom/css.d.ts +2 -2
- package/node_modules/hono/dist/types/jsx/dom/hooks/index.d.ts +5 -3
- package/node_modules/hono/dist/types/jsx/dom/index.d.ts +1 -1
- package/node_modules/hono/dist/types/jsx/dom/server.d.ts +1 -1
- package/node_modules/hono/dist/types/jsx/index.d.ts +1 -1
- package/node_modules/hono/dist/types/jsx/jsx-runtime.d.ts +2 -1
- package/node_modules/hono/dist/types/jsx/streaming.d.ts +4 -3
- package/node_modules/hono/dist/types/middleware/basic-auth/index.d.ts +1 -0
- package/node_modules/hono/dist/types/middleware/bearer-auth/index.d.ts +2 -1
- package/node_modules/hono/dist/types/middleware/ip-restriction/index.d.ts +3 -3
- package/node_modules/hono/dist/types/middleware/jsx-renderer/index.d.ts +3 -3
- package/node_modules/hono/dist/types/middleware/mount/index.d.ts +2 -0
- package/node_modules/hono/dist/types/middleware/request-id/request-id.d.ts +3 -3
- package/node_modules/hono/dist/types/middleware/secure-headers/secure-headers.d.ts +2 -0
- package/node_modules/hono/dist/types/router/reg-exp-router/node.d.ts +3 -3
- package/node_modules/hono/dist/types/router/reg-exp-router/trie.d.ts +1 -1
- package/node_modules/hono/dist/types/utils/cookie.d.ts +1 -1
- package/node_modules/hono/dist/types/utils/ipaddr.d.ts +1 -1
- package/node_modules/hono/dist/types/utils/jwt/jwt.d.ts +4 -2
- package/node_modules/hono/dist/types/utils/mount.d.ts +4 -0
- package/node_modules/hono/dist/types/utils/types.d.ts +12 -2
- package/node_modules/hono/dist/utils/body.js +2 -1
- package/node_modules/hono/dist/utils/cookie.js +3 -3
- package/node_modules/hono/dist/utils/html.js +5 -0
- package/node_modules/hono/dist/utils/jwt/jwt.js +8 -5
- package/node_modules/hono/dist/utils/mime.js +3 -2
- package/node_modules/hono/dist/utils/mount.js +58 -0
- package/node_modules/hono/dist/utils/url.js +23 -11
- package/node_modules/hono/dist/validator/validator.js +5 -5
- package/node_modules/hono/package.json +1 -1
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DOM_ERROR_HANDLER } from "../constants.js";
|
|
2
|
-
import { Fragment } from "./jsx-dev-runtime.js";
|
|
2
|
+
import { Fragment, jsxDEV } from "./jsx-dev-runtime.js";
|
|
3
3
|
import "./jsx-runtime.js";
|
|
4
4
|
//#region src/jsx/dom/components.ts
|
|
5
5
|
const ErrorBoundary = (({ children, fallback, fallbackRender, onError }) => {
|
|
@@ -16,7 +16,7 @@ const Suspense = (({ children, fallback }) => {
|
|
|
16
16
|
res[DOM_ERROR_HANDLER] = (err, retry) => {
|
|
17
17
|
if (!(err instanceof Promise)) throw err;
|
|
18
18
|
err.finally(retry);
|
|
19
|
-
return fallback;
|
|
19
|
+
return fallback || jsxDEV(Fragment, { children: fallback });
|
|
20
20
|
};
|
|
21
21
|
return res;
|
|
22
22
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PERMALINK } from "../../constants.js";
|
|
2
2
|
import { createContext } from "../context.js";
|
|
3
3
|
import { useContext } from "../../context.js";
|
|
4
|
-
import { useCallback, useState } from "../../hooks/index.js";
|
|
4
|
+
import { useCallback, useRef, useState } from "../../hooks/index.js";
|
|
5
5
|
//#region src/jsx/dom/hooks/index.ts
|
|
6
6
|
/**
|
|
7
7
|
* Provide hooks used only in jsx/dom
|
|
@@ -15,7 +15,10 @@ const FormContext = createContext({
|
|
|
15
15
|
const actions = /* @__PURE__ */ new Set();
|
|
16
16
|
const registerAction = (action) => {
|
|
17
17
|
actions.add(action);
|
|
18
|
-
|
|
18
|
+
const remove = () => {
|
|
19
|
+
actions.delete(action);
|
|
20
|
+
};
|
|
21
|
+
action.then(remove, remove);
|
|
19
22
|
};
|
|
20
23
|
/**
|
|
21
24
|
* This hook returns the current form status
|
|
@@ -33,7 +36,7 @@ const useFormStatus = () => {
|
|
|
33
36
|
*/
|
|
34
37
|
const useOptimistic = (state, updateState) => {
|
|
35
38
|
const [optimisticState, setOptimisticState] = useState(state);
|
|
36
|
-
if (actions.size > 0) Promise.
|
|
39
|
+
if (actions.size > 0) Promise.allSettled(actions).then(() => {
|
|
37
40
|
setOptimisticState(state);
|
|
38
41
|
});
|
|
39
42
|
else setOptimisticState(state);
|
|
@@ -42,19 +45,46 @@ const useOptimistic = (state, updateState) => {
|
|
|
42
45
|
}, [])];
|
|
43
46
|
};
|
|
44
47
|
/**
|
|
45
|
-
* This hook returns the current state
|
|
48
|
+
* This hook returns the current state, a function to update the state by form action,
|
|
49
|
+
* and whether an action is pending
|
|
50
|
+
* Actions run one at a time, each receiving the state returned by the previous one
|
|
46
51
|
* @param fn
|
|
47
52
|
* @param initialState
|
|
48
53
|
* @param permalink
|
|
49
|
-
* @returns [T, (data: FormData) => void]
|
|
54
|
+
* @returns [T, (data: FormData) => Promise<void>, boolean]
|
|
50
55
|
*/
|
|
51
56
|
const useActionState = (fn, initialState, permalink) => {
|
|
52
57
|
const [state, setState] = useState(initialState);
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
58
|
+
const [pendingCount, setPendingCount] = useState(0);
|
|
59
|
+
const ref = useRef({
|
|
60
|
+
fn,
|
|
61
|
+
state: initialState,
|
|
62
|
+
pending: 0,
|
|
63
|
+
queue: Promise.resolve()
|
|
64
|
+
});
|
|
65
|
+
ref.current.fn = fn;
|
|
66
|
+
const actionState = useCallback((data) => {
|
|
67
|
+
const current = ref.current;
|
|
68
|
+
const run = async () => {
|
|
69
|
+
try {
|
|
70
|
+
current.state = await current.fn(current.state, data);
|
|
71
|
+
setState(current.state);
|
|
72
|
+
} finally {
|
|
73
|
+
current.pending--;
|
|
74
|
+
setPendingCount((count) => count - 1);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
const result = current.pending++ ? current.queue.then(run) : run();
|
|
78
|
+
current.queue = result.catch(() => {});
|
|
79
|
+
setPendingCount((count) => count + 1);
|
|
80
|
+
return result;
|
|
81
|
+
}, []);
|
|
56
82
|
actionState[PERMALINK] = permalink;
|
|
57
|
-
return [
|
|
83
|
+
return [
|
|
84
|
+
state,
|
|
85
|
+
actionState,
|
|
86
|
+
pendingCount > 0
|
|
87
|
+
];
|
|
58
88
|
};
|
|
59
89
|
//#endregion
|
|
60
90
|
export { FormContext, registerAction, useActionState, useFormStatus, useOptimistic };
|
|
@@ -217,12 +217,15 @@ const form = (props) => {
|
|
|
217
217
|
ev.preventDefault();
|
|
218
218
|
const formData = new FormData(ev.target);
|
|
219
219
|
setState([formData, true]);
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
220
|
+
try {
|
|
221
|
+
const actionRes = currentAction(formData);
|
|
222
|
+
if (actionRes instanceof Promise) {
|
|
223
|
+
registerAction(actionRes);
|
|
224
|
+
await actionRes;
|
|
225
|
+
}
|
|
226
|
+
} finally {
|
|
227
|
+
setState([null, true]);
|
|
224
228
|
}
|
|
225
|
-
setState([null, true]);
|
|
226
229
|
}, []);
|
|
227
230
|
const ref = composeRef(props.ref, (el) => {
|
|
228
231
|
el.addEventListener("submit", onSubmit);
|
|
@@ -155,7 +155,11 @@ const findInsertBefore = (node) => {
|
|
|
155
155
|
};
|
|
156
156
|
const removeNode = (node) => {
|
|
157
157
|
if (!isNodeString(node)) {
|
|
158
|
-
node[DOM_STASH]
|
|
158
|
+
const stash = node[DOM_STASH];
|
|
159
|
+
if (stash?.[1][1]) {
|
|
160
|
+
stash[1][1].forEach((data) => data[2]?.());
|
|
161
|
+
delete stash[1][1];
|
|
162
|
+
}
|
|
159
163
|
refCleanupMap.get(node.e)?.();
|
|
160
164
|
if (node.p === 2) node.vC?.forEach((n) => n.p = 2);
|
|
161
165
|
node.vC?.forEach(removeNode);
|
|
@@ -212,8 +216,9 @@ const applyNodeObject = (node, container, isNew) => {
|
|
|
212
216
|
child.d = false;
|
|
213
217
|
el = child.e ||= document.createTextNode(child.t);
|
|
214
218
|
} else {
|
|
219
|
+
const isCreated = !child.e;
|
|
215
220
|
el = child.e ||= child.n ? document.createElementNS(child.n, child.tag) : document.createElement(child.tag);
|
|
216
|
-
applyProps(el, child.props, child.pP);
|
|
221
|
+
applyProps(el, child.props, isCreated ? void 0 : child.pP);
|
|
217
222
|
applyNodeObject(child, el, isNewLocal);
|
|
218
223
|
if (child.tag === "select") applySelectValue(el, child.props);
|
|
219
224
|
}
|
|
@@ -343,6 +348,7 @@ const build = (context, node, children) => {
|
|
|
343
348
|
prevNode = child;
|
|
344
349
|
}
|
|
345
350
|
}
|
|
351
|
+
if (prevNode && !prevNode.s) for (let p = prevNode; p && !isNodeString(p); p = p.vC?.at(-1)) p.nN = node.nN;
|
|
346
352
|
oldVChildren = oldChildrenByKey ? [...oldChildrenByKey.values()] : oldVChildren;
|
|
347
353
|
node.vR = buildWithPreviousChildren ? [...node.vC, ...oldVChildren || []] : oldVChildren || [];
|
|
348
354
|
node.vC = vChildren;
|
|
@@ -377,7 +383,7 @@ const build = (context, node, children) => {
|
|
|
377
383
|
if (context[0] === 1) context[1] = true;
|
|
378
384
|
else {
|
|
379
385
|
build(context, errorHandlerNode, [fallback]);
|
|
380
|
-
if ((errorHandler.length === 1 || context !== errorHandlerContext) && errorHandlerNode.c) {
|
|
386
|
+
if ((errorHandler.length === 1 || context !== errorHandlerContext) && errorHandlerNode.c && !context[5].some(([, , n]) => n === errorHandlerNode)) {
|
|
381
387
|
apply(errorHandlerNode, errorHandlerNode.c, false);
|
|
382
388
|
return;
|
|
383
389
|
}
|
|
@@ -1,31 +1,27 @@
|
|
|
1
1
|
import { escapeToBuffer, raw, stringBufferToString } from "../utils/html.js";
|
|
2
2
|
import { html } from "../helper/html/index.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { PERMALINK } from "./constants.js";
|
|
4
|
+
import { isValidAttributeName } from "./utils.js";
|
|
5
|
+
import { Fragment, attributeToBuffer, markRenderedJSX } from "./base.js";
|
|
5
6
|
import { jsxDEV } from "./jsx-dev-runtime.js";
|
|
6
7
|
//#region src/jsx/jsx-runtime.ts
|
|
8
|
+
const jsxTemplate = (strings, ...values) => {
|
|
9
|
+
const result = html(strings, ...values);
|
|
10
|
+
return result instanceof Promise ? result.then(markRenderedJSX) : markRenderedJSX(result);
|
|
11
|
+
};
|
|
7
12
|
const jsxAttr = (key, v) => {
|
|
8
13
|
if (!isValidAttributeName(key)) return raw("");
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
let styleStr = "";
|
|
12
|
-
styleObjectForEach(v, (property, value) => {
|
|
13
|
-
if (value != null) styleStr += `${styleStr ? ";" : ""}${property}:${value}`;
|
|
14
|
-
});
|
|
15
|
-
escapeToBuffer(styleStr, buffer);
|
|
16
|
-
buffer[0] += "\"";
|
|
17
|
-
} else if (typeof v === "string") {
|
|
14
|
+
if (typeof v === "string") {
|
|
15
|
+
const buffer = [`${key}="`];
|
|
18
16
|
escapeToBuffer(v, buffer);
|
|
19
|
-
buffer[0]
|
|
20
|
-
} else if (v === null || v === void 0) return raw("");
|
|
21
|
-
else if (typeof v === "number" || v.isEscaped) buffer[0] += `${v}"`;
|
|
22
|
-
else if (v instanceof Promise) buffer.unshift("\"", v);
|
|
23
|
-
else {
|
|
24
|
-
escapeToBuffer(v.toString(), buffer);
|
|
25
|
-
buffer[0] += "\"";
|
|
17
|
+
return raw(buffer[0] + "\"");
|
|
26
18
|
}
|
|
19
|
+
let value = v;
|
|
20
|
+
if (typeof value === "function" && (key === "action" || key === "formaction")) value = PERMALINK in value ? value[PERMALINK] : void 0;
|
|
21
|
+
const buffer = [""];
|
|
22
|
+
attributeToBuffer(buffer, "", key, value);
|
|
27
23
|
return buffer.length === 1 ? raw(buffer[0]) : stringBufferToString(buffer, void 0);
|
|
28
24
|
};
|
|
29
25
|
const jsxEscape = (value) => value;
|
|
30
26
|
//#endregion
|
|
31
|
-
export { Fragment, jsxDEV as jsx, jsxAttr, jsxEscape,
|
|
27
|
+
export { Fragment, jsxDEV as jsx, jsxAttr, jsxEscape, jsxTemplate, jsxDEV as jsxs };
|
|
@@ -15,6 +15,7 @@ import { auth } from "../../utils/basic-auth.js";
|
|
|
15
15
|
* @param {Function} [options.verifyUser] - The function to verify user credentials.
|
|
16
16
|
* @param {string | object | MessageFunction} [options.invalidUserMessage="Unauthorized"] - The invalid user message.
|
|
17
17
|
* @param {Function} [options.onAuthSuccess] - Callback function called on successful authentication.
|
|
18
|
+
* @param {...{ username: string; password: string }} [users] - Additional user credentials.
|
|
18
19
|
* @returns {MiddlewareHandler} The middleware handler function.
|
|
19
20
|
* @throws {HTTPException} If neither "username and password" nor "verifyUser" options are provided.
|
|
20
21
|
*
|
|
@@ -61,6 +62,7 @@ const basicAuth = (options, ...users) => {
|
|
|
61
62
|
username: options.username,
|
|
62
63
|
password: options.password
|
|
63
64
|
});
|
|
65
|
+
for (const user of users) if (typeof user.username !== "string" || typeof user.password !== "string") throw new Error("basic auth middleware requires \"username\" and \"password\" to be strings");
|
|
64
66
|
return async function basicAuth(ctx, next) {
|
|
65
67
|
const requestUser = auth(ctx.req.raw);
|
|
66
68
|
if (requestUser) {
|
|
@@ -80,7 +82,7 @@ const basicAuth = (options, ...users) => {
|
|
|
80
82
|
}
|
|
81
83
|
}
|
|
82
84
|
const status = 401;
|
|
83
|
-
const headers = { "WWW-Authenticate": "Basic realm=\"" + options.realm?.replace(/"/g, "
|
|
85
|
+
const headers = { "WWW-Authenticate": "Basic realm=\"" + options.realm?.replace(/[\\"]/g, "\\$&") + "\"" };
|
|
84
86
|
const responseMessage = typeof options.invalidUserMessage === "function" ? await options.invalidUserMessage(ctx) : options.invalidUserMessage;
|
|
85
87
|
const res = typeof responseMessage === "string" ? new Response(responseMessage, {
|
|
86
88
|
status,
|
|
@@ -44,7 +44,7 @@ const bearerAuth = (options) => {
|
|
|
44
44
|
if (!("token" in options || "verifyToken" in options)) throw new Error("bearer auth middleware requires options for \"token\" or \"verifyToken\"");
|
|
45
45
|
if (!options.realm) options.realm = "";
|
|
46
46
|
if (options.prefix === void 0) options.prefix = PREFIX;
|
|
47
|
-
const realm = options.realm?.replace(/"/g, "
|
|
47
|
+
const realm = options.realm?.replace(/[\\"]/g, "\\$&");
|
|
48
48
|
const prefix = options.prefix;
|
|
49
49
|
const tokenRegexp = new RegExp(`^${TOKEN_STRINGS}$`);
|
|
50
50
|
const wwwAuthenticatePrefix = prefix === "" ? "" : `${prefix} `;
|
|
@@ -52,6 +52,14 @@ const bearerAuth = (options) => {
|
|
|
52
52
|
const wwwAuthenticateHeaderValue = typeof wwwAuthenticateHeader === "function" ? await wwwAuthenticateHeader(c) : wwwAuthenticateHeader;
|
|
53
53
|
const headers = { "WWW-Authenticate": typeof wwwAuthenticateHeaderValue === "string" ? wwwAuthenticateHeaderValue : `${wwwAuthenticatePrefix}${Object.entries(wwwAuthenticateHeaderValue).map(([key, value]) => `${key}="${value}"`).join(",")}` };
|
|
54
54
|
const responseMessage = typeof messageOption === "function" ? await messageOption(c) : messageOption;
|
|
55
|
+
if (responseMessage instanceof Response) {
|
|
56
|
+
const resHeaders = new Headers(responseMessage.headers);
|
|
57
|
+
if (!resHeaders.has("WWW-Authenticate")) resHeaders.set("WWW-Authenticate", headers["WWW-Authenticate"]);
|
|
58
|
+
throw new HTTPException(responseMessage.status, { res: new Response(responseMessage.body, {
|
|
59
|
+
status: responseMessage.status,
|
|
60
|
+
headers: resHeaders
|
|
61
|
+
}) });
|
|
62
|
+
}
|
|
55
63
|
const res = typeof responseMessage === "string" ? new Response(responseMessage, {
|
|
56
64
|
status,
|
|
57
65
|
headers
|
|
@@ -44,23 +44,22 @@ const bodyLimit = (options) => {
|
|
|
44
44
|
const hasTransferEncoding = c.req.raw.headers.has("transfer-encoding");
|
|
45
45
|
if (c.req.raw.headers.has("content-length") && !hasTransferEncoding) return parseInt(c.req.raw.headers.get("content-length") || "0", 10) > maxSize ? onError(c) : next();
|
|
46
46
|
let size = 0;
|
|
47
|
-
|
|
47
|
+
let buffer = /* @__PURE__ */ new Uint8Array(0);
|
|
48
48
|
const rawReader = c.req.raw.body.getReader();
|
|
49
49
|
for (;;) {
|
|
50
50
|
const { done, value } = await rawReader.read();
|
|
51
51
|
if (done) break;
|
|
52
|
+
const offset = size;
|
|
52
53
|
size += value.length;
|
|
53
54
|
if (size > maxSize) return onError(c);
|
|
54
|
-
|
|
55
|
+
if (size > buffer.length) {
|
|
56
|
+
const grown = new Uint8Array(Math.min(maxSize, Math.max(size, buffer.length * 2)));
|
|
57
|
+
grown.set(buffer.subarray(0, offset));
|
|
58
|
+
buffer = grown;
|
|
59
|
+
}
|
|
60
|
+
buffer.set(value, offset);
|
|
55
61
|
}
|
|
56
|
-
|
|
57
|
-
body: new ReadableStream({ start(controller) {
|
|
58
|
-
for (const chunk of chunks) controller.enqueue(chunk);
|
|
59
|
-
controller.close();
|
|
60
|
-
} }),
|
|
61
|
-
duplex: "half"
|
|
62
|
-
};
|
|
63
|
-
c.req.raw = new Request(c.req.raw, requestInit);
|
|
62
|
+
c.req.raw = new Request(c.req.raw, { body: buffer.subarray(0, size) });
|
|
64
63
|
return next();
|
|
65
64
|
};
|
|
66
65
|
};
|
|
@@ -92,6 +92,10 @@ const every = (...middleware) => {
|
|
|
92
92
|
c.req.routeIndex = currentRouteIndex;
|
|
93
93
|
const res = await m(c, next);
|
|
94
94
|
if (res === false) throw new Error("Unmet condition");
|
|
95
|
+
if (res === true) {
|
|
96
|
+
if (!c.finalized) await next();
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
95
99
|
return res;
|
|
96
100
|
}]]))(c, next);
|
|
97
101
|
};
|
|
@@ -58,14 +58,13 @@ const compress = (options) => {
|
|
|
58
58
|
return async function compress(ctx, next) {
|
|
59
59
|
await next();
|
|
60
60
|
const contentLength = ctx.res.headers.get("Content-Length");
|
|
61
|
-
if (ctx.res.status === 206 || ctx.res.headers.has("Content-Encoding") || ctx.res.headers.has("Transfer-Encoding") ||
|
|
61
|
+
if (ctx.res.status === 206 || ctx.res.headers.has("Content-Encoding") || ctx.res.headers.has("Transfer-Encoding") || contentLength && Number(contentLength) < threshold || !shouldCompress(ctx.res) || !shouldTransform(ctx.res)) return;
|
|
62
62
|
const current = ctx.res.headers.get("Vary");
|
|
63
63
|
if (current !== "*" && !(current && varyAcceptEncodingRegExp.test(current))) ctx.header("Vary", current ? `${current}, Accept-Encoding` : "Accept-Encoding");
|
|
64
64
|
const accepted = ctx.req.header("Accept-Encoding");
|
|
65
65
|
const encoding = selectEncoding(accepted, candidates);
|
|
66
66
|
if (!encoding || !ctx.res.body) return;
|
|
67
|
-
|
|
68
|
-
ctx.res = new Response(ctx.res.body.pipeThrough(stream), ctx.res);
|
|
67
|
+
ctx.res = ctx.req.method === "HEAD" ? new Response(null, ctx.res) : new Response(ctx.res.body.pipeThrough(new CompressionStream(encoding)), ctx.res);
|
|
69
68
|
ctx.res.headers.delete("Content-Length");
|
|
70
69
|
ctx.res.headers.set("Content-Encoding", encoding);
|
|
71
70
|
const etag = ctx.res.headers.get("ETag");
|
|
@@ -8,7 +8,7 @@ const secFetchSiteValues = [
|
|
|
8
8
|
];
|
|
9
9
|
const isSecFetchSite = (value) => secFetchSiteValues.includes(value);
|
|
10
10
|
const isSafeMethodRe = /^(GET|HEAD|OPTIONS)$/;
|
|
11
|
-
const
|
|
11
|
+
const isCsrfContentTypeRe = /^\b(application\/x-www-form-urlencoded|multipart\/form-data|text\/(?:plain|ping))\b/i;
|
|
12
12
|
/**
|
|
13
13
|
* CSRF Protection Middleware for Hono.
|
|
14
14
|
*
|
|
@@ -94,7 +94,7 @@ const csrf = (options) => {
|
|
|
94
94
|
return await secFetchSiteHandler(secFetchSite, c);
|
|
95
95
|
};
|
|
96
96
|
return async function csrf(c, next) {
|
|
97
|
-
if (!isSafeMethodRe.test(c.req.method) &&
|
|
97
|
+
if (!isSafeMethodRe.test(c.req.method) && isCsrfContentTypeRe.test(c.req.header("content-type") || "text/plain") && !await isAllowedSecFetchSite(c.req.header("sec-fetch-site"), c) && !await isAllowedOrigin(c.req.header("origin"), c)) {
|
|
98
98
|
const res = new Response("Forbidden", { status: 403 });
|
|
99
99
|
throw new HTTPException(403, { res });
|
|
100
100
|
}
|
|
@@ -16,7 +16,8 @@ const RETAINED_304_HEADERS = [
|
|
|
16
16
|
];
|
|
17
17
|
const stripWeak = (tag) => tag.replace(/^W\//, "");
|
|
18
18
|
function etagMatches(etag, ifNoneMatch) {
|
|
19
|
-
|
|
19
|
+
const expected = stripWeak(etag);
|
|
20
|
+
return ifNoneMatch?.match(/"[^"]*"/g)?.some((tag) => tag === expected) ?? false;
|
|
20
21
|
}
|
|
21
22
|
function initializeGenerator(generator) {
|
|
22
23
|
if (!generator) {
|
|
@@ -64,6 +65,7 @@ const etag = (options) => {
|
|
|
64
65
|
etag = weak ? `W/"${hash}"` : `"${hash}"`;
|
|
65
66
|
}
|
|
66
67
|
if (ifNoneMatch === "*" || etagMatches(etag, ifNoneMatch)) {
|
|
68
|
+
await res.body?.cancel();
|
|
67
69
|
c.res = new Response(null, {
|
|
68
70
|
status: 304,
|
|
69
71
|
statusText: "Not Modified",
|
|
@@ -109,8 +109,8 @@ const jwk = (options, init) => {
|
|
|
109
109
|
};
|
|
110
110
|
};
|
|
111
111
|
function unauthorizedResponse(opts) {
|
|
112
|
-
const realm = (opts.realm ?? opts.ctx.req.url).replace(/"/g, "
|
|
113
|
-
const errDescription = opts.errDescription.replace(/"/g, "
|
|
112
|
+
const realm = (opts.realm ?? opts.ctx.req.url).replace(/[\\"]/g, "\\$&");
|
|
113
|
+
const errDescription = opts.errDescription.replace(/[\\"]/g, "\\$&");
|
|
114
114
|
return new Response("Unauthorized", {
|
|
115
115
|
status: 401,
|
|
116
116
|
statusText: opts.statusText,
|
|
@@ -103,8 +103,8 @@ const jwt = (options) => {
|
|
|
103
103
|
};
|
|
104
104
|
};
|
|
105
105
|
function unauthorizedResponse(opts) {
|
|
106
|
-
const realm = (opts.realm ?? opts.ctx.req.url).replace(/"/g, "
|
|
107
|
-
const errDescription = opts.errDescription.replace(/"/g, "
|
|
106
|
+
const realm = (opts.realm ?? opts.ctx.req.url).replace(/[\\"]/g, "\\$&");
|
|
107
|
+
const errDescription = opts.errDescription.replace(/[\\"]/g, "\\$&");
|
|
108
108
|
return new Response("Unauthorized", {
|
|
109
109
|
status: 401,
|
|
110
110
|
statusText: opts.statusText,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { basePath, matchedRoutes } from "../../helper/route/index.js";
|
|
1
2
|
import "../../router.js";
|
|
2
3
|
import { TrieRouter } from "../../router/trie-router/router.js";
|
|
3
4
|
import "../../router/trie-router/index.js";
|
|
4
|
-
import { basePath, matchedRoutes } from "../../helper/route/index.js";
|
|
5
5
|
//#region src/middleware/method-not-allowed/index.ts
|
|
6
6
|
/**
|
|
7
7
|
* Method Not Allowed Middleware for Hono.
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { parseBody } from "../../utils/body.js";
|
|
2
2
|
//#region src/middleware/method-override/index.ts
|
|
3
3
|
const DEFAULT_METHOD_FORM_NAME = "_method";
|
|
4
|
+
const isBodylessMethod = (method) => /^(?:GET|HEAD)$/i.test(method);
|
|
5
|
+
const withoutBodyHeaders = (headers) => {
|
|
6
|
+
const newHeaders = new Headers(headers);
|
|
7
|
+
newHeaders.delete("content-type");
|
|
8
|
+
newHeaders.delete("content-length");
|
|
9
|
+
return newHeaders;
|
|
10
|
+
};
|
|
4
11
|
/**
|
|
5
12
|
* Method Override Middleware for Hono.
|
|
6
13
|
*
|
|
@@ -37,16 +44,21 @@ const methodOverride = (options) => async function methodOverride(c, next) {
|
|
|
37
44
|
if (contentType?.startsWith("multipart/form-data")) {
|
|
38
45
|
const method = (await clonedRequest.formData()).get(methodFormName);
|
|
39
46
|
if (method) {
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
newHeaders.delete("content-type");
|
|
44
|
-
newHeaders.delete("content-length");
|
|
45
|
-
const request = new Request(c.req.url, {
|
|
46
|
-
body: newForm,
|
|
47
|
+
const newHeaders = withoutBodyHeaders(clonedRequest.headers);
|
|
48
|
+
let request;
|
|
49
|
+
if (isBodylessMethod(method)) request = new Request(c.req.url, {
|
|
47
50
|
headers: newHeaders,
|
|
48
51
|
method
|
|
49
52
|
});
|
|
53
|
+
else {
|
|
54
|
+
const newForm = await newRequest.formData();
|
|
55
|
+
newForm.delete(methodFormName);
|
|
56
|
+
request = new Request(c.req.url, {
|
|
57
|
+
body: newForm,
|
|
58
|
+
headers: newHeaders,
|
|
59
|
+
method
|
|
60
|
+
});
|
|
61
|
+
}
|
|
50
62
|
return app.fetch(request, c.env, getExecutionCtx(c));
|
|
51
63
|
}
|
|
52
64
|
}
|
|
@@ -55,9 +67,14 @@ const methodOverride = (options) => async function methodOverride(c, next) {
|
|
|
55
67
|
const method = params[methodFormName];
|
|
56
68
|
if (method) {
|
|
57
69
|
delete params[methodFormName];
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
70
|
+
const newHeaders = new Headers(newRequest.headers);
|
|
71
|
+
newHeaders.delete("content-length");
|
|
72
|
+
const request = isBodylessMethod(method) ? new Request(c.req.url, {
|
|
73
|
+
headers: withoutBodyHeaders(newHeaders),
|
|
74
|
+
method
|
|
75
|
+
}) : new Request(newRequest, {
|
|
76
|
+
body: new URLSearchParams(params),
|
|
77
|
+
headers: newHeaders,
|
|
61
78
|
method
|
|
62
79
|
});
|
|
63
80
|
return app.fetch(request, c.env, getExecutionCtx(c));
|
|
@@ -69,7 +86,10 @@ const methodOverride = (options) => async function methodOverride(c, next) {
|
|
|
69
86
|
if (method) {
|
|
70
87
|
const newHeaders = new Headers(c.req.raw.headers);
|
|
71
88
|
newHeaders.delete(headerName);
|
|
72
|
-
const request = new Request(c.req.
|
|
89
|
+
const request = isBodylessMethod(method) ? new Request(c.req.url, {
|
|
90
|
+
headers: withoutBodyHeaders(newHeaders),
|
|
91
|
+
method
|
|
92
|
+
}) : new Request(c.req.raw, {
|
|
73
93
|
headers: newHeaders,
|
|
74
94
|
method
|
|
75
95
|
});
|
|
@@ -81,7 +101,10 @@ const methodOverride = (options) => async function methodOverride(c, next) {
|
|
|
81
101
|
if (method) {
|
|
82
102
|
const url = new URL(c.req.url);
|
|
83
103
|
url.searchParams.delete(queryName);
|
|
84
|
-
const requestInit = {
|
|
104
|
+
const requestInit = isBodylessMethod(method) ? {
|
|
105
|
+
headers: withoutBodyHeaders(c.req.raw.headers),
|
|
106
|
+
method
|
|
107
|
+
} : {
|
|
85
108
|
body: c.req.raw.body,
|
|
86
109
|
headers: c.req.raw.headers,
|
|
87
110
|
method,
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { routePath } from "../../helper/route/index.js";
|
|
2
|
+
import { createMountedRequest } from "../../utils/mount.js";
|
|
2
3
|
//#region src/middleware/mount/index.ts
|
|
3
4
|
const defaultReplaceRequest = (c) => {
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
url.pathname = c.req.path.slice(pathPrefix.length) || "/";
|
|
7
|
-
return new Request(url, c.req.raw);
|
|
5
|
+
const path = routePath(c);
|
|
6
|
+
return createMountedRequest(c, path.replace(/\/?\*$/, ""), path);
|
|
8
7
|
};
|
|
9
8
|
const defaultGetOptions = (c) => {
|
|
10
9
|
let executionContext = void 0;
|
|
@@ -21,6 +20,8 @@ const defaultGetOptions = (c) => {
|
|
|
21
20
|
* @param {Function} applicationHandler - other Request Handler
|
|
22
21
|
* @param {MountOptions} [options] - options of `mount()`
|
|
23
22
|
* @returns {MiddlewareHandler} handler to register with `app.all()`
|
|
23
|
+
* @throws {Error} If the route ends with a wildcard inside a segment (e.g. `/assets*`), or automatic request rewriting encounters duplicate path parameter names or an optional regular expression parameter.
|
|
24
|
+
* @throws {HTTPException} With status 400 if automatic request rewriting cannot safely preserve the routed path.
|
|
24
25
|
*
|
|
25
26
|
* @example
|
|
26
27
|
* ```ts
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* Request ID Middleware for Hono.
|
|
4
4
|
*
|
|
5
|
-
* @param {
|
|
5
|
+
* @param {RequestIdOptions} [options] - Options for Request ID middleware.
|
|
6
6
|
* @param {number} [options.limitLength=255] - The maximum length of request id.
|
|
7
|
-
* @param {string} [options.headerName=X-Request-Id] - The header name used in request id.
|
|
8
|
-
* @param {
|
|
7
|
+
* @param {string} [options.headerName='X-Request-Id'] - The header name used in request id.
|
|
8
|
+
* @param {(c: Context) => string} [options.generator=() => crypto.randomUUID()] - The request id generation function.
|
|
9
9
|
*
|
|
10
10
|
* @returns {MiddlewareHandler} The middleware handler function.
|
|
11
11
|
*
|
|
@@ -28,7 +28,8 @@ const DEFAULT_OPTIONS = {
|
|
|
28
28
|
xPermittedCrossDomainPolicies: true,
|
|
29
29
|
xXssProtection: true,
|
|
30
30
|
removePoweredBy: true,
|
|
31
|
-
permissionsPolicy: {}
|
|
31
|
+
permissionsPolicy: {},
|
|
32
|
+
overwrite: true
|
|
32
33
|
};
|
|
33
34
|
const generateNonce = () => {
|
|
34
35
|
const arrayBuffer = /* @__PURE__ */ new Uint8Array(16);
|
|
@@ -66,6 +67,7 @@ const NONCE = (ctx) => {
|
|
|
66
67
|
* @param {overridableHeader} [customOptions.xXssProtection=true] - Settings for the X-XSS-Protection header.
|
|
67
68
|
* @param {boolean} [customOptions.removePoweredBy=true] - Settings for remove X-Powered-By header.
|
|
68
69
|
* @param {PermissionsPolicyOptions} [customOptions.permissionsPolicy] - Settings for the Permissions-Policy header.
|
|
70
|
+
* @param {boolean} [customOptions.overwrite=true] - Whether to replace a header that the response already has. Set `false` to keep a header that a handler set itself.
|
|
69
71
|
* @returns {MiddlewareHandler} The middleware handler function.
|
|
70
72
|
*
|
|
71
73
|
* @example
|
|
@@ -97,7 +99,7 @@ const secureHeaders = (customOptions) => {
|
|
|
97
99
|
return async function secureHeaders(ctx, next) {
|
|
98
100
|
const headersToSetForReq = callbacks.length === 0 ? headersToSet : callbacks.reduce((acc, cb) => cb(ctx, acc), headersToSet);
|
|
99
101
|
await next();
|
|
100
|
-
setHeaders(ctx, headersToSetForReq);
|
|
102
|
+
setHeaders(ctx, headersToSetForReq, options.overwrite !== false);
|
|
101
103
|
if (options?.removePoweredBy) ctx.res.headers.delete("X-Powered-By");
|
|
102
104
|
};
|
|
103
105
|
};
|
|
@@ -155,8 +157,9 @@ function getReportingEndpoints(reportingEndpoints = []) {
|
|
|
155
157
|
function getReportToOptions(reportTo = []) {
|
|
156
158
|
return reportTo.map((option) => JSON.stringify(option)).join(", ");
|
|
157
159
|
}
|
|
158
|
-
function setHeaders(ctx, headersToSet) {
|
|
160
|
+
function setHeaders(ctx, headersToSet, overwrite) {
|
|
159
161
|
headersToSet.forEach(([header, value]) => {
|
|
162
|
+
if (!overwrite && ctx.res.headers.has(header)) return;
|
|
160
163
|
ctx.res.headers.set(header, value);
|
|
161
164
|
});
|
|
162
165
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { tryDecodeURI } from "../../utils/url.js";
|
|
2
|
+
import { parseAccept } from "../../utils/accept.js";
|
|
2
3
|
import { COMPRESSIBLE_CONTENT_TYPE_REGEX } from "../../utils/compress.js";
|
|
3
4
|
import { getMimeType } from "../../utils/mime.js";
|
|
4
5
|
import { defaultJoin } from "./path.js";
|
|
@@ -19,11 +20,12 @@ const serveStatic = (options) => {
|
|
|
19
20
|
const join = options.join ?? defaultJoin;
|
|
20
21
|
return async (c, next) => {
|
|
21
22
|
if (c.finalized) return next();
|
|
23
|
+
if (c.req.method !== "GET" && c.req.method !== "HEAD") return next();
|
|
22
24
|
let filename;
|
|
23
25
|
if (options.path) filename = options.path;
|
|
24
26
|
else try {
|
|
25
|
-
if (!options.allowPercentInPath && c.req.path.includes("%")) throw new Error();
|
|
26
27
|
filename = tryDecodeURI(c.req.path);
|
|
28
|
+
if (c.req.path.includes("%") && (!options.allowPercentInPath || filename !== c.req.path.replace(/%25/g, "%"))) throw new Error();
|
|
27
29
|
if (/(?:^|[\/\\])\.{1,2}(?:$|[\/\\])|[\/\\]{2,}|\\/.test(filename)) throw new Error();
|
|
28
30
|
} catch {
|
|
29
31
|
await options.onNotFound?.(c.req.path, c);
|
|
@@ -38,7 +40,7 @@ const serveStatic = (options) => {
|
|
|
38
40
|
const mimeType = options.mimes && getMimeType(path, options.mimes) || getMimeType(path);
|
|
39
41
|
c.header("Content-Type", mimeType || "application/octet-stream");
|
|
40
42
|
if (options.precompressed && (!mimeType || COMPRESSIBLE_CONTENT_TYPE_REGEX.test(mimeType))) {
|
|
41
|
-
const acceptEncodingSet = new Set(c.req.header("Accept-Encoding")
|
|
43
|
+
const acceptEncodingSet = new Set(parseAccept(c.req.header("Accept-Encoding") ?? "").filter((encoding) => encoding.q > 0).map((encoding) => encoding.type));
|
|
42
44
|
for (const encoding of ENCODINGS_ORDERED_KEYS) {
|
|
43
45
|
if (!acceptEncodingSet.has(encoding)) continue;
|
|
44
46
|
const compressedContent = await getContent(path + ENCODINGS[encoding], c);
|
|
@@ -74,6 +74,7 @@ const timing = (config) => {
|
|
|
74
74
|
}
|
|
75
75
|
};
|
|
76
76
|
};
|
|
77
|
+
const quote = (s) => `"${s.replace(/[\\"]/g, "\\$&")}"`;
|
|
77
78
|
/**
|
|
78
79
|
* Set a metric for the timing middleware.
|
|
79
80
|
*
|
|
@@ -96,11 +97,11 @@ const setMetric = (c, name, valueDescription, description, precision) => {
|
|
|
96
97
|
return;
|
|
97
98
|
}
|
|
98
99
|
if (typeof valueDescription === "number") {
|
|
99
|
-
const dur = valueDescription.toFixed(precision
|
|
100
|
-
const metric = description ? `${name};dur=${dur};desc
|
|
100
|
+
const dur = valueDescription.toFixed(precision ?? 1);
|
|
101
|
+
const metric = description ? `${name};dur=${dur};desc=${quote(description)}` : `${name};dur=${dur}`;
|
|
101
102
|
metrics.headers.push(metric);
|
|
102
103
|
} else {
|
|
103
|
-
const metric = valueDescription ? `${name};desc
|
|
104
|
+
const metric = valueDescription ? `${name};desc=${quote(valueDescription)}` : `${name}`;
|
|
104
105
|
metrics.headers.push(metric);
|
|
105
106
|
}
|
|
106
107
|
};
|