hono 4.13.2 → 4.13.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.
Files changed (50) hide show
  1. package/dist/cjs/client/client.js +25 -11
  2. package/dist/cjs/client/utils.js +4 -1
  3. package/dist/cjs/context.js +4 -0
  4. package/dist/cjs/helper/accepts/accepts.js +36 -2
  5. package/dist/cjs/jsx/dom/render.js +2 -0
  6. package/dist/cjs/middleware/cors/index.js +1 -1
  7. package/dist/cjs/middleware/csrf/index.js +1 -1
  8. package/dist/cjs/middleware/etag/digest.js +1 -1
  9. package/dist/cjs/middleware/etag/index.js +3 -3
  10. package/dist/cjs/middleware/pretty-json/index.js +3 -1
  11. package/dist/cjs/request.js +8 -4
  12. package/dist/cjs/router/linear-router/router.js +7 -2
  13. package/dist/cjs/router/pattern-router/router.js +3 -9
  14. package/dist/cjs/router/reg-exp-router/node.js +10 -3
  15. package/dist/cjs/router/reg-exp-router/router.js +47 -83
  16. package/dist/cjs/router/reg-exp-router/trie.js +2 -1
  17. package/dist/cjs/router/trie-router/node.js +46 -69
  18. package/dist/cjs/router/trie-router/router.js +3 -11
  19. package/dist/cjs/router/utils.js +27 -0
  20. package/dist/cjs/utils/cookie.js +1 -1
  21. package/dist/cjs/utils/ipaddr.js +5 -3
  22. package/dist/cjs/utils/stream.js +7 -1
  23. package/dist/client/client.js +25 -11
  24. package/dist/client/utils.js +4 -1
  25. package/dist/context.js +4 -0
  26. package/dist/helper/accepts/accepts.js +36 -2
  27. package/dist/jsx/dom/render.js +2 -0
  28. package/dist/middleware/cors/index.js +1 -1
  29. package/dist/middleware/csrf/index.js +1 -1
  30. package/dist/middleware/etag/digest.js +1 -1
  31. package/dist/middleware/etag/index.js +3 -3
  32. package/dist/middleware/pretty-json/index.js +3 -1
  33. package/dist/request.js +8 -4
  34. package/dist/router/linear-router/router.js +7 -2
  35. package/dist/router/pattern-router/router.js +3 -9
  36. package/dist/router/reg-exp-router/node.js +6 -2
  37. package/dist/router/reg-exp-router/router.js +53 -84
  38. package/dist/router/reg-exp-router/trie.js +2 -1
  39. package/dist/router/trie-router/node.js +46 -69
  40. package/dist/router/trie-router/router.js +3 -11
  41. package/dist/router/utils.js +5 -0
  42. package/dist/types/context.d.ts +4 -0
  43. package/dist/types/router/reg-exp-router/node.d.ts +3 -0
  44. package/dist/types/router/trie-router/node.d.ts +1 -2
  45. package/dist/types/router/trie-router/router.d.ts +0 -1
  46. package/dist/types/router/utils.d.ts +1 -0
  47. package/dist/utils/cookie.js +1 -1
  48. package/dist/utils/ipaddr.js +5 -3
  49. package/dist/utils/stream.js +7 -1
  50. package/package.json +1 -1
@@ -5,25 +5,25 @@ import {
5
5
  UnsupportedPathError
6
6
  } from "../../router.js";
7
7
  import { checkOptionalParameter } from "../../utils/url.js";
8
+ import { createNullObject } from "../utils.js";
8
9
  import { match, emptyParam } from "./matcher.js";
9
- import { PATH_ERROR } from "./node.js";
10
+ import {
11
+ LABEL_REG_EXP_STR,
12
+ ONLY_WILDCARD_REG_EXP_STR,
13
+ PATH_ERROR,
14
+ TAIL_WILDCARD_REG_EXP_STR
15
+ } from "./node.js";
10
16
  import { Trie } from "./trie.js";
