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.

http = HTTPX.plugin(:compression)
http.get("") #=> 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.with(headers: {"content-encoding" => "gzip"}).post("", body:"path/to/file"))

By default it supports “gzip” and “deflate”.


brotli compression can be activated by installing the brotli gem (caveat: it can’t run in JRuby) and loading the :compression/brotli plugin separately.

http = HTTPX.plugin(:"compression/brotli")
http.get("") #=> sends "Accept-Encoding: br, gzip, deflate" header

http = HTTPX.plugin(:"compression/brotli")
http.with(headers: {"content-encoding" => "br"}).post("", body:"path/to/file"))


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