@@ -7,3 +7,7 @@ // src/adapter/deno/websocket.ts | ||
| } | ||
| const { response, socket } = Deno.upgradeWebSocket(c.req.raw, options ?? {}); | ||
| const subprotocol = c.req.header("sec-websocket-protocol")?.split(",")[0]?.trim(); | ||
| const { response, socket } = Deno.upgradeWebSocket(c.req.raw, { | ||
| ...subprotocol ? { protocol: subprotocol } : {}, | ||
| ...options | ||
| }); | ||
| const wsContext = new WSContext({ | ||
@@ -10,0 +14,0 @@ close: (code, reason) => socket.close(code, reason), |
@@ -28,3 +28,7 @@ var __defProp = Object.defineProperty; | ||
| } | ||
| const { response, socket } = Deno.upgradeWebSocket(c.req.raw, options ?? {}); | ||
| const subprotocol = c.req.header("sec-websocket-protocol")?.split(",")[0]?.trim(); | ||
| const { response, socket } = Deno.upgradeWebSocket(c.req.raw, { | ||
| ...subprotocol ? { protocol: subprotocol } : {}, | ||
| ...options | ||
| }); | ||
| const wsContext = new import_websocket.WSContext({ | ||
@@ -31,0 +35,0 @@ close: (code, reason) => socket.close(code, reason), |
@@ -23,7 +23,27 @@ var __defProp = Object.defineProperty; | ||
| module.exports = __toCommonJS(compress_exports); | ||
| var import_accept = require("../../utils/accept"); | ||
| var import_compress = require("../../utils/compress"); | ||
| const ENCODING_TYPES = ["gzip", "deflate"]; | ||
| const cacheControlNoTransformRegExp = /(?:^|,)\s*?no-transform\s*?(?:,|$)/i; | ||
| const selectEncoding = (header, candidates) => { | ||
| if (header === void 0) { | ||
| return void 0; | ||
| } | ||
| const accepts = (0, import_accept.parseAccept)(header); | ||
| const wildcardQ = accepts.find((a) => a.type === "*")?.q; | ||
| let best; | ||
| for (const enc of candidates) { | ||
| const explicit = accepts.find((a) => a.type.toLowerCase() === enc); | ||
| const q = explicit ? explicit.q : wildcardQ ?? 0; | ||
| if (q === 1) { | ||
| return enc; | ||
| } else if (q > 0 && (!best || q > best.q)) { | ||
| best = { encoding: enc, q }; | ||
| } | ||
| } | ||
| return best?.encoding; | ||
| }; | ||
| const compress = (options) => { | ||
| const threshold = options?.threshold ?? 1024; | ||
| const candidates = options?.encoding ? [options.encoding] : ENCODING_TYPES; | ||
| return async function compress2(ctx, next) { | ||
@@ -41,3 +61,3 @@ await next(); | ||
| const accepted = ctx.req.header("Accept-Encoding"); | ||
| const encoding = options?.encoding ?? ENCODING_TYPES.find((encoding2) => accepted?.includes(encoding2)); | ||
| const encoding = selectEncoding(accepted, candidates); | ||
| if (!encoding || !ctx.res.body) { | ||
@@ -44,0 +64,0 @@ return; |
@@ -23,3 +23,3 @@ var __defProp = Object.defineProperty; | ||
| module.exports = __toCommonJS(compress_exports); | ||
| const COMPRESSIBLE_CONTENT_TYPE_REGEX = /^\s*(?:text\/(?!event-stream(?:[;\s]|$))[^;\s]+|application\/(?:javascript|json|xml|xml-dtd|ecmascript|dart|postscript|rtf|tar|toml|vnd\.dart|vnd\.ms-fontobject|vnd\.ms-opentype|wasm|x-httpd-php|x-javascript|x-ns-proxy-autoconfig|x-sh|x-tar|x-virtualbox-hdd|x-virtualbox-ova|x-virtualbox-ovf|x-virtualbox-vbox|x-virtualbox-vdi|x-virtualbox-vhd|x-virtualbox-vmdk|x-www-form-urlencoded)|font\/(?:otf|ttf)|image\/(?:bmp|vnd\.adobe\.photoshop|vnd\.microsoft\.icon|vnd\.ms-dds|x-icon|x-ms-bmp)|message\/rfc822|model\/gltf-binary|x-shader\/x-fragment|x-shader\/x-vertex|[^;\s]+?\+(?:json|text|xml|yaml))(?:[;\s]|$)/i; | ||
| const COMPRESSIBLE_CONTENT_TYPE_REGEX = /^\s*(?:text\/(?!event-stream(?:[;\s]|$))[^;\s]+|application\/(?:javascript|json|xml|xml-dtd|ecmascript|dart|msgpack|postscript|rtf|tar|toml|vnd\.dart|vnd\.ms-fontobject|vnd\.ms-opentype|vnd\.msgpack|wasm|x-httpd-php|x-javascript|x-msgpack|x-ns-proxy-autoconfig|x-sh|x-tar|x-virtualbox-hdd|x-virtualbox-ova|x-virtualbox-ovf|x-virtualbox-vbox|x-virtualbox-vdi|x-virtualbox-vhd|x-virtualbox-vmdk|x-www-form-urlencoded)|font\/(?:otf|ttf)|image\/(?:bmp|vnd\.adobe\.photoshop|vnd\.microsoft\.icon|vnd\.ms-dds|x-icon|x-ms-bmp)|message\/rfc822|model\/gltf-binary|x-shader\/x-fragment|x-shader\/x-vertex|[^;\s]+?\+(?:json|text|xml|yaml|msgpack))(?:[;\s]|$)/i; | ||
| // Annotate the CommonJS export names for ESM import in node: | ||
@@ -26,0 +26,0 @@ 0 && (module.exports = { |
+15
-17
@@ -31,11 +31,9 @@ var __defProp = Object.defineProperty; | ||
| } | ||
| let mimeType = mimes[match[1].toLowerCase()]; | ||
| if (mimeType && mimeType.startsWith("text")) { | ||
| mimeType += "; charset=utf-8"; | ||
| } | ||
| return mimeType; | ||
| return mimes[match[1].toLowerCase()]; | ||
| }; | ||
| const getExtension = (mimeType) => { | ||
| const baseType = mimeType.split(";", 1)[0].trim(); | ||
| for (const ext in baseMimes) { | ||
| if (baseMimes[ext] === mimeType) { | ||
| const stored = baseMimes[ext]; | ||
| if (stored === mimeType || stored.split(";", 1)[0].trim() === baseType) { | ||
| return ext; | ||
@@ -52,4 +50,4 @@ } | ||
| bmp: "image/bmp", | ||
| css: "text/css", | ||
| csv: "text/csv", | ||
| css: "text/css; charset=utf-8", | ||
| csv: "text/csv; charset=utf-8", | ||
| eot: "application/vnd.ms-fontobject", | ||
@@ -59,9 +57,9 @@ epub: "application/epub+zip", | ||
| gz: "application/gzip", | ||
| htm: "text/html", | ||
| html: "text/html", | ||
| htm: "text/html; charset=utf-8", | ||
| html: "text/html; charset=utf-8", | ||
| ico: "image/x-icon", | ||
| ics: "text/calendar", | ||
| ics: "text/calendar; charset=utf-8", | ||
| jpeg: "image/jpeg", | ||
| jpg: "image/jpeg", | ||
| js: "text/javascript", | ||
| js: "text/javascript; charset=utf-8", | ||
| json: "application/json", | ||
@@ -72,3 +70,3 @@ jsonld: "application/ld+json", | ||
| midi: "audio/x-midi", | ||
| mjs: "text/javascript", | ||
| mjs: "text/javascript; charset=utf-8", | ||
| mp3: "audio/mpeg", | ||
@@ -85,3 +83,3 @@ mp4: "video/mp4", | ||
| rtf: "application/rtf", | ||
| svg: "image/svg+xml", | ||
| svg: "image/svg+xml; charset=utf-8", | ||
| tif: "image/tiff", | ||
@@ -91,3 +89,3 @@ tiff: "image/tiff", | ||
| ttf: "font/ttf", | ||
| txt: "text/plain", | ||
| txt: "text/plain; charset=utf-8", | ||
| wasm: "application/wasm", | ||
@@ -100,4 +98,4 @@ webm: "video/webm", | ||
| woff2: "font/woff2", | ||
| xhtml: "application/xhtml+xml", | ||
| xml: "application/xml", | ||
| xhtml: "application/xhtml+xml; charset=utf-8", | ||
| xml: "application/xml; charset=utf-8", | ||
| zip: "application/zip", | ||
@@ -104,0 +102,0 @@ "3gp": "video/3gpp", |
| // src/middleware/compress/index.ts | ||
| import { parseAccept } from "../../utils/accept.js"; | ||
| import { COMPRESSIBLE_CONTENT_TYPE_REGEX } from "../../utils/compress.js"; | ||
| var ENCODING_TYPES = ["gzip", "deflate"]; | ||
| var cacheControlNoTransformRegExp = /(?:^|,)\s*?no-transform\s*?(?:,|$)/i; | ||
| var selectEncoding = (header, candidates) => { | ||
| if (header === void 0) { | ||
| return void 0; | ||
| } | ||
| const accepts = parseAccept(header); | ||
| const wildcardQ = accepts.find((a) => a.type === "*")?.q; | ||
| let best; | ||
| for (const enc of candidates) { | ||
| const explicit = accepts.find((a) => a.type.toLowerCase() === enc); | ||
| const q = explicit ? explicit.q : wildcardQ ?? 0; | ||
| if (q === 1) { | ||
| return enc; | ||
| } else if (q > 0 && (!best || q > best.q)) { | ||
| best = { encoding: enc, q }; | ||
| } | ||
| } | ||
| return best?.encoding; | ||
| }; | ||
| var compress = (options) => { | ||
| const threshold = options?.threshold ?? 1024; | ||
| const candidates = options?.encoding ? [options.encoding] : ENCODING_TYPES; | ||
| return async function compress2(ctx, next) { | ||
@@ -19,3 +39,3 @@ await next(); | ||
| const accepted = ctx.req.header("Accept-Encoding"); | ||
| const encoding = options?.encoding ?? ENCODING_TYPES.find((encoding2) => accepted?.includes(encoding2)); | ||
| const encoding = selectEncoding(accepted, candidates); | ||
| if (!encoding || !ctx.res.body) { | ||
@@ -22,0 +42,0 @@ return; |
@@ -7,4 +7,5 @@ /** | ||
| declare const ENCODING_TYPES: readonly ["gzip", "deflate"]; | ||
| type Encoding = (typeof ENCODING_TYPES)[number]; | ||
| interface CompressionOptions { | ||
| encoding?: (typeof ENCODING_TYPES)[number]; | ||
| encoding?: Encoding; | ||
| threshold?: number; | ||
@@ -11,0 +12,0 @@ } |
@@ -19,4 +19,4 @@ /** | ||
| readonly bmp: "image/bmp"; | ||
| readonly css: "text/css"; | ||
| readonly csv: "text/csv"; | ||
| readonly css: "text/css; charset=utf-8"; | ||
| readonly csv: "text/csv; charset=utf-8"; | ||
| readonly eot: "application/vnd.ms-fontobject"; | ||
@@ -26,9 +26,9 @@ readonly epub: "application/epub+zip"; | ||
| readonly gz: "application/gzip"; | ||
| readonly htm: "text/html"; | ||
| readonly html: "text/html"; | ||
| readonly htm: "text/html; charset=utf-8"; | ||
| readonly html: "text/html; charset=utf-8"; | ||
| readonly ico: "image/x-icon"; | ||
| readonly ics: "text/calendar"; | ||
| readonly ics: "text/calendar; charset=utf-8"; | ||
| readonly jpeg: "image/jpeg"; | ||
| readonly jpg: "image/jpeg"; | ||
| readonly js: "text/javascript"; | ||
| readonly js: "text/javascript; charset=utf-8"; | ||
| readonly json: "application/json"; | ||
@@ -39,3 +39,3 @@ readonly jsonld: "application/ld+json"; | ||
| readonly midi: "audio/x-midi"; | ||
| readonly mjs: "text/javascript"; | ||
| readonly mjs: "text/javascript; charset=utf-8"; | ||
| readonly mp3: "audio/mpeg"; | ||
@@ -52,3 +52,3 @@ readonly mp4: "video/mp4"; | ||
| readonly rtf: "application/rtf"; | ||
| readonly svg: "image/svg+xml"; | ||
| readonly svg: "image/svg+xml; charset=utf-8"; | ||
| readonly tif: "image/tiff"; | ||
@@ -58,3 +58,3 @@ readonly tiff: "image/tiff"; | ||
| readonly ttf: "font/ttf"; | ||
| readonly txt: "text/plain"; | ||
| readonly txt: "text/plain; charset=utf-8"; | ||
| readonly wasm: "application/wasm"; | ||
@@ -67,4 +67,4 @@ readonly webm: "video/webm"; | ||
| readonly woff2: "font/woff2"; | ||
| readonly xhtml: "application/xhtml+xml"; | ||
| readonly xml: "application/xml"; | ||
| readonly xhtml: "application/xhtml+xml; charset=utf-8"; | ||
| readonly xml: "application/xml; charset=utf-8"; | ||
| readonly zip: "application/zip"; | ||
@@ -71,0 +71,0 @@ readonly '3gp': "video/3gpp"; |
| // src/utils/compress.ts | ||
| var COMPRESSIBLE_CONTENT_TYPE_REGEX = /^\s*(?:text\/(?!event-stream(?:[;\s]|$))[^;\s]+|application\/(?:javascript|json|xml|xml-dtd|ecmascript|dart|postscript|rtf|tar|toml|vnd\.dart|vnd\.ms-fontobject|vnd\.ms-opentype|wasm|x-httpd-php|x-javascript|x-ns-proxy-autoconfig|x-sh|x-tar|x-virtualbox-hdd|x-virtualbox-ova|x-virtualbox-ovf|x-virtualbox-vbox|x-virtualbox-vdi|x-virtualbox-vhd|x-virtualbox-vmdk|x-www-form-urlencoded)|font\/(?:otf|ttf)|image\/(?:bmp|vnd\.adobe\.photoshop|vnd\.microsoft\.icon|vnd\.ms-dds|x-icon|x-ms-bmp)|message\/rfc822|model\/gltf-binary|x-shader\/x-fragment|x-shader\/x-vertex|[^;\s]+?\+(?:json|text|xml|yaml))(?:[;\s]|$)/i; | ||
| var COMPRESSIBLE_CONTENT_TYPE_REGEX = /^\s*(?:text\/(?!event-stream(?:[;\s]|$))[^;\s]+|application\/(?:javascript|json|xml|xml-dtd|ecmascript|dart|msgpack|postscript|rtf|tar|toml|vnd\.dart|vnd\.ms-fontobject|vnd\.ms-opentype|vnd\.msgpack|wasm|x-httpd-php|x-javascript|x-msgpack|x-ns-proxy-autoconfig|x-sh|x-tar|x-virtualbox-hdd|x-virtualbox-ova|x-virtualbox-ovf|x-virtualbox-vbox|x-virtualbox-vdi|x-virtualbox-vhd|x-virtualbox-vmdk|x-www-form-urlencoded)|font\/(?:otf|ttf)|image\/(?:bmp|vnd\.adobe\.photoshop|vnd\.microsoft\.icon|vnd\.ms-dds|x-icon|x-ms-bmp)|message\/rfc822|model\/gltf-binary|x-shader\/x-fragment|x-shader\/x-vertex|[^;\s]+?\+(?:json|text|xml|yaml|msgpack))(?:[;\s]|$)/i; | ||
| export { | ||
| COMPRESSIBLE_CONTENT_TYPE_REGEX | ||
| }; |
+15
-17
@@ -8,11 +8,9 @@ // src/utils/mime.ts | ||
| } | ||
| let mimeType = mimes[match[1].toLowerCase()]; | ||
| if (mimeType && mimeType.startsWith("text")) { | ||
| mimeType += "; charset=utf-8"; | ||
| } | ||
| return mimeType; | ||
| return mimes[match[1].toLowerCase()]; | ||
| }; | ||
| var getExtension = (mimeType) => { | ||
| const baseType = mimeType.split(";", 1)[0].trim(); | ||
| for (const ext in baseMimes) { | ||
| if (baseMimes[ext] === mimeType) { | ||
| const stored = baseMimes[ext]; | ||
| if (stored === mimeType || stored.split(";", 1)[0].trim() === baseType) { | ||
| return ext; | ||
@@ -29,4 +27,4 @@ } | ||
| bmp: "image/bmp", | ||
| css: "text/css", | ||
| csv: "text/csv", | ||
| css: "text/css; charset=utf-8", | ||
| csv: "text/csv; charset=utf-8", | ||
| eot: "application/vnd.ms-fontobject", | ||
@@ -36,9 +34,9 @@ epub: "application/epub+zip", | ||
| gz: "application/gzip", | ||
| htm: "text/html", | ||
| html: "text/html", | ||
| htm: "text/html; charset=utf-8", | ||
| html: "text/html; charset=utf-8", | ||
| ico: "image/x-icon", | ||
| ics: "text/calendar", | ||
| ics: "text/calendar; charset=utf-8", | ||
| jpeg: "image/jpeg", | ||
| jpg: "image/jpeg", | ||
| js: "text/javascript", | ||
| js: "text/javascript; charset=utf-8", | ||
| json: "application/json", | ||
@@ -49,3 +47,3 @@ jsonld: "application/ld+json", | ||
| midi: "audio/x-midi", | ||
| mjs: "text/javascript", | ||
| mjs: "text/javascript; charset=utf-8", | ||
| mp3: "audio/mpeg", | ||
@@ -62,3 +60,3 @@ mp4: "video/mp4", | ||
| rtf: "application/rtf", | ||
| svg: "image/svg+xml", | ||
| svg: "image/svg+xml; charset=utf-8", | ||
| tif: "image/tiff", | ||
@@ -68,3 +66,3 @@ tiff: "image/tiff", | ||
| ttf: "font/ttf", | ||
| txt: "text/plain", | ||
| txt: "text/plain; charset=utf-8", | ||
| wasm: "application/wasm", | ||
@@ -77,4 +75,4 @@ webm: "video/webm", | ||
| woff2: "font/woff2", | ||
| xhtml: "application/xhtml+xml", | ||
| xml: "application/xml", | ||
| xhtml: "application/xhtml+xml; charset=utf-8", | ||
| xml: "application/xml; charset=utf-8", | ||
| zip: "application/zip", | ||
@@ -81,0 +79,0 @@ "3gp": "video/3gpp", |
+3
-3
| { | ||
| "name": "hono", | ||
| "version": "4.12.21", | ||
| "version": "4.12.22", | ||
| "description": "Web framework built on Web Standards", | ||
@@ -666,3 +666,3 @@ "main": "dist/cjs/index.js", | ||
| "@typescript/native-preview": "7.0.0-dev.20260210.1", | ||
| "@vitest/coverage-v8": "^3.2.4", | ||
| "@vitest/coverage-v8": "^4.1.7", | ||
| "arg": "^5.0.2", | ||
@@ -684,3 +684,3 @@ "bun-types": "^1.2.20", | ||
| "vite-plugin-fastly-js-compute": "^0.4.2", | ||
| "vitest": "^3.2.4", | ||
| "vitest": "^4.1.7", | ||
| "wrangler": "4.12.0", | ||
@@ -687,0 +687,0 @@ "ws": "^8.18.0", |
Sorry, the diff of this file is not supported yet
1414924
0.15%37214
0.12%