hono 4.6.20 → 4.7.1

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.
Files changed (101) hide show
  1. package/dist/adapter/aws-lambda/handler.js +0 -2
  2. package/dist/cjs/adapter/aws-lambda/handler.js +0 -8
  3. package/dist/cjs/helper/accepts/accepts.js +4 -26
  4. package/dist/cjs/helper/factory/index.js +6 -2
  5. package/dist/cjs/helper/proxy/index.js +75 -0
  6. package/dist/cjs/middleware/combine/index.js +10 -3
  7. package/dist/cjs/middleware/etag/digest.js +3 -8
  8. package/dist/cjs/middleware/etag/index.js +18 -2
  9. package/dist/cjs/middleware/jwk/index.js +28 -0
  10. package/dist/cjs/middleware/jwk/jwk.js +124 -0
  11. package/dist/cjs/middleware/language/index.js +36 -0
  12. package/dist/cjs/middleware/language/language.js +210 -0
  13. package/dist/cjs/middleware/logger/index.js +2 -3
  14. package/dist/cjs/request.js +1 -1
  15. package/dist/cjs/router/linear-router/router.js +3 -1
  16. package/dist/cjs/router/trie-router/node.js +24 -11
  17. package/dist/cjs/utils/accept.js +86 -0
  18. package/dist/cjs/utils/jwt/index.js +1 -1
  19. package/dist/cjs/utils/jwt/jwt.js +56 -3
  20. package/dist/cjs/utils/jwt/types.js +8 -0
  21. package/dist/cjs/utils/url.js +10 -25
  22. package/dist/helper/accepts/accepts.js +2 -23
  23. package/dist/helper/factory/index.js +6 -2
  24. package/dist/helper/proxy/index.js +52 -0
  25. package/dist/middleware/combine/index.js +10 -3
  26. package/dist/middleware/etag/digest.js +3 -8
  27. package/dist/middleware/etag/index.js +18 -2
  28. package/dist/middleware/jwk/index.js +5 -0
  29. package/dist/middleware/jwk/jwk.js +101 -0
  30. package/dist/middleware/language/index.js +15 -0
  31. package/dist/middleware/language/language.js +178 -0
  32. package/dist/middleware/logger/index.js +2 -3
  33. package/dist/request.js +1 -1
  34. package/dist/router/linear-router/router.js +3 -1
  35. package/dist/router/trie-router/node.js +24 -11
  36. package/dist/types/adapter/cloudflare-pages/handler.d.ts +1 -1
  37. package/dist/types/adapter/cloudflare-workers/websocket.d.ts +1 -1
  38. package/dist/types/adapter/lambda-edge/handler.d.ts +2 -2
  39. package/dist/types/client/types.d.ts +7 -8
  40. package/dist/types/compose.d.ts +11 -1
  41. package/dist/types/context.d.ts +31 -21
  42. package/dist/types/helper/accepts/accepts.d.ts +0 -1
  43. package/dist/types/helper/adapter/index.d.ts +2 -2
  44. package/dist/types/helper/conninfo/types.d.ts +2 -2
  45. package/dist/types/helper/css/common.d.ts +6 -1
  46. package/dist/types/helper/factory/index.d.ts +289 -12
  47. package/dist/types/helper/proxy/index.d.ts +54 -0
  48. package/dist/types/helper/ssg/ssg.d.ts +1 -1
  49. package/dist/types/helper/websocket/index.d.ts +1 -2
  50. package/dist/types/hono-base.d.ts +18 -15
  51. package/dist/types/hono.d.ts +1 -1
  52. package/dist/types/jsx/base.d.ts +4 -1
  53. package/dist/types/jsx/dom/hooks/index.d.ts +9 -3
  54. package/dist/types/jsx/dom/index.d.ts +28 -7
  55. package/dist/types/jsx/dom/intrinsic-element/components.d.ts +6 -6
  56. package/dist/types/jsx/dom/render.d.ts +28 -4
  57. package/dist/types/jsx/dom/server.d.ts +28 -7
  58. package/dist/types/jsx/hooks/index.d.ts +20 -5
  59. package/dist/types/jsx/index.d.ts +28 -7
  60. package/dist/types/jsx/intrinsic-element/components.d.ts +4 -4
  61. package/dist/types/jsx/intrinsic-elements.d.ts +46 -46
  62. package/dist/types/middleware/compress/index.d.ts +4 -1
  63. package/dist/types/middleware/etag/digest.d.ts +1 -1
  64. package/dist/types/middleware/etag/index.d.ts +4 -0
  65. package/dist/types/middleware/jwk/index.d.ts +1 -0
  66. package/dist/types/middleware/jwk/jwk.d.ts +40 -0
  67. package/dist/types/middleware/language/index.d.ts +7 -0
  68. package/dist/types/middleware/language/language.d.ts +102 -0
  69. package/dist/types/middleware/secure-headers/permissions-policy.d.ts +3 -3
  70. package/dist/types/middleware/secure-headers/secure-headers.d.ts +1 -1
  71. package/dist/types/preset/quick.d.ts +1 -1
  72. package/dist/types/preset/tiny.d.ts +1 -1
  73. package/dist/types/request.d.ts +5 -3
  74. package/dist/types/router/linear-router/router.d.ts +0 -1
  75. package/dist/types/router/pattern-router/router.d.ts +0 -1
  76. package/dist/types/router/reg-exp-router/node.d.ts +4 -2
  77. package/dist/types/router/reg-exp-router/router.d.ts +0 -1
  78. package/dist/types/router/reg-exp-router/trie.d.ts +5 -2
  79. package/dist/types/router/smart-router/router.d.ts +0 -1
  80. package/dist/types/router/trie-router/node.d.ts +6 -2
  81. package/dist/types/router/trie-router/router.d.ts +0 -1
  82. package/dist/types/router.d.ts +20 -2
  83. package/dist/types/types.d.ts +2002 -111
  84. package/dist/types/utils/accept.d.ts +11 -0
  85. package/dist/types/utils/cookie.d.ts +4 -4
  86. package/dist/types/utils/headers.d.ts +3 -3
  87. package/dist/types/utils/html.d.ts +6 -2
  88. package/dist/types/utils/jwt/index.d.ts +4 -0
  89. package/dist/types/utils/jwt/jws.d.ts +4 -1
  90. package/dist/types/utils/jwt/jwt.d.ts +8 -2
  91. package/dist/types/utils/jwt/types.d.ts +4 -0
  92. package/dist/types/utils/mime.d.ts +2 -2
  93. package/dist/types/utils/stream.d.ts +0 -4
  94. package/dist/types/utils/url.d.ts +16 -2
  95. package/dist/types/validator/validator.d.ts +18 -6
  96. package/dist/utils/accept.js +63 -0
  97. package/dist/utils/jwt/index.js +2 -2
  98. package/dist/utils/jwt/jwt.js +54 -2
  99. package/dist/utils/jwt/types.js +7 -0
  100. package/dist/utils/url.js +10 -25
  101. package/package.json +24 -3
