mirror of https://github.com/fafhrd91/actix-web
Merge branch 'master' into scope_work
This commit is contained in:
commit
567deaa3ec
|
@ -45,7 +45,7 @@ jobs:
|
||||||
toolchain: ${{ matrix.version.version }}
|
toolchain: ${{ matrix.version.version }}
|
||||||
|
|
||||||
- name: Install cargo-hack
|
- name: Install cargo-hack
|
||||||
uses: taiki-e/install-action@v2.21.17
|
uses: taiki-e/install-action@v2.21.19
|
||||||
with:
|
with:
|
||||||
tool: cargo-hack
|
tool: cargo-hack
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ jobs:
|
||||||
uses: actions-rust-lang/setup-rust-toolchain@v1.5.0
|
uses: actions-rust-lang/setup-rust-toolchain@v1.5.0
|
||||||
|
|
||||||
- name: Install cargo-hack
|
- name: Install cargo-hack
|
||||||
uses: taiki-e/install-action@v2.21.17
|
uses: taiki-e/install-action@v2.21.19
|
||||||
with:
|
with:
|
||||||
tool: cargo-hack
|
tool: cargo-hack
|
||||||
|
|
||||||
|
@ -106,7 +106,7 @@ jobs:
|
||||||
uses: actions-rust-lang/setup-rust-toolchain@v1.5.0
|
uses: actions-rust-lang/setup-rust-toolchain@v1.5.0
|
||||||
|
|
||||||
- name: Install nextest
|
- name: Install nextest
|
||||||
uses: taiki-e/install-action@v2.21.17
|
uses: taiki-e/install-action@v2.21.19
|
||||||
with:
|
with:
|
||||||
tool: nextest
|
tool: nextest
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,7 @@ jobs:
|
||||||
toolchain: ${{ matrix.version.version }}
|
toolchain: ${{ matrix.version.version }}
|
||||||
|
|
||||||
- name: Install cargo-hack
|
- name: Install cargo-hack
|
||||||
uses: taiki-e/install-action@v2.21.17
|
uses: taiki-e/install-action@v2.21.19
|
||||||
with:
|
with:
|
||||||
tool: cargo-hack
|
tool: cargo-hack
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ jobs:
|
||||||
components: llvm-tools-preview
|
components: llvm-tools-preview
|
||||||
|
|
||||||
- name: Install cargo-llvm-cov
|
- name: Install cargo-llvm-cov
|
||||||
uses: taiki-e/install-action@v2.21.17
|
uses: taiki-e/install-action@v2.21.19
|
||||||
with:
|
with:
|
||||||
tool: cargo-llvm-cov
|
tool: cargo-llvm-cov
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,10 @@
|
||||||
|
|
||||||
- Updated `zstd` dependency to `0.13`.
|
- Updated `zstd` dependency to `0.13`.
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Do not encode zero-sized response bodies
|
||||||
|
|
||||||
## 3.4.0
|
## 3.4.0
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
|
@ -52,7 +52,7 @@ impl<B: MessageBody> Encoder<B> {
|
||||||
|
|
||||||
pub fn response(encoding: ContentEncoding, head: &mut ResponseHead, body: B) -> Self {
|
pub fn response(encoding: ContentEncoding, head: &mut ResponseHead, body: B) -> Self {
|
||||||
// no need to compress an empty body
|
// no need to compress an empty body
|
||||||
if matches!(body.size(), BodySize::None) {
|
if matches!(body.size(), BodySize::None | BodySize::Sized(0)) {
|
||||||
return Self::none();
|
return Self::none();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -373,7 +373,7 @@ mod tests {
|
||||||
.default_service(web::to(move || {
|
.default_service(web::to(move || {
|
||||||
HttpResponse::Ok()
|
HttpResponse::Ok()
|
||||||
.insert_header((header::VARY, "x-test"))
|
.insert_header((header::VARY, "x-test"))
|
||||||
.finish()
|
.body(TEXT_DATA)
|
||||||
}))
|
}))
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
@ -429,4 +429,47 @@ mod tests {
|
||||||
assert_successful_identity_res_with_content_type(&res, "image/jpeg");
|
assert_successful_identity_res_with_content_type(&res, "image/jpeg");
|
||||||
assert_eq!(test::read_body(res).await, TEXT_DATA.as_bytes());
|
assert_eq!(test::read_body(res).await, TEXT_DATA.as_bytes());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[actix_rt::test]
|
||||||
|
async fn prevents_compression_empty() {
|
||||||
|
let app = test::init_service({
|
||||||
|
App::new()
|
||||||
|
.wrap(Compress::default())
|
||||||
|
.default_service(web::to(move || HttpResponse::Ok().finish()))
|
||||||
|
})
|
||||||
|
.await;
|
||||||
|
|
||||||
|
let req = test::TestRequest::default()
|
||||||
|
.insert_header((header::ACCEPT_ENCODING, "gzip"))
|
||||||
|
.to_request();
|
||||||
|
let res = test::call_service(&app, req).await;
|
||||||
|
assert_eq!(res.status(), StatusCode::OK);
|
||||||
|
assert!(!res.headers().contains_key(header::CONTENT_ENCODING));
|
||||||
|
assert!(test::read_body(res).await.is_empty());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "compress-brotli")]
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests_brotli {
|
||||||
|
use super::*;
|
||||||
|
use crate::{test, web, App};
|
||||||
|
|
||||||
|
#[actix_rt::test]
|
||||||
|
async fn prevents_compression_empty() {
|
||||||
|
let app = test::init_service({
|
||||||
|
App::new()
|
||||||
|
.wrap(Compress::default())
|
||||||
|
.default_service(web::to(move || HttpResponse::Ok().finish()))
|
||||||
|
})
|
||||||
|
.await;
|
||||||
|
|
||||||
|
let req = test::TestRequest::default()
|
||||||
|
.insert_header((header::ACCEPT_ENCODING, "br"))
|
||||||
|
.to_request();
|
||||||
|
let res = test::call_service(&app, req).await;
|
||||||
|
assert_eq!(res.status(), StatusCode::OK);
|
||||||
|
assert!(!res.headers().contains_key(header::CONTENT_ENCODING));
|
||||||
|
assert!(test::read_body(res).await.is_empty());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue