Skip to content

Commit 07a1c23

Browse files
committed
allow disabling http compression
compression can hinder http response streaming, and is unwanted when using a reverse proxy that does the compression itself. see #435
1 parent ca2eb6a commit 07a1c23

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

configuration.md

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Here are the available configuration options and their default values:
2424
| `allow_exec` | false | Allow usage of the `sqlpage.exec` function. Do this only if all users with write access to sqlpage query files and to the optional `sqlpage_files` table on the database are trusted. |
2525
| `max_uploaded_file_size` | 5242880 | Maximum size of uploaded files in bytes. Defaults to 5 MiB. |
2626
| `max_pending_rows` | 256 | Maximum number of rendered rows that can be queued up in memory when a client is slow to receive them. |
27+
| `compress_responses` | true | When the client supports it, compress the http response body. This can save bandwidth and speed up page loading on slow connections, but can also increase CPU usage and cause rendering delays on pages that take time to render (because streaming responses are buffered for longer than necessary). |
2728
| `https_domain` | | Domain name to request a certificate for. Setting this parameter will automatically make SQLPage listen on port 443 and request an SSL certificate. The server will take a little bit longer to start the first time it has to request a certificate. |
2829
| `https_certificate_email` | contact@<https_domain> | The email address to use when requesting a certificate. |
2930
| `https_certificate_cache_dir` | ./sqlpage/https | A writeable directory where to cache the certificates, so that SQLPage can serve https traffic immediately when it restarts. |

src/app_config.rs

+8
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ pub struct AppConfig {
9393
/// Maximum number of messages that can be stored in memory before sending them to the client.
9494
#[serde(default = "default_max_pending_rows")]
9595
pub max_pending_rows: usize,
96+
97+
/// Whether to compress the http response body when the client supports it.
98+
#[serde(default = "default_compress_responses")]
99+
pub compress_responses: bool,
96100
}
97101

98102
impl AppConfig {
@@ -302,6 +306,10 @@ fn default_max_pending_rows() -> usize {
302306
256
303307
}
304308

309+
fn default_compress_responses() -> bool {
310+
true
311+
}
312+
305313
#[derive(Debug, Deserialize, Serialize, PartialEq, Clone, Copy, Eq, Default)]
306314
#[serde(rename_all = "lowercase")]
307315
pub enum DevOrProd {

src/webserver/http.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,10 @@ pub fn create_app(
538538
"script-src 'self' https://cdn.jsdelivr.net",
539539
)),
540540
)
541-
.wrap(middleware::Compress::default())
541+
.wrap(middleware::Condition::new(
542+
app_state.config.compress_responses,
543+
middleware::Compress::default(),
544+
))
542545
.wrap(middleware::NormalizePath::new(
543546
middleware::TrailingSlash::MergeOnly,
544547
))

0 commit comments

Comments
 (0)