Skip to main content
Deno 2 is finally here 🎉️
Learn more

http-compress

deno land deno doc GitHub release (latest by date) GitHub

test NPM

Compress HTTP response, supported Web standard compression methods

Packages

The package supports multiple platforms.

  • deno.land/x - https://deno.land/x/http_compress/mod.ts
  • npm - @httpland/http-compress

Compress with handler

Takes a handler and returns a handler with the response body compressed.

import { withCompress } from "https://deno.land/x/http_compress@$VERSION/mod.ts";

function handler(req: Request): Response {
  return new Response("Huge content");
}
Deno.serve(withCompress(handler));

Spec

Create a new Response object with the compressed value of the response body.

No destructive changes are made to the original Response object.

For the Response header, the following fields may be added:

  • Content-Encoding
  • Vary

Definition of Terms

  • Handler - It is a function that takes a Request object as its first argument and returns a Response or Promise<Response> object.

    type Handler = (request: Request) => Promise<Response> | Response;

License

Copyright © 2022-present httpland.

Released under the MIT license