Comparing version 4.5.9 to 4.5.10
@@ -25,5 +25,12 @@ "use strict"; | ||
const ENCODING_TYPES = ["gzip", "deflate"]; | ||
const cacheControlNoTransformRegExp = /(?:^|,)\s*?no-transform\s*?(?:,|$)/i; | ||
const compressibleContentTypeRegExp = /^\s*(?:text\/[^;\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 compress = (options) => { | ||
const threshold = options?.threshold ?? 1024; | ||
return async function compress2(ctx, next) { | ||
await next(); | ||
const contentLength = ctx.res.headers.get("Content-Length"); | ||
if (ctx.res.headers.has("Content-Encoding") || ctx.req.method === "HEAD" || contentLength && Number(contentLength) < threshold || !shouldCompress(ctx.res) || !shouldTransform(ctx.res)) { | ||
return; | ||
} | ||
const accepted = ctx.req.header("Accept-Encoding"); | ||
@@ -40,2 +47,10 @@ const encoding = options?.encoding ?? ENCODING_TYPES.find((encoding2) => accepted?.includes(encoding2)); | ||
}; | ||
const shouldCompress = (res) => { | ||
const type = res.headers.get("Content-Type"); | ||
return type && compressibleContentTypeRegExp.test(type); | ||
}; | ||
const shouldTransform = (res) => { | ||
const cacheControl = res.headers.get("Cache-Control"); | ||
return !cacheControl || !cacheControlNoTransformRegExp.test(cacheControl); | ||
}; | ||
// Annotate the CommonJS export names for ESM import in node: | ||
@@ -42,0 +57,0 @@ 0 && (module.exports = { |
@@ -56,3 +56,3 @@ "use strict"; | ||
function log(fn, prefix, method, path, status = 0, elapsed) { | ||
const out = prefix === "<--" /* Incoming */ ? ` ${prefix} ${method} ${path}` : ` ${prefix} ${method} ${path} ${colorStatus(status)} ${elapsed}`; | ||
const out = prefix === "<--" /* Incoming */ ? `${prefix} ${method} ${path}` : `${prefix} ${method} ${path} ${colorStatus(status)} ${elapsed}`; | ||
fn(out); | ||
@@ -59,0 +59,0 @@ } |
// src/middleware/compress/index.ts | ||
var ENCODING_TYPES = ["gzip", "deflate"]; | ||
var cacheControlNoTransformRegExp = /(?:^|,)\s*?no-transform\s*?(?:,|$)/i; | ||
var compressibleContentTypeRegExp = /^\s*(?:text\/[^;\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 compress = (options) => { | ||
const threshold = options?.threshold ?? 1024; | ||
return async function compress2(ctx, next) { | ||
await next(); | ||
const contentLength = ctx.res.headers.get("Content-Length"); | ||
if (ctx.res.headers.has("Content-Encoding") || ctx.req.method === "HEAD" || contentLength && Number(contentLength) < threshold || !shouldCompress(ctx.res) || !shouldTransform(ctx.res)) { | ||
return; | ||
} | ||
const accepted = ctx.req.header("Accept-Encoding"); | ||
@@ -17,4 +24,12 @@ const encoding = options?.encoding ?? ENCODING_TYPES.find((encoding2) => accepted?.includes(encoding2)); | ||
}; | ||
var shouldCompress = (res) => { | ||
const type = res.headers.get("Content-Type"); | ||
return type && compressibleContentTypeRegExp.test(type); | ||
}; | ||
var shouldTransform = (res) => { | ||
const cacheControl = res.headers.get("Cache-Control"); | ||
return !cacheControl || !cacheControlNoTransformRegExp.test(cacheControl); | ||
}; | ||
export { | ||
compress | ||
}; |
@@ -28,3 +28,3 @@ // src/middleware/logger/index.ts | ||
function log(fn, prefix, method, path, status = 0, elapsed) { | ||
const out = prefix === "<--" /* Incoming */ ? ` ${prefix} ${method} ${path}` : ` ${prefix} ${method} ${path} ${colorStatus(status)} ${elapsed}`; | ||
const out = prefix === "<--" /* Incoming */ ? `${prefix} ${method} ${path}` : `${prefix} ${method} ${path} ${colorStatus(status)} ${elapsed}`; | ||
fn(out); | ||
@@ -31,0 +31,0 @@ } |
@@ -169,3 +169,4 @@ import type { BaseMime } from '../utils/mime'; | ||
placeholder?: string | undefined; | ||
popover?: string | undefined; | ||
/** @see https://developer.mozilla.org/en-US/docs/Web/API/Popover_API */ | ||
popover?: boolean | 'auto' | 'manual' | undefined; | ||
slot?: string | undefined; | ||
@@ -211,7 +212,9 @@ spellcheck?: boolean | undefined; | ||
} | ||
/** @see https://developer.mozilla.org/en-US/docs/Web/API/Popover_API */ | ||
type HTMLAttributePopoverTargetAction = 'show' | 'hide' | 'toggle'; | ||
interface ButtonHTMLAttributes extends HTMLAttributes { | ||
disabled?: boolean | undefined; | ||
form?: string | undefined; | ||
formenctype?: string | undefined; | ||
formmethod?: string | undefined; | ||
formenctype?: HTMLAttributeFormEnctype | undefined; | ||
formmethod?: HTMLAttributeFormMethod | undefined; | ||
formnovalidate?: boolean | undefined; | ||
@@ -222,2 +225,4 @@ formtarget?: HTMLAttributeAnchorTarget | undefined; | ||
value?: string | ReadonlyArray<string> | number | undefined; | ||
popovertarget?: string | undefined; | ||
popovertargetaction?: HTMLAttributePopoverTargetAction | undefined; | ||
formAction?: string | Function | undefined; | ||
@@ -260,7 +265,13 @@ } | ||
} | ||
/** @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form#method */ | ||
type HTMLAttributeFormMethod = 'get' | 'post' | 'dialog'; | ||
/** @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form#enctype */ | ||
type HTMLAttributeFormEnctype = 'application/x-www-form-urlencoded' | 'multipart/form-data' | 'text/plain'; | ||
/** @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form#autocomplete */ | ||
type HTMLAttributeFormAutocomplete = 'on' | 'off'; | ||
interface FormHTMLAttributes extends HTMLAttributes { | ||
'accept-charset'?: string | undefined; | ||
autocomplete?: string | undefined; | ||
enctype?: string | undefined; | ||
method?: string | undefined; | ||
'accept-charset'?: StringLiteralUnion<'utf-8'> | undefined; | ||
autocomplete?: HTMLAttributeFormAutocomplete | undefined; | ||
enctype?: HTMLAttributeFormEnctype | undefined; | ||
method?: HTMLAttributeFormMethod | undefined; | ||
name?: string | undefined; | ||
@@ -324,4 +335,4 @@ novalidate?: boolean | undefined; | ||
form?: string | undefined; | ||
formenctype?: string | undefined; | ||
formmethod?: string | undefined; | ||
formenctype?: HTMLAttributeFormEnctype | undefined; | ||
formmethod?: HTMLAttributeFormMethod | undefined; | ||
formnovalidate?: boolean | undefined; | ||
@@ -347,2 +358,4 @@ formtarget?: HTMLAttributeAnchorTarget | undefined; | ||
width?: number | string | undefined; | ||
popovertarget?: string | undefined; | ||
popovertargetaction?: HTMLAttributePopoverTargetAction | undefined; | ||
formAction?: string | Function | undefined; | ||
@@ -349,0 +362,0 @@ } |
@@ -9,2 +9,3 @@ /** | ||
encoding?: (typeof ENCODING_TYPES)[number]; | ||
threshold?: number; | ||
} | ||
@@ -18,2 +19,3 @@ /** | ||
* @param {'gzip' | 'deflate'} [options.encoding] - The compression scheme to allow for response compression. Either 'gzip' or 'deflate'. If not defined, both are allowed and will be used based on the Accept-Encoding header. 'gzip' is prioritized if this option is not provided and the client provides both in the Accept-Encoding header. | ||
* @param {number} [options.threshold=1024] - The minimum size in bytes to compress. Defaults to 1024 bytes. | ||
* @returns {MiddlewareHandler} The middleware handler function. | ||
@@ -20,0 +22,0 @@ * |
{ | ||
"name": "hono", | ||
"version": "4.5.9", | ||
"version": "4.5.10", | ||
"description": "Web framework built on Web Standards", | ||
@@ -620,3 +620,3 @@ "main": "dist/cjs/index.js", | ||
"@types/supertest": "^2.0.12", | ||
"@vitest/coverage-v8": "^1.1.0", | ||
"@vitest/coverage-v8": "^2.0.5", | ||
"arg": "^5.0.2", | ||
@@ -635,3 +635,3 @@ "crypto-js": "^4.1.1", | ||
"vite-plugin-fastly-js-compute": "^0.4.2", | ||
"vitest": "^1.2.2", | ||
"vitest": "^2.0.5", | ||
"wrangler": "^3.58.0", | ||
@@ -638,0 +638,0 @@ "ws": "^8.17.0", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1016096
28749