From 83168731fc5e265f61dd25265a6ac11634c28175 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Thu, 12 Apr 2018 09:54:35 -0700 Subject: [PATCH] update user guide content compression section --- .travis.yml | 2 +- CHANGES.md | 4 +++- Cargo.toml | 2 +- guide/src/qs_7.md | 37 ++++++++++++++++++++++++++++++++++++- src/application.rs | 2 +- 5 files changed, 42 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1c3fe7e37..76352ddf0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -79,7 +79,7 @@ after_success: if [[ "$TRAVIS_OS_NAME" == "linux" && "$TRAVIS_PULL_REQUEST" = "false" && "$TRAVIS_BRANCH" == "master" && "$TRAVIS_RUST_VERSION" == "beta" ]]; then cargo doc --features "alpn, tls, session" --no-deps && echo "" > target/doc/index.html && - curl -sL https://github.com/rust-lang-nursery/mdBook/releases/download/v0.1.3/mdbook-v0.1.3-x86_64-unknown-linux-gnu.tar.gz | tar xvz -C $HOME/.cargo/bin && + curl -sL https://github.com/rust-lang-nursery/mdBook/releases/download/v0.1.2/mdbook-v0.1.2-x86_64-unknown-linux-gnu.tar.gz | tar xvz -C $HOME/.cargo/bin && cd guide && mdbook build -d ../target/doc/guide && cd .. && git clone https://github.com/davisp/ghp-import.git && ./ghp-import/ghp_import.py -n -p -f -m "Documentation upload" -r https://"$GH_TOKEN"@github.com/"$TRAVIS_REPO_SLUG.git" target/doc && diff --git a/CHANGES.md b/CHANGES.md index 72fcf9c7f..07a655040 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,10 +1,12 @@ # Changes -## 0.5.1 (2018-xx-xx) +## 0.5.1 (2018-04-xx) * Client connector provides stats, `ClientConnector::stats()` +* Fix end-of-stream handling in parse_payload #173 + ## 0.5.0 (2018-04-10) diff --git a/Cargo.toml b/Cargo.toml index 8c663f58a..9bafefeec 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "actix-web" version = "0.5.1" authors = ["Nikolay Kim "] -description = "Actix web is a simple, pragmatic, extremely fast, web framework for Rust." +description = "Actix web is a simple, pragmatic and extremely fast web framework for Rust." readme = "README.md" keywords = ["http", "web", "framework", "async", "futures"] homepage = "https://github.com/actix/actix-web" diff --git a/guide/src/qs_7.md b/guide/src/qs_7.md index 3e8694514..b07a25d6f 100644 --- a/guide/src/qs_7.md +++ b/guide/src/qs_7.md @@ -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. diff --git a/src/application.rs b/src/application.rs index db0e9d813..d2f673433 100644 --- a/src/application.rs +++ b/src/application.rs @@ -350,7 +350,7 @@ impl App where S: 'static { } /// Set default content encoding. `ContentEncoding::Auto` is set by default. - pub fn default_encoding(mut self, encoding: ContentEncoding) -> App + pub fn default_encoding(mut self, encoding: ContentEncoding) -> App { { let parts = self.parts.as_mut().expect("Use after finish");