Awesome
<div align="center">http_compression
</div>Deno HTTP compression middleware.
Features
gzip
,deflate
andbrotli
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