From 25a109d9ea27ad3a76fdce14bba283e953af9bce Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Fri, 19 Aug 2022 15:54:54 +0530 Subject: chore(bench): add flash router benchmarks (#15495) --- .../npm/hono/dist/middleware/compress/index.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 cli/bench/testdata/npm/hono/dist/middleware/compress/index.js (limited to 'cli/bench/testdata/npm/hono/dist/middleware/compress/index.js') diff --git a/cli/bench/testdata/npm/hono/dist/middleware/compress/index.js b/cli/bench/testdata/npm/hono/dist/middleware/compress/index.js new file mode 100644 index 000000000..fd605cf71 --- /dev/null +++ b/cli/bench/testdata/npm/hono/dist/middleware/compress/index.js @@ -0,0 +1,19 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.compress = void 0; +const compress = (options) => { + return async (ctx, next) => { + await next(); + const accepted = ctx.req.headers.get('Accept-Encoding'); + const pattern = options?.encoding ?? /gzip|deflate/; + const match = accepted?.match(pattern); + if (!accepted || !match || !ctx.res.body) { + return; + } + const encoding = match[0]; + const stream = new CompressionStream(encoding); + ctx.res = new Response(ctx.res.body.pipeThrough(stream), ctx.res.clone()); + ctx.res.headers.set('Content-Encoding', encoding); + }; +}; +exports.compress = compress; -- cgit v1.2.3