Skip to content

Commit

Permalink
Compress Middleware (#2697)
Browse files Browse the repository at this point in the history
  • Loading branch information
goisaki authored May 18, 2024
1 parent 3d24a2c commit ffa2c03
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
16 changes: 16 additions & 0 deletions deno_dist/middleware/compress/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,22 @@ interface CompressionOptions {
encoding?: (typeof ENCODING_TYPES)[number]
}

/**
* Compress middleware for Hono.
*
* @see {@link https://hono.dev/middleware/builtin/compress}
*
* @param {CompressionOptions} [options] - The options for the compress middleware.
* @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.
* @returns {MiddlewareHandler} The middleware handler function.
*
* @example
* ```ts
* const app = new Hono()
*
* app.use(compress())
* ```
*/
export const compress = (options?: CompressionOptions): MiddlewareHandler => {
return async function compress(ctx, next) {
await next()
Expand Down
16 changes: 16 additions & 0 deletions src/middleware/compress/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,22 @@ interface CompressionOptions {
encoding?: (typeof ENCODING_TYPES)[number]
}

/**
* Compress middleware for Hono.
*
* @see {@link https://hono.dev/middleware/builtin/compress}
*
* @param {CompressionOptions} [options] - The options for the compress middleware.
* @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.
* @returns {MiddlewareHandler} The middleware handler function.
*
* @example
* ```ts
* const app = new Hono()
*
* app.use(compress())
* ```
*/
export const compress = (options?: CompressionOptions): MiddlewareHandler => {
return async function compress(ctx, next) {
await next()
Expand Down

0 comments on commit ffa2c03

Please sign in to comment.