Skip to content

lukevp/compression

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

compression

nest badge GitHub Workflow Status Codecov

Deno HTTP compression middleware.

Features

  • gzip, deflate and brotli support
  • Detects supported encodings with Accept-Encoding header
  • Respects encodings order (depending on Accept-Encoding value)
  • Creates a Content-Encoding header with applied compression
  • Send 409 Not Acceptable if encoding is not supported

Example

import { compression } from 'https://deno.land/x/compression/mod.ts'
import { Server } from 'https://deno.land/std@0.107.0/http/server.ts'

const s = new Server({
  handler: async (req) => {
    return await compression({
      path: 'README.md',
      compression: ['br', 'gzip', 'deflate']
    })(req)
  },
  addr: ':3000'
})

s.listenAndServe()

Now try to send a HEAD request with curl:

$ curl localhost:3000 --head -H "Accept-Encoding: br, gzip, deflate" --compressed
HTTP/1.1 200 OK
content-length: 550
content-encoding: br, gzip, deflate

About

🗜️ Deno HTTP compression middleware

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 100.0%