hono 4.9.4 → 4.9.6

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.
@@ -165,9 +165,11 @@ var EventV1Processor = class extends EventProcessor {
165
165
  }
166
166
  getQueryString(event) {
167
167
  if (event.multiValueQueryStringParameters) {
168
- return Object.entries(event.multiValueQueryStringParameters || {}).filter(([, value]) => value).map(([key, value]) => `${key}=${value.join(`&${key}=`)}`).join("&");
168
+ return Object.entries(event.multiValueQueryStringParameters || {}).filter(([, value]) => value).map(
169
+ ([key, values]) => values.map((value) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`).join("&")
170
+ ).join("&");
169
171
  } else {
170
- return Object.entries(event.queryStringParameters || {}).filter(([, value]) => value).map(([key, value]) => `${key}=${value}`).join("&");
172
+ return Object.entries(event.queryStringParameters || {}).filter(([, value]) => value).map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value || "")}`).join("&");
171
173
  }
172
174
  }
173
175
  getCookies(event, headers) {
@@ -5,7 +5,7 @@ var handle = (app, opts = {
5
5
  return (evt) => {
6
6
  evt.respondWith(
7
7
  (async () => {
8
- const res = await app.fetch(evt.request, evt);
8
+ const res = await app.fetch(evt.request, {}, evt);
9
9
  if (opts.fetch && res.status === 404) {
10
10
  return await opts.fetch(evt.request);
11
11
  }
@@ -195,9 +195,11 @@ class EventV1Processor extends EventProcessor {
195
195
  }
196
196
  getQueryString(event) {
197
197
  if (event.multiValueQueryStringParameters) {
198
- return Object.entries(event.multiValueQueryStringParameters || {}).filter(([, value]) => value).map(([key, value]) => `${key}=${value.join(`&${key}=`)}`).join("&");
198
+ return Object.entries(event.multiValueQueryStringParameters || {}).filter(([, value]) => value).map(
199
+ ([key, values]) => values.map((value) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`).join("&")
200
+ ).join("&");
199
201
  } else {
200
- return Object.entries(event.queryStringParameters || {}).filter(([, value]) => value).map(([key, value]) => `${key}=${value}`).join("&");
202
+ return Object.entries(event.queryStringParameters || {}).filter(([, value]) => value).map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value || "")}`).join("&");
201
203
  }
202
204
  }
203
205
  getCookies(event, headers) {
@@ -27,7 +27,7 @@ const handle = (app, opts = {
27
27
  return (evt) => {
28
28
  evt.respondWith(
29
29
  (async () => {
30
- const res = await app.fetch(evt.request, evt);
30
+ const res = await app.fetch(evt.request, {}, evt);
31
31
  if (opts.fetch && res.status === 404) {
32
32
  return await opts.fetch(evt.request);
33
33
  }
@@ -58,7 +58,7 @@ const cors = (options) => {
58
58
  function set(key, value) {
59
59
  c.res.headers.set(key, value);
60
60
  }
61
- const allowOrigin = findAllowOrigin(c.req.header("origin") || "", c);
61
+ const allowOrigin = await findAllowOrigin(c.req.header("origin") || "", c);
62
62
  if (allowOrigin) {
63
63
  set("Access-Control-Allow-Origin", allowOrigin);
64
64
  }
@@ -80,7 +80,7 @@ const cors = (options) => {
80
80
  if (opts.maxAge != null) {
81
81
  set("Access-Control-Max-Age", opts.maxAge.toString());
82
82
  }
83
- const allowMethods = findAllowMethods(c.req.header("origin") || "", c);
83
+ const allowMethods = await findAllowMethods(c.req.header("origin") || "", c);
84
84
  if (allowMethods.length) {
85
85
  set("Access-Control-Allow-Methods", allowMethods.join(","));
86
86
  }
@@ -108,7 +108,8 @@ function detectFromHeader(c, options) {
108
108
  }
109
109
  function detectFromPath(c, options) {
110
110
  try {
111
- const pathSegments = c.req.path.split("/").filter(Boolean);
111
+ const url = new URL(c.req.url);
112
+ const pathSegments = url.pathname.split("/").filter(Boolean);
112
113
  const langSegment = pathSegments[options.lookupFromPathIndex];
113
114
  return normalizeLanguage(langSegment, options);
114
115
  } catch {
@@ -100,10 +100,7 @@ const tryDecode = (str, decoder) => {
100
100
  const tryDecodeURI = (str) => tryDecode(str, decodeURI);
101
101
  const getPath = (request) => {
102
102
  const url = request.url;
103
- const start = url.indexOf(
104
- "/",
105
- url.charCodeAt(9) === 58 ? 13 : 8
106
- );
103
+ const start = url.indexOf("/", url.indexOf(":") + 4);
107
104
  let i = start;
108
105
  for (; i < url.length; i++) {
109
106
  const charCode = url.charCodeAt(i);
@@ -36,7 +36,7 @@ var cors = (options) => {
36
36
  function set(key, value) {
37
37
  c.res.headers.set(key, value);
38
38
  }
39
- const allowOrigin = findAllowOrigin(c.req.header("origin") || "", c);
39
+ const allowOrigin = await findAllowOrigin(c.req.header("origin") || "", c);
40
40
  if (allowOrigin) {
41
41
  set("Access-Control-Allow-Origin", allowOrigin);
42
42
  }
@@ -58,7 +58,7 @@ var cors = (options) => {
58
58
  if (opts.maxAge != null) {
59
59
  set("Access-Control-Max-Age", opts.maxAge.toString());
60
60
  }
61
- const allowMethods = findAllowMethods(c.req.header("origin") || "", c);
61
+ const allowMethods = await findAllowMethods(c.req.header("origin") || "", c);
62
62
  if (allowMethods.length) {
63
63
  set("Access-Control-Allow-Methods", allowMethods.join(","));
64
64
  }
@@ -77,7 +77,8 @@ function detectFromHeader(c, options) {
77
77
  }
78
78
  function detectFromPath(c, options) {
79
79
  try {
80
- const pathSegments = c.req.path.split("/").filter(Boolean);
80
+ const url = new URL(c.req.url);
81
+ const pathSegments = url.pathname.split("/").filter(Boolean);
81
82
  const langSegment = pathSegments[options.lookupFromPathIndex];
82
83
  return normalizeLanguage(langSegment, options);
83
84
  } catch {
@@ -5,8 +5,8 @@
5
5
  import type { Context } from '../../context';
6
6
  import type { MiddlewareHandler } from '../../types';
7
7
  type CORSOptions = {
8
- origin: string | string[] | ((origin: string, c: Context) => string | undefined | null);
9
- allowMethods?: string[] | ((origin: string, c: Context) => string[]);
8
+ origin: string | string[] | ((origin: string, c: Context) => Promise<string | undefined | null> | string | undefined | null);
9
+ allowMethods?: string[] | ((origin: string, c: Context) => Promise<string[]> | string[]);
10
10
  allowHeaders?: string[];
11
11
  maxAge?: number;
12
12
  credentials?: boolean;
@@ -18,8 +18,8 @@ type CORSOptions = {
18
18
  * @see {@link https://hono.dev/docs/middleware/builtin/cors}
19
19
  *
20
20
  * @param {CORSOptions} [options] - The options for the CORS middleware.
21
- * @param {string | string[] | ((origin: string, c: Context) => string | undefined | null)} [options.origin='*'] - The value of "Access-Control-Allow-Origin" CORS header.
22
- * @param {string[] | ((origin: string, c: Context) => string[])} [options.allowMethods=['GET', 'HEAD', 'PUT', 'POST', 'DELETE', 'PATCH']] - The value of "Access-Control-Allow-Methods" CORS header.
21
+ * @param {string | string[] | ((origin: string, c: Context) => Promise<string | undefined | null> | string | undefined | null)} [options.origin='*'] - The value of "Access-Control-Allow-Origin" CORS header.
22
+ * @param {string[] | ((origin: string, c: Context) => Promise<string[]> | string[])} [options.allowMethods=['GET', 'HEAD', 'PUT', 'POST', 'DELETE', 'PATCH']] - The value of "Access-Control-Allow-Methods" CORS header.
23
23
  * @param {string[]} [options.allowHeaders=[]] - The value of "Access-Control-Allow-Headers" CORS header.
24
24
  * @param {number} [options.maxAge] - The value of "Access-Control-Max-Age" CORS header.
25
25
  * @param {boolean} [options.credentials] - The value of "Access-Control-Allow-Credentials" CORS header.
package/dist/utils/url.js CHANGED
@@ -67,10 +67,7 @@ var tryDecode = (str, decoder) => {
67
67
  var tryDecodeURI = (str) => tryDecode(str, decodeURI);
68
68
  var getPath = (request) => {
69
69
  const url = request.url;
70
- const start = url.indexOf(
71
- "/",
72
- url.charCodeAt(9) === 58 ? 13 : 8
73
- );
70
+ const start = url.indexOf("/", url.indexOf(":") + 4);
74
71
  let i = start;
75
72
  for (; i < url.length; i++) {
76
73
  const charCode = url.charCodeAt(i);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hono",
3
- "version": "4.9.4",
3
+ "version": "4.9.6",
4
4
  "description": "Web framework built on Web Standards",
5
5
  "main": "dist/cjs/index.js",
6
6
  "type": "module",
@@ -661,7 +661,6 @@
661
661
  "@types/glob": "^9.0.0",
662
662
  "@types/jsdom": "^21.1.7",
663
663
  "@types/node": "^24.3.0",
664
- "@types/supertest": "^6.0.3",
665
664
  "@typescript/native-preview": "7.0.0-dev.20250523.1",
666
665
  "@vitest/coverage-v8": "^3.2.4",
667
666
  "arg": "^5.0.2",
@@ -676,8 +675,8 @@
676
675
  "pkg-pr-new": "^0.0.53",
677
676
  "prettier": "^2.6.2",
678
677
  "publint": "^0.1.16",
679
- "supertest": "^6.3.4",
680
678
  "typescript": "^5.9.2",
679
+ "undici": "^6.21.3",
681
680
  "vite-plugin-fastly-js-compute": "^0.4.2",
682
681
  "vitest": "^3.2.4",
683
682
  "wrangler": "4.12.0",