hono 4.4.7 → 4.4.8

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.
@@ -1,10 +1,10 @@
1
1
  // src/adapter/deno/websocket.ts
2
- var upgradeWebSocket = (createEvents) => async (c, next) => {
2
+ var upgradeWebSocket = (createEvents, options) => async (c, next) => {
3
3
  if (c.req.header("upgrade") !== "websocket") {
4
4
  return await next();
5
5
  }
6
6
  const events = await createEvents(c);
7
- const { response, socket } = Deno.upgradeWebSocket(c.req.raw);
7
+ const { response, socket } = Deno.upgradeWebSocket(c.req.raw, options || {});
8
8
  const wsContext = {
9
9
  binaryType: "arraybuffer",
10
10
  close: (code, reason) => socket.close(code, reason),
@@ -21,12 +21,12 @@ __export(websocket_exports, {
21
21
  upgradeWebSocket: () => upgradeWebSocket
22
22
  });
23
23
  module.exports = __toCommonJS(websocket_exports);
24
- const upgradeWebSocket = (createEvents) => async (c, next) => {
24
+ const upgradeWebSocket = (createEvents, options) => async (c, next) => {
25
25
  if (c.req.header("upgrade") !== "websocket") {
26
26
  return await next();
27
27
  }
28
28
  const events = await createEvents(c);
29
- const { response, socket } = Deno.upgradeWebSocket(c.req.raw);
29
+ const { response, socket } = Deno.upgradeWebSocket(c.req.raw, options || {});
30
30
  const wsContext = {
31
31
  binaryType: "arraybuffer",
32
32
  close: (code, reason) => socket.close(code, reason),
@@ -26,14 +26,20 @@ module.exports = __toCommonJS(accepts_exports);
26
26
  const parseAccept = (acceptHeader) => {
27
27
  const accepts2 = acceptHeader.split(",");
28
28
  return accepts2.map((accept) => {
29
- const [type, ...params] = accept.trim().split(";");
29
+ const parts = accept.trim().split(";");
30
+ const type = parts[0];
31
+ const params = parts.slice(1);
30
32
  const q = params.find((param) => param.startsWith("q="));
33
+ const paramsObject = params.reduce((acc, param) => {
34
+ const keyValue = param.split("=");
35
+ const key = keyValue[0].trim();
36
+ const value = keyValue[1].trim();
37
+ acc[key] = value;
38
+ return acc;
39
+ }, {});
31
40
  return {
32
41
  type,
33
- params: params.reduce((acc, param) => {
34
- const [key, value] = param.split("=");
35
- return { ...acc, [key.trim()]: value.trim() };
36
- }, {}),
42
+ params: paramsObject,
37
43
  q: q ? parseFloat(q.split("=")[1]) : 1
38
44
  };
39
45
  });
@@ -46,8 +46,7 @@ const timingSafeEqual = async (a, b, hashFunction) => {
46
46
  if (!hashFunction) {
47
47
  hashFunction = import_crypto.sha256;
48
48
  }
49
- const sa = await hashFunction(a);
50
- const sb = await hashFunction(b);
49
+ const [sa, sb] = await Promise.all([hashFunction(a), hashFunction(b)]);
51
50
  if (!sa || !sb) {
52
51
  return false;
53
52
  }
@@ -2,14 +2,20 @@
2
2
  var parseAccept = (acceptHeader) => {
3
3
  const accepts2 = acceptHeader.split(",");
4
4
  return accepts2.map((accept) => {
5
- const [type, ...params] = accept.trim().split(";");
5
+ const parts = accept.trim().split(";");
6
+ const type = parts[0];
7
+ const params = parts.slice(1);
6
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
+ }, {});
7
16
  return {
8
17
  type,
9
- params: params.reduce((acc, param) => {
10
- const [key, value] = param.split("=");
11
- return { ...acc, [key.trim()]: value.trim() };
12
- }, {}),
18
+ params: paramsObject,
13
19
  q: q ? parseFloat(q.split("=")[1]) : 1
14
20
  };
15
21
  });
@@ -1,2 +1,21 @@
1
1
  import type { UpgradeWebSocket } from '../../helper/websocket';
2
- export declare const upgradeWebSocket: UpgradeWebSocket;
2
+ export interface UpgradeWebSocketOptions {
3
+ /**
4
+ * Sets the `.protocol` property on the client side web socket to the
5
+ * value provided here, which should be one of the strings specified in the
6
+ * `protocols` parameter when requesting the web socket. This is intended
7
+ * for clients and servers to specify sub-protocols to use to communicate to
8
+ * each other.
9
+ */
10
+ protocol?: string;
11
+ /**
12
+ * If the client does not respond to this frame with a
13
+ * `pong` within the timeout specified, the connection is deemed
14
+ * unhealthy and is closed. The `close` and `error` event will be emitted.
15
+ *
16
+ * The unit is seconds, with a default of 30.
17
+ * Set to `0` to disable timeouts.
18
+ */
19
+ idleTimeout?: number;
20
+ }
21
+ export declare const upgradeWebSocket: UpgradeWebSocket<UpgradeWebSocketOptions>;
@@ -22,11 +22,11 @@ export type NetAddrInfo = {
22
22
  addressType: AddressType;
23
23
  } | {});
24
24
  /**
25
- * HTTP Connection infomation
25
+ * HTTP Connection information
26
26
  */
27
27
  export interface ConnInfo {
28
28
  /**
29
- * Remote infomation
29
+ * Remote information
30
30
  */
31
31
  remote: NetAddrInfo;
32
32
  }
@@ -16,7 +16,7 @@ export interface WSEvents {
16
16
  /**
17
17
  * Upgrade WebSocket Type
18
18
  */
19
- export type UpgradeWebSocket = (createEvents: (c: Context) => WSEvents | Promise<WSEvents>) => MiddlewareHandler<any, string, {
19
+ export type UpgradeWebSocket<T = any> = (createEvents: (c: Context) => WSEvents | Promise<WSEvents>, options?: T) => MiddlewareHandler<any, string, {
20
20
  outputFormat: 'ws';
21
21
  }>;
22
22
  export type WSReadyState = 0 | 1 | 2 | 3;
@@ -87,7 +87,7 @@ declare class Hono<E extends Env = Env, S extends Schema = {}, BasePath extends
87
87
  *
88
88
  * @param {string} path - base Path
89
89
  * @param {Hono} app - other Hono instance
90
- * @returns {Hono} routed Hono instnace
90
+ * @returns {Hono} routed Hono instance
91
91
  *
92
92
  * @example
93
93
  * ```ts
@@ -188,7 +188,7 @@ declare class Hono<E extends Env = Env, S extends Schema = {}, BasePath extends
188
188
  *
189
189
  * @see {@link https://hono.dev/api/hono#fetch}
190
190
  *
191
- * @param {Request} request - reuqest Object of request
191
+ * @param {Request} request - request Object of request
192
192
  * @param {Env} Env - env Object
193
193
  * @param {ExecutionContext} - context of execution
194
194
  * @returns {Response | Promise<Response>} response of request
@@ -21,8 +21,7 @@ var timingSafeEqual = async (a, b, hashFunction) => {
21
21
  if (!hashFunction) {
22
22
  hashFunction = sha256;
23
23
  }
24
- const sa = await hashFunction(a);
25
- const sb = await hashFunction(b);
24
+ const [sa, sb] = await Promise.all([hashFunction(a), hashFunction(b)]);
26
25
  if (!sa || !sb) {
27
26
  return false;
28
27
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hono",
3
- "version": "4.4.7",
3
+ "version": "4.4.8",
4
4
  "description": "Ultrafast web framework for the Edges",
5
5
  "main": "dist/cjs/index.js",
6
6
  "type": "module",