Compression

The compression plugin allows to reduce transferred data between client and server by enabling compression.

It also allows one to compress the body of requests.

By default it supports “gzip” and “deflate”, but one can optionally use “br” by installing the brotli gem (caveat: it can’t run in JRuby).

http = HTTPX.plugin(:compression)
http.get("https://www.google.com") #=> response with "content-type" as "gzip" or "deflate", response is decoded automatically

Compressing the request payload is a matter of just adding the content-encoding header with the desired compression (again, only supports the already mentioned ones):

http = HTTPX.plugin(:compression)
http.headers("content-encoding" => "gzip").post("https://filmupload.com", body: File.open("path/to/file"))

:compression_threshold_size

When set, it means: byte size threshold until which request payload won’t be compressed.

Sometimes, most of your payloads are so small that there is no gain in compressing (in some cases the resulting compressed payload size is higher), so you’d like to activate it only when you see fit.

Next: Server Push