Skip to content

Commit

Permalink
allow disabling http compression
Browse files Browse the repository at this point in the history
compression can hinder http response streaming,
and is unwanted when using a reverse proxy that does the compression itself.

see #435
  • Loading branch information
lovasoa committed Jun 23, 2024
1 parent ca2eb6a commit 07a1c23
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Here are the available configuration options and their default values:
| `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. |
| `max_uploaded_file_size` | 5242880 | Maximum size of uploaded files in bytes. Defaults to 5 MiB. |
| `max_pending_rows` | 256 | Maximum number of rendered rows that can be queued up in memory when a client is slow to receive them. |
| `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). |
| `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. |
| `https_certificate_email` | contact@<https_domain> | The email address to use when requesting a certificate. |
| `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. |
Expand Down
8 changes: 8 additions & 0 deletions src/app_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ pub struct AppConfig {
/// Maximum number of messages that can be stored in memory before sending them to the client.
#[serde(default = "default_max_pending_rows")]
pub max_pending_rows: usize,

/// Whether to compress the http response body when the client supports it.
#[serde(default = "default_compress_responses")]
pub compress_responses: bool,
}

impl AppConfig {
Expand Down Expand Up @@ -302,6 +306,10 @@ fn default_max_pending_rows() -> usize {
256
}

fn default_compress_responses() -> bool {
true
}

#[derive(Debug, Deserialize, Serialize, PartialEq, Clone, Copy, Eq, Default)]
#[serde(rename_all = "lowercase")]
pub enum DevOrProd {
Expand Down
5 changes: 4 additions & 1 deletion src/webserver/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,10 @@ pub fn create_app(
"script-src 'self' https://cdn.jsdelivr.net",
)),
)
.wrap(middleware::Compress::default())
.wrap(middleware::Condition::new(
app_state.config.compress_responses,
middleware::Compress::default(),
))
.wrap(middleware::NormalizePath::new(
middleware::TrailingSlash::MergeOnly,
))
Expand Down

0 comments on commit 07a1c23

Please sign in to comment.