diff --git a/docs/response.md b/docs/response.md index f28fbe9..aeeb096 100644 --- a/docs/response.md +++ b/docs/response.md @@ -38,31 +38,17 @@ Actix Web can automatically _compress_ payloads with the [_Compress middleware_] - Deflate - Identity - - -Response payload is compressed based on the _encoding_ parameter from the `middleware::BodyEncoding` trait. By default, `ContentEncoding::Auto` is used. If `ContentEncoding::Auto` is selected, then the compression depends on the request's `Accept-Encoding` header. - -> `ContentEncoding::Identity` can be used to disable compression. If another content encoding is selected, the compression is enforced for that codec. - -For example, to enable `brotli` for a single handler use `ContentEncoding::Br`: - - - -or for the entire application: - - - -In this case we explicitly disable content compression by setting content encoding to an `Identity` value: - - - -When dealing with an already compressed body (for example when serving assets), set the content encoding to `Identity` to avoid compressing the already compressed data and set the `content-encoding` header manually: - - - -Also it is possible to set default content encoding on application level, by default `ContentEncoding::Auto` is used, which implies automatic content compression negotiation. +A response's `Content-Encoding` header defaults to `ContentEncoding::Auto`, which performs automatic content compression negotiation based on the request's `Accept-Encoding` header. +Explicitly disable content compression on a handler by setting `Content-Encoding` to an `Identity` value: + + + +When dealing with an already compressed body (for example, when serving pre-compressed assets), set the `Content-Encoding` header on the response manually to bypass the middleware: + + + [responsebuilder]: https://docs.rs/actix-web/4/actix_web/struct.HttpResponseBuilder.html [compressmidddleware]: https://docs.rs/actix-web/4/actix_web/middleware/struct.Compress.html diff --git a/examples/responses/src/brotli.rs b/examples/responses/src/brotli.rs deleted file mode 100644 index b0296a7..0000000 --- a/examples/responses/src/brotli.rs +++ /dev/null @@ -1,20 +0,0 @@ -// -use actix_web::{get, middleware, App, HttpResponse, HttpServer}; - -#[get("/")] -async fn index_br() -> HttpResponse { - HttpResponse::Ok().body("data") -} - -#[actix_web::main] -async fn main() -> std::io::Result<()> { - HttpServer::new(|| { - App::new() - .wrap(middleware::Compress::default()) - .service(index_br) - }) - .bind(("127.0.0.1", 8080))? - .run() - .await -} -// diff --git a/examples/responses/src/brotli_two.rs b/examples/responses/src/brotli_two.rs deleted file mode 100644 index 5bd899a..0000000 --- a/examples/responses/src/brotli_two.rs +++ /dev/null @@ -1,21 +0,0 @@ -// -use actix_web::{http::ContentEncoding, dev::BodyEncoding, HttpResponse}; - -async fn index_br() -> HttpResponse { - HttpResponse::Ok().body("data") -} - -#[actix_web::main] -async fn main() -> std::io::Result<()> { - use actix_web::{middleware, web, App, HttpServer}; - - HttpServer::new(|| { - App::new() - .wrap(middleware::Compress::new(ContentEncoding::Br)) - .route("/", web::get().to(index_br)) - }) - .bind(("127.0.0.1", 8080))? - .run() - .await -} -// diff --git a/examples/responses/src/compress.rs b/examples/responses/src/compress.rs deleted file mode 100644 index 43b8b81..0000000 --- a/examples/responses/src/compress.rs +++ /dev/null @@ -1,20 +0,0 @@ -// -use actix_web::{get, middleware, App, HttpResponse, HttpServer}; - -#[get("/")] -async fn index_br() -> HttpResponse { - HttpResponse::Ok().body("data") -} - -#[actix_web::main] -async fn main() -> std::io::Result<()> { - HttpServer::new(|| { - App::new() - .wrap(middleware::Compress::default()) - .service(index_br) - }) - .bind(("127.0.0.1", 8080))? - .run() - .await -} -// diff --git a/examples/responses/src/main.rs b/examples/responses/src/main.rs index fcb71b8..cf9beec 100644 --- a/examples/responses/src/main.rs +++ b/examples/responses/src/main.rs @@ -1,7 +1,5 @@ pub mod auto; -pub mod brotli; pub mod chunked; -pub mod compress; pub mod identity; pub mod identity_two; pub mod json_resp;