Skip to content

deno-libs/http_compression

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

63 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

http_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/http_compression/mod.ts'
import { Server } from 'https://deno.land/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