1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-11-26 03:21:08 +00:00

Remove content_length from ResponseBuilder (#1491)

* Remove content_length since it'll be overwritten by the response body. FIXES #1439

* Add setting of Content-Length to the no_chunking function

* Add changes and migration documentations

* Update MIGRATION.md

Co-authored-by: Yuki Okushi <huyuumi.dev@gmail.com>

Co-authored-by: Rob Ede <robjtede@icloud.com>
Co-authored-by: Yuki Okushi <huyuumi.dev@gmail.com>
This commit is contained in:
Omid Rad 2020-05-19 00:46:31 +02:00 committed by GitHub
parent 426a9b5d4d
commit 32a37b7282
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 14 additions and 13 deletions

View file

@ -6,6 +6,8 @@
* actix-http support for Actors messages was moved to actix-http crate and is enabled
with feature `actors`
* content_length function is removed from actix-http.
You can set Content-Length by normally setting the response body or calling no_chunking function.
* `BodySize::Sized64` variant has been removed. `BodySize::Sized` now receives a
`u64` instead of a `usize`.

View file

@ -5,6 +5,7 @@
### Changed
* Bump minimum supported Rust version to 1.40
* content_length function is removed, and you can set Content-Length by calling no_chunking function [#1439]
* `BodySize::Sized64` variant has been removed. `BodySize::Sized` now receives a
`u64` instead of a `usize`.
@ -13,6 +14,9 @@
* Support parsing of `SameSite=None` [#1503]
[#1439]: https://github.com/actix/actix-web/pull/1439
[#1503]: https://github.com/actix/actix-web/pull/1503
## [2.0.0-alpha.3] - 2020-05-08
### Fixed

View file

@ -472,7 +472,9 @@ impl ResponseBuilder {
/// Disable chunked transfer encoding for HTTP/1.1 streaming responses.
#[inline]
pub fn no_chunking(&mut self) -> &mut Self {
pub fn no_chunking(&mut self, len: u64) -> &mut Self {
self.header(header::CONTENT_LENGTH, len);
if let Some(parts) = parts(&mut self.head, &self.err) {
parts.no_chunking(true);
}
@ -497,12 +499,6 @@ impl ResponseBuilder {
self
}
/// Set content length
#[inline]
pub fn content_length(&mut self, len: u64) -> &mut Self {
self.header(header::CONTENT_LENGTH, len)
}
/// Set a cookie
///
/// ```rust

View file

@ -275,7 +275,7 @@ async fn test_h2_head_binary() {
let mut srv = test_server(move || {
HttpService::build()
.h2(|_| {
ok::<_, ()>(Response::Ok().content_length(STR.len() as u64).body(STR))
ok::<_, ()>(Response::Ok().body(STR))
})
.openssl(ssl_acceptor())
.map_err(|_| ())

View file

@ -281,7 +281,7 @@ async fn test_h2_head_binary() {
let mut srv = test_server(move || {
HttpService::build()
.h2(|_| {
ok::<_, ()>(Response::Ok().content_length(STR.len() as u64).body(STR))
ok::<_, ()>(Response::Ok().body(STR))
})
.rustls(ssl_acceptor())
})

View file

@ -490,7 +490,7 @@ async fn test_h1_head_binary() {
let mut srv = test_server(|| {
HttpService::build()
.h1(|_| {
ok::<_, ()>(Response::Ok().content_length(STR.len() as u64).body(STR))
ok::<_, ()>(Response::Ok().body(STR))
})
.tcp()
})

View file

@ -349,7 +349,7 @@ async fn test_body_br_streaming() {
async fn test_head_binary() {
let srv = test::start_with(test::config().h1(), || {
App::new().service(web::resource("/").route(
web::head().to(move || HttpResponse::Ok().content_length(100).body(STR)),
web::head().to(move || HttpResponse::Ok().body(STR)),
))
});
@ -371,8 +371,7 @@ async fn test_no_chunking() {
let srv = test::start_with(test::config().h1(), || {
App::new().service(web::resource("/").route(web::to(move || {
HttpResponse::Ok()
.no_chunking()
.content_length(STR.len() as u64)
.no_chunking(STR.len() as u64)
.streaming(TestBody::new(Bytes::from_static(STR.as_ref()), 24))
})))
});