1- // import { compress as brotli } from 'https://deno.land/x/[email protected] /mod.ts'1+ import { compress as brotli } from 'https://deno.land/x/[email protected] /mod.ts' 22import { gzip , deflate } from 'https://deno.land/x/[email protected] /mod.ts' 33import { ServerRequest } from 'https://deno.land/[email protected] /http/server.ts' 44import { Accepts } from 'https://deno.land/x/[email protected] /mod.ts' 5+ import { readAll } from 'https://deno.land/[email protected] /io/util.ts' 56
67const funcs = {
7- // br: brotli,
8+ br : brotli ,
89 gzip : ( body : Uint8Array ) => gzip ( body , undefined ) ,
910 deflate : ( body : Uint8Array ) => deflate ( body , undefined )
1011}
1112
1213/**
1314 * Supported compression algorithms
1415 */
15- type Compression = 'gzip' | /* 'br' | */ 'deflate'
16+ type Compression = 'gzip' | 'br' | 'deflate'
1617
1718export type CompressionOptions = {
1819 /**
@@ -51,7 +52,7 @@ export const compression = (opts: CompressionOptions) => async (req: ServerReque
5152
5253 const encodings = accepts . encodings ( )
5354
54- const buf = await Deno . readAll ( await Deno . open ( opts . path ) )
55+ const buf = await readAll ( await Deno . open ( opts . path ) )
5556
5657 if ( ! acceptHeader || acceptHeader === 'identity' || ( Array . isArray ( encodings ) && encodings [ 0 ] === 'identity' ) ) {
5758 return await req . respond ( {
@@ -77,7 +78,10 @@ export const compression = (opts: CompressionOptions) => async (req: ServerReque
7778 if ( Array . isArray ( encodings ) ) {
7879 let compressed : Uint8Array = buf
7980 let encs : string [ ] = [ ]
80- for ( const enc of encodings . filter ( ( x ) => x !== 'identity' ) ) {
81+
82+ for ( let enc of encodings . filter ( ( x ) => x !== 'identity' ) ) {
83+ if ( enc === 'brotli' ) enc = 'br'
84+
8185 if ( Object . keys ( funcs ) . includes ( enc as string ) ) {
8286 compressed = funcs [ enc as Compression ] ( compressed )
8387 encs . push ( enc )
0 commit comments