1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-08-31 00:50:20 +02:00

update user guide content compression section

This commit is contained in:
Nikolay Kim
2018-04-12 09:54:35 -07:00
parent 7295846426
commit 83168731fc
5 changed files with 42 additions and 5 deletions

View File

@@ -37,7 +37,8 @@ Actix automatically *compresses*/*decompresses* payloads. The following codecs a
* Identity
If request headers contain a `Content-Encoding` header, the request payload is decompressed
according to the header value. Multiple codecs are not supported, i.e: `Content-Encoding: br, gzip`.
according to the header value. Multiple codecs are not supported,
i.e: `Content-Encoding: br, gzip`.
Response payload is compressed based on the *content_encoding* parameter.
By default, `ContentEncoding::Auto` is used. If `ContentEncoding::Auto` is selected,
@@ -60,6 +61,40 @@ fn index(req: HttpRequest) -> HttpResponse {
# fn main() {}
```
In this case we explicitly disable content compression
by setting content encoding to a `Identity` value:
```rust
# extern crate actix_web;
use actix_web::{HttpRequest, HttpResponse, http::ContentEncoding};
fn index(req: HttpRequest) -> HttpResponse {
HttpResponse::Ok()
.content_encoding(ContentEncoding::Identity) // <- disable compression
.body("data")
}
# fn main() {}
```
Also it is possible to set default content encoding on application level, by
default `ContentEncoding::Auto` is used, which implies automatic content compression
negotiation.
```rust
# extern crate actix_web;
use actix_web::{App, HttpRequest, HttpResponse, http::ContentEncoding};
fn index(req: HttpRequest) -> HttpResponse {
HttpResponse::Ok()
.body("data")
}
fn main() {
let app = App::new()
.default_encoding(ContentEncoding::Identity) // <- disable compression for all routes
.resource("/index.html", |r| r.with(index));
}
```
## JSON Request
There are several options for json body deserialization.