NAME

Hypersonic::Compress - JIT-compiled gzip compression for Hypersonic

SYNOPSIS

use Hypersonic;

my $server = Hypersonic->new();

# Enable gzip compression
$server->compress(
    min_size => 1024,    # Minimum size to compress (bytes)
    level    => 6,       # Compression level (1-9)
);

$server->get('/api/data' => sub {
    my ($req) = @_;
    # Large JSON response will be gzip compressed
    return res->json({ data => [...large array...] });
}, { dynamic => 1 });

DESCRIPTION

Hypersonic::Compress provides JIT-compiled gzip compression using zlib. All compression happens in C for maximum performance.

How It Works

1. At compile time, zlib compression code is JIT-compiled into the server

2. For each response, the C code checks: - Does client send Accept-Encoding: gzip? - Is response body larger than min_size? - Is Content-Type compressible (text/*, application/json, etc.)?

3. If all conditions are met, the response is gzip compressed in C

4. Content-Encoding: gzip header is added automatically

Performance

Compression runs entirely in C using zlib, with no Perl overhead. Thread-local buffers avoid memory allocation for each request.

CONFIGURATION

min_size

Minimum response size to compress. Responses smaller than this are sent uncompressed. Default: 1024 bytes.

level

Compression level from 1 (fastest) to 9 (smallest). Default: 6 (good balance of speed and compression ratio).

types

Array of MIME types to compress. Default includes text/*, application/json, application/javascript, etc.

REQUIREMENTS

Requires zlib library to be installed:

# macOS
brew install zlib

# Ubuntu/Debian
apt-get install zlib1g-dev

# RHEL/CentOS
yum install zlib-devel

SEE ALSO

Hypersonic, Hypersonic::Response

AUTHOR

LNATION <email@lnation.org>

LICENSE

Same terms as Perl itself.