压缩中间件
此中间件根据 Accept-Encoding 请求头压缩响应体。
INFO
注意:在 Cloudflare Workers 和 Deno Deploy 上,响应体会被自动压缩,因此无需使用此中间件。
导入
ts
import { Hono } from 'hono'
import { compress } from 'hono/compress'用法
ts
const app = new Hono()
app.use(compress())选项
可选 encoding: 'gzip' | 'deflate'
允许用于响应压缩的压缩方案。可以是 gzip 或 deflate。如果未定义,则两者都允许,并将根据 Accept-Encoding 头使用。如果未提供此选项且客户端在 Accept-Encoding 头中同时提供了两者,则优先使用 gzip。
可选 threshold: number
要压缩的最小字节大小。默认为 1024 字节。