actix / actix/actix-web

Conditional Compression

Abierto
#3,031 0 comentarios 2 reacciones 0 asignados Ver en GitHub
A-http C-improvement
Lenguaje dominante
Rust
Estrellas
24.8k
Forks
1.9k
Merge medio
23 h 10 min
PR fusionados (30 d)
26

Descripción

# 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

```

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.