rustfs_config/constants/compress.rs
1// Copyright 2024 RustFS Team
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! HTTP Response Compression Configuration
16//!
17//! This module provides configuration options for HTTP response compression.
18//! By default, compression is disabled (aligned with MinIO behavior).
19//! When enabled via `RUSTFS_COMPRESS_ENABLE=on`, compression can be configured
20//! to apply only to specific file extensions, MIME types, and minimum file sizes.
21
22/// Environment variable to enable/disable HTTP response compression
23/// Default: off (disabled)
24/// Values: on, off, true, false, yes, no, 1, 0
25/// Example: RUSTFS_COMPRESS_ENABLE=on
26pub const ENV_COMPRESS_ENABLE: &str = "RUSTFS_COMPRESS_ENABLE";
27
28/// Default compression enable state
29/// Aligned with MinIO behavior - compression is disabled by default
30pub const DEFAULT_COMPRESS_ENABLE: bool = false;
31
32/// Environment variable for file extensions that should be compressed
33/// Comma-separated list of file extensions (with or without leading dot)
34/// Default: "" (empty, meaning use MIME type matching only)
35/// Example: RUSTFS_COMPRESS_EXTENSIONS=.txt,.log,.csv,.json,.xml,.html,.css,.js
36pub const ENV_COMPRESS_EXTENSIONS: &str = "RUSTFS_COMPRESS_EXTENSIONS";
37
38/// Default file extensions for compression
39/// Empty by default - relies on MIME type matching
40pub const DEFAULT_COMPRESS_EXTENSIONS: &str = "";
41
42/// Environment variable for MIME types that should be compressed
43/// Comma-separated list of MIME types, supports wildcard (*) for subtypes
44/// Default: "text/*,application/json,application/xml,application/javascript"
45/// Example: RUSTFS_COMPRESS_MIME_TYPES=text/*,application/json,application/xml
46pub const ENV_COMPRESS_MIME_TYPES: &str = "RUSTFS_COMPRESS_MIME_TYPES";
47
48/// Default MIME types for compression
49/// Includes common text-based content types that benefit from compression
50pub const DEFAULT_COMPRESS_MIME_TYPES: &str = "text/*,application/json,application/xml,application/javascript";
51
52/// Environment variable for minimum file size to apply compression
53/// Files smaller than this size will not be compressed
54/// Default: 1000 (bytes)
55/// Example: RUSTFS_COMPRESS_MIN_SIZE=1000
56pub const ENV_COMPRESS_MIN_SIZE: &str = "RUSTFS_COMPRESS_MIN_SIZE";
57
58/// Default minimum file size for compression (in bytes)
59/// Files smaller than 1000 bytes typically don't benefit from compression
60/// and the compression overhead may outweigh the benefits
61pub const DEFAULT_COMPRESS_MIN_SIZE: u64 = 1000;