HTTP Compression
RustMailer supports built-in HTTP compression and decompression using the Poem web framework. This helps reduce bandwidth usage and improve API performance, especially for large JSON payloads or webhook traffic.
✅ Overview
RustMailer automatically selects compression and decompression algorithms based on HTTP headers:
- Request Decompression: If the request contains a
Content-Encoding
header, RustMailer will decompress it accordingly. - Response Compression: If the request includes an
Accept-Encoding
header, RustMailer will choose the best supported compression algorithm.
🛠️ How to Enable
You can enable HTTP compression via command-line argument or environment variable:
Command-line Argument | Environment Variable | Default | Description |
---|---|---|---|
--rustmailer-http-compression-enabled | RUSTMAILER_HTTP_COMPRESSION_ENABLED | false | Enables HTTP compression and decoding |
Example: Enable via Command Line
./rustmailer --rustmailer-http-compression-enabled
Example: Enable via Environment Variable
export RUSTMAILER_HTTP_COMPRESSION_ENABLED=true
./rustmailer
🔄 Supported Compression Algorithms
RustMailer supports the following compression types:
gzip
deflate
br
(Brotli)zstd
*
(wildcard - auto-select best available)
Sample Headers
Accept-Encoding: br, gzip, deflate
Content-Encoding: gzip
💡 Use Cases
- High-throughput webhook traffic
- Mobile or bandwidth-constrained environments
- Large JSON API responses
- Uploading IMAP sync data efficiently
🧬 gRPC Compression
RustMailer also supports gRPC compression, which is configured differently from HTTP compression.
Unlike HTTP compression, where the algorithm is negotiated via headers, gRPC compression requires explicitly specifying the compression algorithm.
🧩 Configuration
Use either a command-line argument or environment variable:
Command-line Argument | Environment Variable | Default | Description |
---|---|---|---|
--rustmailer-grpc-compression | RUSTMAILER_GRPC_COMPRESSION | none | Sets gRPC compression algorithm (see below) |
🔧 Supported gRPC Compression Algorithms
You must specify one of the following compression algorithms:
none
gzip
brotli
zstd
deflate
⚙️ Example
./rustmailer --rustmailer-grpc-compression=gzip
# or
export RUSTMAILER_GRPC_COMPRESSION=gzip
./rustmailer
🔁 Client Configuration
RustMailer will apply the selected algorithm for both:
send_compressed(...)
(outbound gRPC responses)accept_compressed(...)
(inbound gRPC requests)
The gRPC client must know which compression algorithm is configured on the server, and must set both send_compressed
and accept_compressed
accordingly.
Mismatched compression settings may lead to connection errors or failed decoding.
For example, when using a gRPC client library (e.g., tonic
), configure compression to match:
use tonic::transport::Channel;
let channel = Channel::from_static("http://localhost:16630")
.connect()
.await?
.send_compressed(tonic::codec::CompressionEncoding::Gzip)
.accept_compressed(tonic::codec::CompressionEncoding::Gzip);