Conditional Compression
- Ngôn ngữ chính
- Rust
- Star
- 24.8k
- Fork
- 1.9k
- Merge trung bình
- 23 giờ 10 phút
- Pull request đã merge (30 ngày)
- 26
Mô tả
# 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
```
Hướng dẫn đóng góp
Đánh giá
Issue này chưa được đánh giá.