Module: Bitfab::Compress
- Defined in:
- lib/bitfab/compress.rb
Overview
Request body compression for Bitfab API requests.
Constant Summary collapse
- DISABLE_COMPRESSION_ENV =
"BITFAB_DISABLE_COMPRESSION"- MIN_COMPRESSED_BYTES =
Below this, compressing costs more than the saved bytes are worth, so small requests (function lookups, replay status polls, single-span batches) ride uncompressed.
8_192
Class Method Summary collapse
-
.encode_request_body(body) ⇒ Object
Returns the body to send and the Content-Encoding it carries, or nil when the body is sent as-is.
Class Method Details
.encode_request_body(body) ⇒ Object
Returns the body to send and the Content-Encoding it carries, or nil when the body is sent as-is. Compression is best-effort: any failure sends the original body rather than dropping the span.
20 21 22 23 24 25 26 27 |
# File 'lib/bitfab/compress.rb', line 20 def encode_request_body(body) return [body, nil] if ENV[DISABLE_COMPRESSION_ENV] return [body, nil] if body.bytesize < MIN_COMPRESSED_BYTES [Zlib.gzip(body), "gzip"] rescue [body, nil] end |