actix / actix/actix-web

Conditional Compression

Offen
#3,031 0 Kommentare 2 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
A-http C-improvement
Vorherrschende Sprache
Rust
Sterne
24.8k
Forks
1.9k
Ø Merge
23 Std. 10 Min.
Gemergte PRs (30 T.)
26

Beschreibung

# Current Behavior
Currently, enabling the compression middleware will enable it for all responses. This is a good default but can lead to wasted compression computation if the response is already very small. This happens when the cost to compress response data is more expensive that simply sending it uncompressed.

# Possible Solution
I think [Spring](https://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/web/server/Compression.html) has a very nice way of handling this issue:
In Spring responses are only compressed if they exceed a threshold size (in bytes).
By default in Spring, the threshold is 2KB but is overridable.

Considering the changes in https://github.com/actix/actix-web/pull/2948 I think we can can extend that pattern like so

```rs
actix_web::middleware::Compress::new()
.min_response_size(2048)
.... // other options

```

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.