diff --git a/docs/graphql/manual/deployment/compression.rst b/docs/graphql/manual/deployment/compression.rst index 93ef7da5808a0a..787c077ce1f841 100644 --- a/docs/graphql/manual/deployment/compression.rst +++ b/docs/graphql/manual/deployment/compression.rst @@ -8,9 +8,7 @@ HTTP Compression The Hasura GraphQL Engine supports HTTP compression. The server looks for the ``Accept-Encoding`` header in request. -If the header contains ``br`` then the server uses `Brotli `__ compression else if the header contains -``gzip`` then the server uses `Gzip `__ compression. -If both values are present then the server prefers ``Brotli`` over ``Gzip``. -Also, the server sets the ``Content-Encoding`` response header value to ``br`` for ``Brotli`` compression or ``gzip`` for ``Gzip`` compression. +If the header contains ``gzip`` then the server uses `Gzip `__ compression. +Also, the server sets the ``Content-Encoding`` response header value to ``gzip``. **Only responses from "/v1/query" and "/v1/graphql" endpoints are compressed.** diff --git a/server/graphql-engine.cabal b/server/graphql-engine.cabal index f4cdd5c8a957ae..17121b8ebc7d5a 100644 --- a/server/graphql-engine.cabal +++ b/server/graphql-engine.cabal @@ -148,7 +148,6 @@ library -- HTTP compression , zlib - , brotli exposed-modules: Hasura.Prelude , Hasura.Logging diff --git a/server/src-lib/Hasura/Server/Compression.hs b/server/src-lib/Hasura/Server/Compression.hs index d35a91ba8bb106..8c3dcd31753c61 100644 --- a/server/src-lib/Hasura/Server/Compression.hs +++ b/server/src-lib/Hasura/Server/Compression.hs @@ -7,9 +7,8 @@ where import Hasura.Prelude -import Hasura.Server.Utils (brHeader, gzipHeader) +import Hasura.Server.Utils (gzipHeader) -import qualified Codec.Compression.Brotli as BR import qualified Codec.Compression.GZip as GZ import qualified Data.ByteString.Lazy as BL import qualified Data.Text as T @@ -17,12 +16,10 @@ import qualified Network.HTTP.Types.Header as NH data CompressionType = CTGZip - | CTBrotli deriving (Show, Eq) compressionTypeToTxt :: CompressionType -> T.Text compressionTypeToTxt CTGZip = "gzip" -compressionTypeToTxt CTBrotli = "brotli" compressResponse :: NH.RequestHeaders @@ -31,14 +28,14 @@ compressResponse compressResponse reqHeaders unCompressedResp = let compressionTypeM = getRequestedCompression reqHeaders appendCompressionType (res, headerM) = (res, headerM, compressionTypeM) + gzipCompressionParams = + GZ.defaultCompressParams{GZ.compressLevel = GZ.compressionLevel 1} in appendCompressionType $ case compressionTypeM of - Just CTBrotli -> (BR.compress unCompressedResp, Just brHeader) - Just CTGZip -> (GZ.compress unCompressedResp, Just gzipHeader) - Nothing -> (unCompressedResp, Nothing) + Just CTGZip -> (GZ.compressWith gzipCompressionParams unCompressedResp, Just gzipHeader) + Nothing -> (unCompressedResp, Nothing) getRequestedCompression :: NH.RequestHeaders -> Maybe CompressionType getRequestedCompression reqHeaders - | "br" `elem` acceptEncodingVals = Just CTBrotli | "gzip" `elem` acceptEncodingVals = Just CTGZip | otherwise = Nothing where diff --git a/server/tests-py/test_compression.py b/server/tests-py/test_compression.py index 552b51432bbf68..8d8da452afd32b 100644 --- a/server/tests-py/test_compression.py +++ b/server/tests-py/test_compression.py @@ -63,27 +63,16 @@ def test_gzip_compression_v1_query(self, hge_ctx): resp = self._make_post(hge_ctx, url, q, self.gzip_header) self._assert_gzip(resp, exp_resp) - def test_brotli_compression_graphql(self, hge_ctx): - url, q, exp_resp = self._get_config(self.dir() + '/graphql_query.yaml') - resp = self._make_post(hge_ctx, url, q, self.brotli_header) - self._assert_brotli(resp, exp_resp) - - def test_brotli_compression_v1_query(self, hge_ctx): - url, q, exp_resp = self._get_config(self.dir() + '/v1_query.yaml') - resp = self._make_post(hge_ctx, url, q, self.brotli_header) - self._assert_brotli(resp, exp_resp) - - # If gzip and brotli encoding are requested the server prefers brotli def test_gzip_brotli_graphql_query(self, hge_ctx): url, q, exp_resp = self._get_config(self.dir() + '/graphql_query.yaml') resp = self._make_post(hge_ctx, url, q, self.gzip_brotli_header) - self._assert_brotli(resp, exp_resp) + self._assert_gzip(resp, exp_resp) def test_gzip_brotli_v1_query(self, hge_ctx): url, q, exp_resp = self._get_config(self.dir() + '/v1_query.yaml') resp = self._make_post(hge_ctx, url, q, self.gzip_brotli_header) - self._assert_brotli(resp, exp_resp) + self._assert_gzip(resp, exp_resp) @classmethod def dir(cls):