11
- var wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
17
+ var wildcardRegExpCache = createNullObject();
12
18
  function buildWildcardRegExp(path) {
13
19
  return wildcardRegExpCache[path] ??= new RegExp(
14
- path === "*" ? "" : `^${path.replace(
15
- /\/\*$|([.\\+*[^\]$()])/g,
16
- (_, metaChar) => metaChar ? `\\${metaChar}` : "(?:|/.*)"
20
+ `^${path.replace(
21
+ /\/:[^/{}]+(?:\{\[\^\/]\+})?(?=[/{]|$)|\/?\*$|([.\\+*[^\]$()?{}|])/g,
22
+ (match2, metaChar) => metaChar ? `\\${metaChar}` : match2 === "/*" ? TAIL_WILDCARD_REG_EXP_STR : match2 === "*" ? ONLY_WILDCARD_REG_EXP_STR : `/:${LABEL_REG_EXP_STR}`
17
23
  )}$`
18
24
  );
19
25
  }
20
- function clearWildcardRegExpCache() {
21
- wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
22
- }
23
26
  function findMiddleware(middleware, path) {
24
- if (!middleware) {
25
- return void 0;
26
- }
27
27
  for (const k of Object.keys(middleware).sort((a, b) => b.length - a.length)) {
28
28
  if (buildWildcardRegExp(k).test(path)) {
29
29
  return [...middleware[k]];
@@ -37,8 +37,8 @@ var RegExpRouter = class {
37
37
  #routes;
38
38
  #tries;
39
39
  constructor() {
40
- this.#middleware = { [METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) };
41
- this.#routes = { [METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) };
40
+ this.#middleware = { [METHOD_NAME_ALL]: createNullObject() };
41
+ this.#routes = { [METHOD_NAME_ALL]: createNullObject() };
42
42
  this.#tries = { [METHOD_NAME_ALL]: new Trie() };
43
43
  }
44
44
  #insertPath(method, path) {
@@ -51,117 +51,86 @@ var RegExpRouter = class {
51
51
  add(method, path, handler) {
52
52
  const middleware = this.#middleware;
53
53
  const routes = this.#routes;
54
- if (!middleware || !routes) {
54
+ if (!middleware) {
55
55
  throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT);
56
56
  }
57
57
  if (!middleware[method]) {
58
58
  this.#tries[method] = new Trie();
59
- [middleware, routes].forEach((handlerMap) => {
60
- handlerMap[method] = /* @__PURE__ */ Object.create(null);
61
- Object.keys(handlerMap[METHOD_NAME_ALL]).forEach((p) => {
59
+ for (const handlerMap of [middleware, routes]) {
60
+ handlerMap[method] = createNullObject();
61
+ for (const p in handlerMap[METHOD_NAME_ALL]) {
62
62
  handlerMap[method][p] = [...handlerMap[METHOD_NAME_ALL][p]];
63
63
  this.#insertPath(method, p);
64
- });
65
- });
64
+ }
65
+ }
66
66
  }
67
67
  if (path === "/*") {
68
68
  path = "*";
69
69
  }
70
- const paramCount = (path.match(/\/:/g) || []).length;
70
+ const methods = method === METHOD_NAME_ALL ? Object.keys(middleware) : [method];
71
71
  if (/\*$/.test(path)) {
72
72
  const re = buildWildcardRegExp(path);
73
- Object.keys(middleware).forEach((m) => {
74
- if ((method === METHOD_NAME_ALL || method === m) && !middleware[m][path]) {
73
+ for (const m of methods) {
74
+ if (!middleware[m][path]) {
75
75
  this.#insertPath(m, path);
76
76
  middleware[m][path] = findMiddleware(middleware[m], path) || findMiddleware(middleware[METHOD_NAME_ALL], path) || [];
77
77
  }
78
- });
79
- Object.keys(middleware).forEach((m) => {
80
- if (method === METHOD_NAME_ALL || method === m) {
81
- Object.keys(middleware[m]).forEach((p) => {
82
- re.test(p) && middleware[m][p].push([handler, paramCount]);
83
- });
84
- }
85
- });
86
- Object.keys(routes).forEach((m) => {
87
- if (method === METHOD_NAME_ALL || method === m) {
88
- Object.keys(routes[m]).forEach(
89
- (p) => re.test(p) && routes[m][p].push([handler, paramCount])
90
- );
78
+ }
79
+ for (const handlerMap of [middleware, routes]) {
80
+ for (const m of methods) {
81
+ for (const p in handlerMap[m]) {
82
+ re.test(p) && handlerMap[m][p].push([handler, path]);
83
+ }
91
84
  }
92
- });
85
+ }
93
86
  return;
94
87
  }
95
88
  const paths = checkOptionalParameter(path) || [path];
96
- for (let i = 0, len = paths.length; i < len; i++) {
97
- const path2 = paths[i];
98
- Object.keys(routes).forEach((m) => {
99
- if (method === METHOD_NAME_ALL || method === m) {
100
- if (!routes[m][path2]) {
101
- this.#insertPath(m, path2);
102
- routes[m][path2] = [
103
- ...findMiddleware(middleware[m], path2) || findMiddleware(middleware[METHOD_NAME_ALL], path2) || []
104
- ];
105
- }
106
- routes[m][path2].push([handler, paramCount - len + i + 1]);
89
+ for (const path2 of paths) {
90
+ for (const m of methods) {
91
+ if (!routes[m][path2]) {
92
+ this.#insertPath(m, path2);
93
+ routes[m][path2] = findMiddleware(middleware[m], path2) || findMiddleware(middleware[METHOD_NAME_ALL], path2) || [];
107
94
  }
108
- });
95
+ routes[m][path2].push([handler, path2]);
96
+ }
109
97
  }
110
98
  }
111
99
  match = match;
112
100
  buildAllMatchers() {
113
- const matchers = /* @__PURE__ */ Object.create(null);
114
- Object.keys(this.#routes).concat(Object.keys(this.#middleware)).forEach((method) => {
115
- matchers[method] ||= this.#buildMatcher(method);
116
- });
101
+ const matchers = createNullObject();
102
+ for (const method of Object.keys(this.#routes)) {
103
+ matchers[method] = this.#buildMatcher(method);
104
+ }
117
105
  this.#middleware = this.#routes = this.#tries = void 0;
118
- clearWildcardRegExpCache();
106
+ wildcardRegExpCache = createNullObject();
119
107
  return matchers;
120
108
  }
121
109
  #buildMatcher(method) {
122
110
  const middleware = this.#middleware[method];
123
111
  const routes = this.#routes[method];
124
112
  const trie = this.#tries[method];
125
- const staticMap = /* @__PURE__ */ Object.create(null);
113
+ const staticMap = createNullObject();
126
114
  const handlerData = [];
127
- [middleware, routes].forEach((r) => {
115
+ const [regexp, indexReplacementMap, paramReplacementMap] = trie.buildRegExp();
116
+ for (const r of [middleware, routes]) {
128
117
  for (const path in r) {
129
118
  const handlers = r[path];
130
119
  const pathData = trie.paths[path];
131
120
  if (!pathData) {
132
- staticMap[path] = [handlers.map(([h]) => [h, /* @__PURE__ */ Object.create(null)]), emptyParam];
133
- continue;
134
- }
135
- const paramAssoc = pathData[1];
136
- handlerData[pathData[0]] = handlers.map(([h, paramCount]) => {
137
- const paramIndexMap = /* @__PURE__ */ Object.create(null);
138
- paramCount -= 1;
139
- for (; paramCount >= 0; paramCount--) {
140
- const [key, value] = paramAssoc[paramCount];
141
- paramIndexMap[key] = value;
142
- }
143
- return [h, paramIndexMap];
144
- });
145
- }
146
- });
147
- const [regexp, indexReplacementMap, paramReplacementMap] = trie.buildRegExp();
148
- for (let i = 0, len = handlerData.length; i < len; i++) {
149
- for (let j = 0, len2 = handlerData[i].length; j < len2; j++) {
150
- const map = handlerData[i][j]?.[1];
151
- if (!map) {
121
+ staticMap[path] = [handlers.map(([h]) => [h, createNullObject()]), emptyParam];
152
122
  continue;
153
123
  }
154
- const keys = Object.keys(map);
155
- for (let k = 0, len3 = keys.length; k < len3; k++) {
156
- map[keys[k]] = paramReplacementMap[map[keys[k]]];
157
- }
124
+ handlerData[pathData[0]] = handlers.map(([h, handlerPath]) => [
125
+ h,
126
+ trie.paths[handlerPath][1].reduceRight((map, [key], i) => {
127
+ map[key] = paramReplacementMap[pathData[1][i][1]];
128
+ return map;
129
+ }, createNullObject())
130
+ ]);
158
131
  }
159
132
  }
160
- const handlerMap = [];
161
- for (const i in indexReplacementMap) {
162
- handlerMap[i] = handlerData[indexReplacementMap[i]];
163
- }
164
- return [regexp, handlerMap, staticMap];
133
+ return [regexp, indexReplacementMap.map((i) => handlerData[i]), staticMap];
165
134
  }
166
135
  };
167
136
  export {
@@ -1,11 +1,12 @@
1
1
  // src/router/reg-exp-router/trie.ts
2
+ import { createNullObject } from "../utils.js";
2
3
  import { Node } from "./node.js";
3
4
  var Trie = class {
4
5
  #context = { varIndex: 0 };
5
6
  #root = new Node();
6
7
  #index = 0;
7
8
  // dynamic path -> [handler index, param assoc]; static paths are not registered
8
- paths = /* @__PURE__ */ Object.create(null);
9
+ paths = createNullObject();
9
10
  insert(path, isStatic) {
10
11
  if (isStatic) {
11
12
  this.#root.insert(path.split(""), 0, [], this.#context, true);
@@ -1,77 +1,53 @@
1
1
  // src/router/trie-router/node.ts
2
2
  import { METHOD_NAME_ALL } from "../../router.js";
3
3
  import { getPattern, splitPath, splitRoutingPath } from "../../utils/url.js";
4
- var emptyParams = /* @__PURE__ */ Object.create(null);
5
- var hasChildren = (children) => {
6
- for (const _ in children) {
7
- return true;
8
- }
9
- return false;
10
- };
4
+ import { createNullObject } from "../utils.js";
5
+ var emptyParams = createNullObject();
6
+ var order = 0;
11
7
  var Node = class _Node {
12
- #methods;
13
- #children;
14
- #patterns;
15
- #order = 0;
8
+ #methods = [];
9
+ #children = createNullObject();
10
+ #patterns = [];
11
+ #pattern;
16
12
  #params = emptyParams;
17
- constructor(method, handler, children) {
18
- this.#children = children || /* @__PURE__ */ Object.create(null);
19
- this.#methods = [];
20
- if (method && handler) {
21
- const m = /* @__PURE__ */ Object.create(null);
22
- m[method] = { handler, possibleKeys: [], score: 0 };
23
- this.#methods = [m];
24
- }
25
- this.#patterns = [];
26
- }
27
13
  insert(method, path, handler) {
28
- this.#order = ++this.#order;
29
14
  let curNode = this;
30
15
  const parts = splitRoutingPath(path);
31
- const possibleKeys = [];
32
- for (let i = 0, len = parts.length; i < len; i++) {
33
- const p = parts[i];
34
- const nextP = parts[i + 1];
35
- const pattern = getPattern(p, nextP);
36
- const key = Array.isArray(pattern) ? pattern[0] : p;
37
- if (key in curNode.#children) {
38
- curNode = curNode.#children[key];
39
- if (pattern) {
40
- possibleKeys.push(pattern[1]);
41
- }
42
- continue;
16
+ const possibleKeys = /* @__PURE__ */ new Set();
17
+ let i = 0;
18
+ for (const p of parts) {
19
+ const nextP = parts[++i];
20
+ const pattern = getPattern(p, nextP) || (nextP === void 0 && p && p.indexOf("*") === p.length - 1 ? p : null);
21
+ const isParam = Array.isArray(pattern);
22
+ const key = isParam ? pattern[0] : pattern || p;
23
+ const child = curNode.#children[key] ||= new _Node();
24
+ if (pattern && !child.#pattern) {
25
+ child.#pattern = pattern;
26
+ curNode.#patterns.push(child);
43
27
  }
44
- curNode.#children[key] = new _Node();
45
- if (pattern) {
46
- curNode.#patterns.push(pattern);
47
- possibleKeys.push(pattern[1]);
28
+ curNode = child;
29
+ if (isParam) {
30
+ possibleKeys.add(pattern[1]);
48
31
  }
49
- curNode = curNode.#children[key];
50
32
  }
51
33
  curNode.#methods.push({
52
34
  [method]: {
53
35
  handler,
54
- possibleKeys: possibleKeys.filter((v, i, a) => a.indexOf(v) === i),
55
- score: this.#order
36
+ possibleKeys: [...possibleKeys],
37
+ score: ++order
56
38
  }
57
39
  });
58
- return curNode;
59
40
  }
60
41
  #pushHandlerSets(handlerSets, node, method, nodeParams, params) {
61
42
  for (let i = 0, len = node.#methods.length; i < len; i++) {
62
43
  const m = node.#methods[i];
63
44
  const handlerSet = m[method] || m[METHOD_NAME_ALL];
64
- const processedSet = {};
65
- if (handlerSet !== void 0) {
66
- handlerSet.params = /* @__PURE__ */ Object.create(null);
45
+ if (handlerSet) {
46
+ handlerSet.params = createNullObject();
67
47
  handlerSets.push(handlerSet);
68
- if (nodeParams !== emptyParams || params && params !== emptyParams) {
69
- for (let i2 = 0, len2 = handlerSet.possibleKeys.length; i2 < len2; i2++) {
70
- const key = handlerSet.possibleKeys[i2];
71
- const processed = processedSet[handlerSet.score];
72
- handlerSet.params[key] = params?.[key] && !processed ? params[key] : nodeParams[key] ?? params?.[key];
73
- processedSet[handlerSet.score] = true;
74
- }
48
+ for (let i2 = 0, len2 = handlerSet.possibleKeys.length; i2 < len2; i2++) {
49
+ const key = handlerSet.possibleKeys[i2];
50
+ handlerSet.params[key] = params?.[key] && !i2 ? params[key] : nodeParams[key] ?? params?.[key];
75
51
  }
76
52
  }
77
53
  }
@@ -103,33 +79,33 @@ var Node = class _Node {
103
79
  tempNodes.push(nextNode);
104
80
  }
105
81
  }
106
- for (let k = 0, len3 = node.#patterns.length; k < len3; k++) {
107
- const pattern = node.#patterns[k];
82
+ for (const child of node.#patterns) {
83
+ const pattern = child.#pattern;
108
84
  const params = node.#params === emptyParams ? {} : { ...node.#params };
109
- if (pattern === "*") {
110
- const astNode = node.#children["*"];
111
- if (astNode) {
112
- this.#pushHandlerSets(handlerSets, astNode, method, node.#params);
113
- astNode.#params = params;
114
- tempNodes.push(astNode);
85
+ if (typeof pattern === "string") {
86
+ if (pattern === "*" || part.startsWith(pattern.slice(0, -1))) {
87
+ this.#pushHandlerSets(handlerSets, child, method, node.#params);
88
+ if (pattern === "*") {
89
+ child.#params = params;
90
+ tempNodes.push(child);
91
+ }
115
92
  }
116
93
  continue;
117
94
  }
118
- const [key, name, matcher] = pattern;
119
- if (!part && !(matcher instanceof RegExp)) {
95
+ const [, name, matcher] = pattern;
96
+ if (!part && matcher === true) {
120
97
  continue;
121
98
  }
122
- const child = node.#children[key];
123
- if (matcher instanceof RegExp) {
124
- if (partOffsets === null) {
125
- partOffsets = new Array(len);
99
+ if (matcher !== true) {
100
+ if (!partOffsets) {
101
+ partOffsets = [];
126
102
  let offset = path[0] === "/" ? 1 : 0;
127
103
  for (let p = 0; p < len; p++) {
128
104
  partOffsets[p] = offset;
129
105
  offset += parts[p].length + 1;
130
106
  }
131
107
  }
132
- const restPathString = path.substring(partOffsets[i]);
108
+ const restPathString = path.slice(partOffsets[i]);
133
109
  const m = matcher.exec(restPathString);
134
110
  if (m) {
135
111
  params[name] = m[0];
@@ -143,11 +119,12 @@ var Node = class _Node {
143
119
  params
144
120
  );
145
121
  }
146
- if (hasChildren(child.#children)) {
122
+ for (const _ in child.#children) {
147
123
  child.#params = params;
148
124
  const componentCount = m[0].match(/\//g)?.length ?? 0;
149
125
  const targetCurNodes = curNodesQueue[componentCount] ||= [];
150
126
  targetCurNodes.push(child);
127
+ break;
151
128
  }
152
129
  continue;
153
130
  }
@@ -175,7 +152,7 @@ var Node = class _Node {
175
152
  const shifted = curNodesQueue.shift();
176
153
  curNodes = shifted ? tempNodes.concat(shifted) : tempNodes;
177
154
  }
178
- if (handlerSets.length > 1) {
155
+ if (handlerSets[1]) {
179
156
  handlerSets.sort((a, b) => {
180
157
  return a.score - b.score;
181
158
  });
@@ -3,19 +3,11 @@ import { checkOptionalParameter } from "../../utils/url.js";
3
3
  import { Node } from "./node.js";
4
4
  var TrieRouter = class {
5
5
  name = "TrieRouter";
6
- #node;
7
- constructor() {
8
- this.#node = new Node();
9
- }
6
+ #node = new Node();
10
7
  add(method, path, handler) {
11
- const results = checkOptionalParameter(path);
12
- if (results) {
13
- for (let i = 0, len = results.length; i < len; i++) {
14
- this.#node.insert(method, results[i], handler);
15
- }
16
- return;
8
+ for (const result of checkOptionalParameter(path) || [path]) {
9
+ this.#node.insert(method, result, handler);
17
10
  }
18
- this.#node.insert(method, path, handler);
19
11
  }
20
12
  match(method, path) {
21
13
  return this.#node.search(method, path);
@@ -0,0 +1,5 @@
1
+ // src/router/utils.ts
2
+ var createNullObject = () => /* @__PURE__ */ Object.create(null);
3
+ export {
4
+ createNullObject
5
+ };
@@ -323,6 +323,10 @@ export declare class Context<E extends Env = any, P extends string = any, I exte
323
323
  * c.header('X-Message', 'Hello!')
324
324
  * c.header('Content-Type', 'text/plain')
325
325
  *
326
+ * // Append multiple headers using the append option (e.g. Vary)
327
+ * c.header('Vary', 'Accept-Encoding', { append: true })
328
+ * c.header('Vary', 'User-Agent', { append: true })
329
+ *
326
330
  * return c.body('Thank you for coming')
327
331
  * })
328
332
  * ```
@@ -1,3 +1,6 @@
1
+ export declare const LABEL_REG_EXP_STR = "[^/]+";
2
+ export declare const ONLY_WILDCARD_REG_EXP_STR = ".*";
3
+ export declare const TAIL_WILDCARD_REG_EXP_STR = "(?:|/.*)";
1
4
  export declare const PATH_ERROR: unique symbol;
2
5
  export type ParamAssocArray = [string, number][];
3
6
  export interface Context {
@@ -1,7 +1,6 @@
1
1
  import type { Params } from '../../router';
2
2
  export declare class Node<T> {
3
3
 
4
- constructor(method?: string, handler?: T, children?: Record<string, Node<T>>);
5
- insert(method: string, path: string, handler: T): Node<T>;
4
+ insert(method: string, path: string, handler: T): void;
6
5
  search(method: string, path: string): [[T, Params][]];
7
6
  }
@@ -2,7 +2,6 @@ import type { Result, Router } from '../../router';
2
2
  export declare class TrieRouter<T> implements Router<T> {
3
3
 
4
4
  name: string;
5
- constructor();
6
5
  add(method: string, path: string, handler: T): void;
7
6
  match(method: string, path: string): Result<T>;
8
7
  }
@@ -0,0 +1 @@
1
+ export declare const createNullObject: () => any;
@@ -77,7 +77,7 @@ var parseSigned = async (cookie, secret, name) => {
77
77
  const secretKey = await getCryptoKey(secret);
78
78
  for (const [key, value] of Object.entries(parse(cookie, name))) {
79
79
  const signatureStartPos = value.lastIndexOf(".");
80
- if (signatureStartPos < 1) {
80
+ if (signatureStartPos < 0) {
81
81
  continue;
82
82
  }
83
83
  const signedValue = value.substring(0, signatureStartPos);
@@ -1,12 +1,14 @@
1
1
  // src/utils/ipaddr.ts
2
2
  var expandIPv6 = (ipV6) => {
3
3
  const sections = ipV6.split(":");
4
- if (IPV4_REGEX.test(sections.at(-1))) {
4
+ const lastSection = sections.at(-1);
5
+ if (IPV4_REGEX.test(lastSection)) {
6
+ const octets = lastSection.split(".").map(Number);
5
7
  sections.splice(
6
8
  -1,
7
9
  1,
8
- ...convertIPv6BinaryToString(convertIPv4ToBinary(sections.at(-1))).substring(2).split(":")
9
- // => ['7f00', '0001']
10
+ (octets[0] << 8 | octets[1]).toString(16),
11
+ (octets[2] << 8 | octets[3]).toString(16)
10
12
  );
11
13
  }
12
14
  for (let i = 0; i < sections.length; i++) {
@@ -75,7 +75,13 @@ var StreamingApi = class {
75
75
  abort() {
76
76
  if (!this.aborted) {
77
77
  this.aborted = true;
78
- this.abortSubscribers.forEach((subscriber) => subscriber());
78
+ this.abortSubscribers.forEach((subscriber) => {
79
+ try {
80
+ void Promise.resolve(subscriber()).catch(() => {
81
+ });
82
+ } catch {
83
+ }
84
+ });
79
85
  }
80
86
  }
81
87
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hono",
3
- "version": "4.13.2",
3
+ "version": "4.13.4",
4
4
  "description": "Web framework built on Web Standards",
5
5
  "main": "dist/cjs/index.js",
6
6
  "type": "module",