@@ -22,7 +22,6 @@ __export(logger_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(logger_exports);
24
24
  var import_color = require("../../utils/color");
25
- var import_url = require("../../utils/url");
26
25
  var LogPrefix = /* @__PURE__ */ ((LogPrefix2) => {
27
26
  LogPrefix2["Outgoing"] = "-->";
28
27
  LogPrefix2["Incoming"] = "<--";
@@ -60,8 +59,8 @@ function log(fn, prefix, method, path, status = 0, elapsed) {
60
59
  }
61
60
  const logger = (fn = console.log) => {
62
61
  return async function logger2(c, next) {
63
- const { method } = c.req;
64
- const path = (0, import_url.getPath)(c.req.raw);
62
+ const { method, url } = c.req;
63
+ const path = url.slice(url.indexOf("/", 8));
65
64
  log(fn, "<--" /* Incoming */, method, path);
66
65
  const start = Date.now();
67
66
  await next();
@@ -67,7 +67,7 @@ class HonoRequest {
67
67
  }
68
68
  header(name) {
69
69
  if (name) {
70
- return this.raw.headers.get(name.toLowerCase()) ?? void 0;
70
+ return this.raw.headers.get(name) ?? void 0;
71
71
  }
72
72
  const headerData = {};
73
73
  this.raw.headers.forEach((value, key) => {
@@ -88,7 +88,9 @@ class LinearRouter {
88
88
  let value;
89
89
  if (name.charCodeAt(name.length - 1) === 125) {
90
90
  const openBracePos = name.indexOf("{");
91
- const pattern = name.slice(openBracePos + 1, -1);
91
+ const next = parts[j + 1];
92
+ const lookahead = next && next[1] !== ":" && next[1] !== "*" ? `(?=${next})` : "";
93
+ const pattern = name.slice(openBracePos + 1, -1) + lookahead;
92
94
  const restPath = path.slice(pos + 1);
93
95
  const match = new RegExp(pattern, "d").exec(restPath);
94
96
  if (!match || match.indices[0][0] !== 0 || match.indices[0][1] === 0) {
@@ -47,21 +47,23 @@ class Node {
47
47
  const possibleKeys = [];
48
48
  for (let i = 0, len = parts.length; i < len; i++) {
49
49
  const p = parts[i];
50
- if (Object.keys(curNode.#children).includes(p)) {
51
- curNode = curNode.#children[p];
52
- const pattern2 = (0, import_url.getPattern)(p);
50
+ const nextP = parts[i + 1];
51
+ const pattern = (0, import_url.getPattern)(p, nextP);
52
+ const key = Array.isArray(pattern) ? pattern[0] : p;
53
+ if (Object.keys(curNode.#children).includes(key)) {
54
+ curNode = curNode.#children[key];
55
+ const pattern2 = (0, import_url.getPattern)(p, nextP);
53
56
  if (pattern2) {
54
57
  possibleKeys.push(pattern2[1]);
55
58
  }
56
59
  continue;
57
60
  }
58
- curNode.#children[p] = new Node();
59
- const pattern = (0, import_url.getPattern)(p);
61
+ curNode.#children[key] = new Node();
60
62
  if (pattern) {
61
63
  curNode.#patterns.push(pattern);
62
64
  possibleKeys.push(pattern[1]);
63
65
  }
64
- curNode = curNode.#children[p];
66
+ curNode = curNode.#children[key];
65
67
  }
66
68
  const m = /* @__PURE__ */ Object.create(null);
67
69
  const handlerSet = {
@@ -100,6 +102,7 @@ class Node {
100
102
  const curNode = this;
101
103
  let curNodes = [curNode];
102
104
  const parts = (0, import_url.splitPath)(path);
105
+ const curNodesQueue = [];
103
106
  for (let i = 0, len = parts.length; i < len; i++) {
104
107
  const part = parts[i];
105
108
  const isLast = i === len - 1;
@@ -127,6 +130,7 @@ class Node {
127
130
  const astNode = node.#children["*"];
128
131
  if (astNode) {
129
132
  handlerSets.push(...this.#getHandlerSets(astNode, method, node.#params));
133
+ astNode.#params = params;
130
134
  tempNodes.push(astNode);
131
135
  }
132
136
  continue;
@@ -137,10 +141,19 @@ class Node {
137
141
  const [key, name, matcher] = pattern;
138
142
  const child = node.#children[key];
139
143
  const restPathString = parts.slice(i).join("/");
140
- if (matcher instanceof RegExp && matcher.test(restPathString)) {
141
- params[name] = restPathString;
142
- handlerSets.push(...this.#getHandlerSets(child, method, node.#params, params));
143
- continue;
144
+ if (matcher instanceof RegExp) {
145
+ const m = matcher.exec(restPathString);
146
+ if (m) {
147
+ params[name] = m[0];
148
+ handlerSets.push(...this.#getHandlerSets(child, method, node.#params, params));
149
+ if (Object.keys(child.#children).length) {
150
+ child.#params = params;
151
+ const componentCount = m[0].match(/\//)?.length ?? 0;
152
+ const targetCurNodes = curNodesQueue[componentCount] ||= [];
153
+ targetCurNodes.push(child);
154
+ }
155
+ continue;
156
+ }
144
157
  }
145
158
  if (matcher === true || matcher.test(part)) {
146
159
  params[name] = part;
@@ -158,7 +171,7 @@ class Node {
158
171
  }
159
172
  }
160
173
  }
161
- curNodes = tempNodes;
174
+ curNodes = tempNodes.concat(curNodesQueue.shift() ?? []);
162
175
  }
163
176
  if (handlerSets.length > 1) {
164
177
  handlerSets.sort((a, b) => {
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var accept_exports = {};
20
+ __export(accept_exports, {
21
+ parseAccept: () => parseAccept
22
+ });
23
+ module.exports = __toCommonJS(accept_exports);
24
+ const parseAccept = (acceptHeader) => {
25
+ if (!acceptHeader) {
26
+ return [];
27
+ }
28
+ const acceptValues = acceptHeader.split(",").map((value, index) => ({ value, index }));
29
+ return acceptValues.map(parseAcceptValue).filter((item) => Boolean(item)).sort(sortByQualityAndIndex).map(({ type, params, q }) => ({ type, params, q }));
30
+ };
31
+ const parseAcceptValueRegex = /;(?=(?:(?:[^"]*"){2})*[^"]*$)/;
32
+ const parseAcceptValue = ({ value, index }) => {
33
+ const parts = value.trim().split(parseAcceptValueRegex).map((s) => s.trim());
34
+ const type = parts[0];
35
+ if (!type) {
36
+ return null;
37
+ }
38
+ const params = parseParams(parts.slice(1));
39
+ const q = parseQuality(params.q);
40
+ return { type, params, q, index };
41
+ };
42
+ const parseParams = (paramParts) => {
43
+ return paramParts.reduce((acc, param) => {
44
+ const [key, val] = param.split("=").map((s) => s.trim());
45
+ if (key && val) {
46
+ acc[key] = val;
47
+ }
48
+ return acc;
49
+ }, {});
50
+ };
51
+ const parseQuality = (qVal) => {
52
+ if (qVal === void 0) {
53
+ return 1;
54
+ }
55
+ if (qVal === "") {
56
+ return 1;
57
+ }
58
+ if (qVal === "NaN") {
59
+ return 0;
60
+ }
61
+ const num = Number(qVal);
62
+ if (num === Infinity) {
63
+ return 1;
64
+ }
65
+ if (num === -Infinity) {
66
+ return 0;
67
+ }
68
+ if (Number.isNaN(num)) {
69
+ return 1;
70
+ }
71
+ if (num < 0 || num > 1) {
72
+ return 1;
73
+ }
74
+ return num;
75
+ };
76
+ const sortByQualityAndIndex = (a, b) => {
77
+ const qDiff = b.q - a.q;
78
+ if (qDiff !== 0) {
79
+ return qDiff;
80
+ }
81
+ return a.index - b.index;
82
+ };
83
+ // Annotate the CommonJS export names for ESM import in node:
84
+ 0 && (module.exports = {
85
+ parseAccept
86
+ });
@@ -22,7 +22,7 @@ __export(jwt_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(jwt_exports);
24
24
  var import_jwt = require("./jwt");
25
- const Jwt = { sign: import_jwt.sign, verify: import_jwt.verify, decode: import_jwt.decode };
25
+ const Jwt = { sign: import_jwt.sign, verify: import_jwt.verify, decode: import_jwt.decode, verifyFromJwks: import_jwt.verifyFromJwks };
26
26
  // Annotate the CommonJS export names for ESM import in node:
27
27
  0 && (module.exports = {
28
28
  Jwt
@@ -19,9 +19,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  var jwt_exports = {};
20
20
  __export(jwt_exports, {
21
21
  decode: () => decode,
22
+ decodeHeader: () => decodeHeader,
22
23
  isTokenHeader: () => isTokenHeader,
23
24
  sign: () => sign,
24
- verify: () => verify
25
+ verify: () => verify,
26
+ verifyFromJwks: () => verifyFromJwks
25
27
  });
26
28
  module.exports = __toCommonJS(jwt_exports);
27
29
  var import_encode = require("../../utils/encode");
@@ -41,7 +43,13 @@ function isTokenHeader(obj) {
41
43
  }
42
44
  const sign = async (payload, privateKey, alg = "HS256") => {
43
45
  const encodedPayload = encodeJwtPart(payload);
44
- const encodedHeader = encodeJwtPart({ alg, typ: "JWT" });
46
+ let encodedHeader;
47
+ if (typeof privateKey === "object" && "alg" in privateKey) {
48
+ alg = privateKey.alg;
49
+ encodedHeader = encodeJwtPart({ alg, typ: "JWT", kid: privateKey.kid });
50
+ } else {
51
+ encodedHeader = encodeJwtPart({ alg, typ: "JWT" });
52
+ }
45
53
  const partialToken = `${encodedHeader}.${encodedPayload}`;
46
54
  const signaturePart = await (0, import_jws.signing)(privateKey, alg, import_utf8.utf8Encoder.encode(partialToken));
47
55
  const signature = encodeSignaturePart(signaturePart);
@@ -78,6 +86,41 @@ const verify = async (token, publicKey, alg = "HS256") => {
78
86
  }
79
87
  return payload;
80
88
  };
89
+ const verifyFromJwks = async (token, options, init) => {
90
+ const header = decodeHeader(token);
91
+ if (!isTokenHeader(header)) {
92
+ throw new import_types.JwtHeaderInvalid(header);
93
+ }
94
+ if (!header.kid) {
95
+ throw new import_types.JwtHeaderRequiresKid(header);
96
+ }
97
+ let keys = typeof options.keys === "function" ? await options.keys() : options.keys;
98
+ if (options.jwks_uri) {
99
+ const response = await fetch(options.jwks_uri, init);
100
+ if (!response.ok) {
101
+ throw new Error(`failed to fetch JWKS from ${options.jwks_uri}`);
102
+ }
103
+ const data = await response.json();
104
+ if (!data.keys) {
105
+ throw new Error('invalid JWKS response. "keys" field is missing');
106
+ }
107
+ if (!Array.isArray(data.keys)) {
108
+ throw new Error('invalid JWKS response. "keys" field is not an array');
109
+ }
110
+ if (keys) {
111
+ keys.push(...data.keys);
112
+ } else {
113
+ keys = data.keys;
114
+ }
115
+ } else if (!keys) {
116
+ throw new Error('verifyFromJwks requires options for either "keys" or "jwks_uri" or both');
117
+ }
118
+ const matchingKey = keys.find((key) => key.kid === header.kid);
119
+ if (!matchingKey) {
120
+ throw new import_types.JwtTokenInvalid(token);
121
+ }
122
+ return await verify(token, matchingKey, matchingKey.alg);
123
+ };
81
124
  const decode = (token) => {
82
125
  try {
83
126
  const [h, p] = token.split(".");
@@ -91,10 +134,20 @@ const decode = (token) => {
91
134
  throw new import_types.JwtTokenInvalid(token);
92
135
  }
93
136
  };
137
+ const decodeHeader = (token) => {
138
+ try {
139
+ const [h] = token.split(".");
140
+ return decodeJwtPart(h);
141
+ } catch {
142
+ throw new import_types.JwtTokenInvalid(token);
143
+ }
144
+ };
94
145
  // Annotate the CommonJS export names for ESM import in node:
95
146
  0 && (module.exports = {
96
147
  decode,
148
+ decodeHeader,
97
149
  isTokenHeader,
98
150
  sign,
99
- verify
151
+ verify,
152
+ verifyFromJwks
100
153
  });
@@ -21,6 +21,7 @@ __export(types_exports, {
21
21
  CryptoKeyUsage: () => CryptoKeyUsage,
22
22
  JwtAlgorithmNotImplemented: () => JwtAlgorithmNotImplemented,
23
23
  JwtHeaderInvalid: () => JwtHeaderInvalid,
24
+ JwtHeaderRequiresKid: () => JwtHeaderRequiresKid,
24
25
  JwtTokenExpired: () => JwtTokenExpired,
25
26
  JwtTokenInvalid: () => JwtTokenInvalid,
26
27
  JwtTokenIssuedAt: () => JwtTokenIssuedAt,
@@ -64,6 +65,12 @@ class JwtHeaderInvalid extends Error {
64
65
  this.name = "JwtHeaderInvalid";
65
66
  }
66
67
  }
68
+ class JwtHeaderRequiresKid extends Error {
69
+ constructor(header) {
70
+ super(`required "kid" in jwt header: ${JSON.stringify(header)}`);
71
+ this.name = "JwtHeaderRequiresKid";
72
+ }
73
+ }
67
74
  class JwtTokenSignatureMismatched extends Error {
68
75
  constructor(token) {
69
76
  super(`token(${token}) signature mismatched`);
@@ -86,6 +93,7 @@ var CryptoKeyUsage = /* @__PURE__ */ ((CryptoKeyUsage2) => {
86
93
  CryptoKeyUsage,
87
94
  JwtAlgorithmNotImplemented,
88
95
  JwtHeaderInvalid,
96
+ JwtHeaderRequiresKid,
89
97
  JwtTokenExpired,
90
98
  JwtTokenInvalid,
91
99
  JwtTokenIssuedAt,
@@ -66,20 +66,21 @@ const replaceGroupMarks = (paths, groups) => {
66
66
  return paths;
67
67
  };
68
68
  const patternCache = {};
69
- const getPattern = (label) => {
69
+ const getPattern = (label, next) => {
70
70
  if (label === "*") {
71
71
  return "*";
72
72
  }
73
73
  const match = label.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
74
74
  if (match) {
75
- if (!patternCache[label]) {
75
+ const cacheKey = `${label}#${next}`;
76
+ if (!patternCache[cacheKey]) {
76
77
  if (match[2]) {
77
- patternCache[label] = [label, match[1], new RegExp("^" + match[2] + "$")];
78
+ patternCache[cacheKey] = next && next[0] !== ":" && next[0] !== "*" ? [cacheKey, match[1], new RegExp(`^${match[2]}(?=/${next})`)] : [label, match[1], new RegExp(`^${match[2]}$`)];
78
79
  } else {
79
- patternCache[label] = [label, match[1], true];
80
+ patternCache[cacheKey] = [label, match[1], true];
80
81
  }
81
82
  }
82
- return patternCache[label];
83
+ return patternCache[cacheKey];
83
84
  }
84
85
  return null;
85
86
  };
@@ -121,27 +122,11 @@ const getPathNoStrict = (request) => {
121
122
  const result = getPath(request);
122
123
  return result.length > 1 && result.at(-1) === "/" ? result.slice(0, -1) : result;
123
124
  };
124
- const mergePath = (...paths) => {
125
- let p = "";
126
- let endsWithSlash = false;
127
- for (let path of paths) {
128
- if (p.at(-1) === "/") {
129
- p = p.slice(0, -1);
130
- endsWithSlash = true;
131
- }
132
- if (path[0] !== "/") {
133
- path = `/${path}`;
134
- }
135
- if (path === "/" && endsWithSlash) {
136
- p = `${p}/`;
137
- } else if (path !== "/") {
138
- p = `${p}${path}`;
139
- }
140
- if (path === "/" && p === "") {
141
- p = "/";
142
- }
125
+ const mergePath = (base, sub, ...rest) => {
126
+ if (rest.length) {
127
+ sub = mergePath(sub, ...rest);
143
128
  }
144
- return p;
129
+ return `${base?.[0] === "/" ? "" : "/"}${base}${sub === "/" ? "" : `${base?.at(-1) === "/" ? "" : "/"}${sub?.[0] === "/" ? sub.slice(1) : sub}`}`;
145
130
  };
146
131
  const checkOptionalParameter = (path) => {
147
132
  if (!path.match(/\:.+\?$/)) {
@@ -1,25 +1,5 @@
1
1
  // src/helper/accepts/accepts.ts
2
- var parseAccept = (acceptHeader) => {
3
- const accepts2 = acceptHeader.split(",");
4
- return accepts2.map((accept) => {
5
- const parts = accept.trim().split(";");
6
- const type = parts[0];
7
- const params = parts.slice(1);
8
- const q = params.find((param) => param.startsWith("q="));
9
- const paramsObject = params.reduce((acc, param) => {
10
- const keyValue = param.split("=");
11
- const key = keyValue[0].trim();
12
- const value = keyValue[1].trim();
13
- acc[key] = value;
14
- return acc;
15
- }, {});
16
- return {
17
- type,
18
- params: paramsObject,
19
- q: q ? parseFloat(q.split("=")[1]) : 1
20
- };
21
- });
22
- };
2
+ import { parseAccept } from "../../utils/accept.js";
23
3
  var defaultMatch = (accepts2, config) => {
24
4
  const { supports, default: defaultSupport } = config;
25
5
  const accept = accepts2.sort((a, b) => b.q - a.q).find((accept2) => supports.includes(accept2.type));
@@ -36,6 +16,5 @@ var accepts = (c, options) => {
36
16
  };
37
17
  export {
38
18
  accepts,
39
- defaultMatch,
40
- parseAccept
19
+ defaultMatch
41
20
  };
@@ -2,11 +2,15 @@
2
2
  import { Hono } from "../../hono.js";
3
3
  var Factory = class {
4
4
  initApp;
5
+ #defaultAppOptions;
5
6
  constructor(init) {
6
7
  this.initApp = init?.initApp;
8
+ this.#defaultAppOptions = init?.defaultAppOptions;
7
9
  }
8
- createApp = () => {
9
- const app = new Hono();
10
+ createApp = (options) => {
11
+ const app = new Hono(
12
+ options && this.#defaultAppOptions ? { ...this.#defaultAppOptions, ...options } : options ?? this.#defaultAppOptions
13
+ );
10
14
  if (this.initApp) {
11
15
  this.initApp(app);
12
16
  }
@@ -0,0 +1,52 @@
1
+ // src/helper/proxy/index.ts
2
+ var hopByHopHeaders = [
3
+ "connection",
4
+ "keep-alive",
5
+ "proxy-authenticate",
6
+ "proxy-authorization",
7
+ "te",
8
+ "trailers",
9
+ "transfer-encoding"
10
+ ];
11
+ var buildRequestInitFromRequest = (request) => {
12
+ if (!request) {
13
+ return {};
14
+ }
15
+ const headers = new Headers(request.headers);
16
+ hopByHopHeaders.forEach((header) => {
17
+ headers.delete(header);
18
+ });
19
+ return {
20
+ method: request.method,
21
+ body: request.body,
22
+ duplex: request.body ? "half" : void 0,
23
+ headers
24
+ };
25
+ };
26
+ var proxy = async (input, proxyInit) => {
27
+ const { raw, ...requestInit } = proxyInit ?? {};
28
+ const req = new Request(
29
+ input,
30
+ {
31
+ ...buildRequestInitFromRequest(raw),
32
+ ...requestInit
33
+ }
34
+ );
35
+ req.headers.delete("accept-encoding");
36
+ const res = await fetch(req);
37
+ const resHeaders = new Headers(res.headers);
38
+ hopByHopHeaders.forEach((header) => {
39
+ resHeaders.delete(header);
40
+ });
41
+ if (resHeaders.has("content-encoding")) {
42
+ resHeaders.delete("content-encoding");
43
+ resHeaders.delete("content-length");
44
+ }
45
+ return new Response(res.body, {
46
+ ...res,
47
+ headers: resHeaders
48
+ });
49
+ };
50
+ export {
51
+ proxy
52
+ };
@@ -4,12 +4,17 @@ import { METHOD_NAME_ALL } from "../../router.js";
4
4
  import { TrieRouter } from "../../router/trie-router/index.js";
5
5
  var some = (...middleware) => {
6
6
  return async function some2(c, next) {
7
+ let isNextCalled = false;
8
+ const wrappedNext = () => {
9
+ isNextCalled = true;
10
+ return next();
11
+ };
7
12
  let lastError;
8
13
  for (const handler of middleware) {
9
14
  try {
10
- const result = await handler(c, next);
15
+ const result = await handler(c, wrappedNext);
11
16
  if (result === true && !c.finalized) {
12
- await next();
17
+ await wrappedNext();
13
18
  } else if (result === false) {
14
19
  lastError = new Error("No successful middleware found");
15
20
  continue;
@@ -18,7 +23,9 @@ var some = (...middleware) => {
18
23
  break;
19
24
  } catch (error) {
20
25
  lastError = error;
21
- continue;
26
+ if (isNextCalled) {
27
+ break;
28
+ }
22
29
  }
23
30
  }
24
31
  if (lastError) {
@@ -8,8 +8,8 @@ var mergeBuffers = (buffer1, buffer2) => {
8
8
  merged.set(buffer2, buffer1.byteLength);
9
9
  return merged;
10
10
  };
11
- var generateDigest = async (stream) => {
12
- if (!stream || !crypto || !crypto.subtle) {
11
+ var generateDigest = async (stream, generator) => {
12
+ if (!stream) {
13
13
  return null;
14
14
  }
15
15
  let result = void 0;
@@ -19,12 +19,7 @@ var generateDigest = async (stream) => {
19
19
  if (done) {
20
20
  break;
21
21
  }
22
- result = await crypto.subtle.digest(
23
- {
24
- name: "SHA-1"
25
- },
26
- mergeBuffers(result, value)
27
- );
22
+ result = await generator(mergeBuffers(result, value));
28
23
  }
29
24
  if (!result) {
30
25
  return null;
@@ -11,23 +11,39 @@ var RETAINED_304_HEADERS = [
11
11
  function etagMatches(etag2, ifNoneMatch) {
12
12
  return ifNoneMatch != null && ifNoneMatch.split(/,\s*/).indexOf(etag2) > -1;
13
13
  }
14
+ function initializeGenerator(generator) {
15
+ if (!generator) {
16
+ if (crypto && crypto.subtle) {
17
+ generator = (body) => crypto.subtle.digest(
18
+ {
19
+ name: "SHA-1"
20
+ },
21
+ body
22
+ );
23
+ }
24
+ }
25
+ return generator;
26
+ }
14
27
  var etag = (options) => {
15
28
  const retainedHeaders = options?.retainedHeaders ?? RETAINED_304_HEADERS;
16
29
  const weak = options?.weak ?? false;
30
+ const generator = initializeGenerator(options?.generateDigest);
17
31
  return async function etag2(c, next) {
18
32
  const ifNoneMatch = c.req.header("If-None-Match") ?? null;
19
33
  await next();
20
34
  const res = c.res;
21
35
  let etag3 = res.headers.get("ETag");
22
36
  if (!etag3) {
23
- const hash = await generateDigest(res.clone().body);
37
+ if (!generator) {
38
+ return;
39
+ }
40
+ const hash = await generateDigest(res.clone().body, generator);
24
41
  if (hash === null) {
25
42
  return;
26
43
  }
27
44
  etag3 = weak ? `W/"${hash}"` : `"${hash}"`;
28
45
  }
29
46
  if (etagMatches(etag3, ifNoneMatch)) {
30
- await c.res.blob();
31
47
  c.res = new Response(null, {
32
48
  status: 304,
33
49
  statusText: "Not Modified",
@@ -0,0 +1,5 @@
1
+ // src/middleware/jwk/index.ts
2
+ import { jwk } from "./jwk.js";
3
+ export {
4
+ jwk
5
+ };