ItzNotABug / appexpress

An express.js like framework for Appwrite Functions, enabling super-easy navigation!
Apache License 2.0
39 stars 4 forks source link

Feat: Add HTTP Compression #17

Closed ItzNotABug closed 4 months ago

ItzNotABug commented 4 months ago

This PR adds support for HTTP Compression for faster data transfer! There are 3 default compressions used which are provided by the zlib i.e. br, gzip, deflate in the same order for perf.

Additionally, a user can also provide a custom compression handler if the client supports it. Example -

import zstd from '@mongodb-js/zstd';

express.compression({
  encodings: new Set(['zstd']),
  compress: async (buffer) =>  await zstd.compress(buffer, 9);  // don't go over 20!
});

Supported compressible content types -

const contentTypePatterns = [
  /^text\/(html|css|plain|xml|x-component|javascript)$/i,
  /^application\/(x-javascript|javascript|json|manifest\+json|vnd\.api\+json|xml|xhtml\+xml|rss\+xml|atom\+xml|vnd\.ms-fontobject|x-font-ttf|x-font-opentype|x-font-truetype)$/i,
  /^image\/(svg\+xml|x-icon|vnd\.microsoft\.icon)$/i,
  /^font\/(ttf|eot|otf|opentype)$/i,
];