From 7753b9da6dcb21ed7e7a56022869208447680319 Mon Sep 17 00:00:00 2001 From: Igor Gnatenko Date: Sat, 1 Jun 2019 10:13:45 +0200 Subject: [PATCH 1/5] web-codegen: Add extra-traits to syn features (#879) ```rust error[E0277]: `syn::attr::NestedMeta` doesn't implement `std::fmt::Debug` --> src/route.rs:149:57 | 149 | attr => panic!("Unknown attribute{:?}", attr), | ^^^^ `syn::attr::NestedMeta` cannot be formatted using `{:?}` because it doesn't implement `std::fmt::Debug` | = help: the trait `std::fmt::Debug` is not implemented for `syn::attr::NestedMeta` = note: required because of the requirements on the impl of `std::fmt::Debug` for `&syn::attr::NestedMeta` = note: required by `std::fmt::Debug::fmt` ``` --- actix-web-codegen/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actix-web-codegen/Cargo.toml b/actix-web-codegen/Cargo.toml index 5ca9f416d..8b9f8d1bd 100644 --- a/actix-web-codegen/Cargo.toml +++ b/actix-web-codegen/Cargo.toml @@ -13,7 +13,7 @@ proc-macro = true [dependencies] quote = "0.6" -syn = { version = "0.15", features = ["full", "parsing"] } +syn = { version = "0.15", features = ["full", "parsing", "extra-traits"] } [dev-dependencies] actix-web = { version = "1.0.0-beta.5" } From 29a0fe76d5d6b4ba778fe92f15e51be7e8edd117 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Sat, 1 Jun 2019 17:21:22 +0600 Subject: [PATCH 2/5] prepare actix-web-codegen release --- actix-web-codegen/CHANGES.md | 4 ++++ actix-web-codegen/Cargo.toml | 10 +++++----- actix-web-codegen/LICENSE-APACHE | 1 + actix-web-codegen/LICENSE-MIT | 1 + 4 files changed, 11 insertions(+), 5 deletions(-) create mode 120000 actix-web-codegen/LICENSE-APACHE create mode 120000 actix-web-codegen/LICENSE-MIT diff --git a/actix-web-codegen/CHANGES.md b/actix-web-codegen/CHANGES.md index 4f2d1c865..ac1861118 100644 --- a/actix-web-codegen/CHANGES.md +++ b/actix-web-codegen/CHANGES.md @@ -1,5 +1,9 @@ # Changes +## [0.1.1] - 2019-06-01 + +* Add syn "extra-traits" feature + ## [0.1.0] - 2019-05-18 * Release diff --git a/actix-web-codegen/Cargo.toml b/actix-web-codegen/Cargo.toml index 8b9f8d1bd..5557441c4 100644 --- a/actix-web-codegen/Cargo.toml +++ b/actix-web-codegen/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "actix-web-codegen" -version = "0.1.0" +version = "0.1.1" description = "Actix web proc macros" readme = "README.md" authors = ["Nikolay Kim "] @@ -12,11 +12,11 @@ workspace = ".." proc-macro = true [dependencies] -quote = "0.6" -syn = { version = "0.15", features = ["full", "parsing", "extra-traits"] } +quote = "0.6.12" +syn = { version = "0.15.34", features = ["full", "parsing", "extra-traits"] } [dev-dependencies] -actix-web = { version = "1.0.0-beta.5" } -actix-http = { version = "0.2.0", features=["ssl"] } +actix-web = { version = "1.0.0-rc" } +actix-http = { version = "0.2.2", features=["ssl"] } actix-http-test = { version = "0.2.0", features=["ssl"] } futures = { version = "0.1" } diff --git a/actix-web-codegen/LICENSE-APACHE b/actix-web-codegen/LICENSE-APACHE new file mode 120000 index 000000000..965b606f3 --- /dev/null +++ b/actix-web-codegen/LICENSE-APACHE @@ -0,0 +1 @@ +../LICENSE-APACHE \ No newline at end of file diff --git a/actix-web-codegen/LICENSE-MIT b/actix-web-codegen/LICENSE-MIT new file mode 120000 index 000000000..76219eb72 --- /dev/null +++ b/actix-web-codegen/LICENSE-MIT @@ -0,0 +1 @@ +../LICENSE-MIT \ No newline at end of file From a1b40f431481e0f41a73f4808c33241708abeb9f Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Sat, 1 Jun 2019 17:25:29 +0600 Subject: [PATCH 3/5] add license files --- Cargo.toml | 2 +- actix-files/LICENSE-APACHE | 1 + actix-files/LICENSE-MIT | 1 + actix-multipart/LICENSE-APACHE | 1 + actix-multipart/LICENSE-MIT | 1 + actix-session/LICENSE-APACHE | 1 + actix-session/LICENSE-MIT | 1 + actix-web-actors/LICENSE-APACHE | 1 + actix-web-actors/LICENSE-MIT | 1 + awc/LICENSE-APACHE | 1 + awc/LICENSE-MIT | 1 + test-server/LICENSE-APACHE | 1 + test-server/LICENSE-MIT | 1 + 13 files changed, 13 insertions(+), 1 deletion(-) create mode 120000 actix-files/LICENSE-APACHE create mode 120000 actix-files/LICENSE-MIT create mode 120000 actix-multipart/LICENSE-APACHE create mode 120000 actix-multipart/LICENSE-MIT create mode 120000 actix-session/LICENSE-APACHE create mode 120000 actix-session/LICENSE-MIT create mode 120000 actix-web-actors/LICENSE-APACHE create mode 120000 actix-web-actors/LICENSE-MIT create mode 120000 awc/LICENSE-APACHE create mode 120000 awc/LICENSE-MIT create mode 120000 test-server/LICENSE-APACHE create mode 120000 test-server/LICENSE-MIT diff --git a/Cargo.toml b/Cargo.toml index 829277654..e8fdb1362 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -72,7 +72,7 @@ actix-service = "0.4.0" actix-utils = "0.4.1" actix-router = "0.1.5" actix-rt = "0.2.2" -actix-web-codegen = "0.1.0" +actix-web-codegen = "0.1.1" actix-http = "0.2.2" actix-server = "0.5.1" actix-server-config = "0.1.1" diff --git a/actix-files/LICENSE-APACHE b/actix-files/LICENSE-APACHE new file mode 120000 index 000000000..965b606f3 --- /dev/null +++ b/actix-files/LICENSE-APACHE @@ -0,0 +1 @@ +../LICENSE-APACHE \ No newline at end of file diff --git a/actix-files/LICENSE-MIT b/actix-files/LICENSE-MIT new file mode 120000 index 000000000..76219eb72 --- /dev/null +++ b/actix-files/LICENSE-MIT @@ -0,0 +1 @@ +../LICENSE-MIT \ No newline at end of file diff --git a/actix-multipart/LICENSE-APACHE b/actix-multipart/LICENSE-APACHE new file mode 120000 index 000000000..965b606f3 --- /dev/null +++ b/actix-multipart/LICENSE-APACHE @@ -0,0 +1 @@ +../LICENSE-APACHE \ No newline at end of file diff --git a/actix-multipart/LICENSE-MIT b/actix-multipart/LICENSE-MIT new file mode 120000 index 000000000..76219eb72 --- /dev/null +++ b/actix-multipart/LICENSE-MIT @@ -0,0 +1 @@ +../LICENSE-MIT \ No newline at end of file diff --git a/actix-session/LICENSE-APACHE b/actix-session/LICENSE-APACHE new file mode 120000 index 000000000..965b606f3 --- /dev/null +++ b/actix-session/LICENSE-APACHE @@ -0,0 +1 @@ +../LICENSE-APACHE \ No newline at end of file diff --git a/actix-session/LICENSE-MIT b/actix-session/LICENSE-MIT new file mode 120000 index 000000000..76219eb72 --- /dev/null +++ b/actix-session/LICENSE-MIT @@ -0,0 +1 @@ +../LICENSE-MIT \ No newline at end of file diff --git a/actix-web-actors/LICENSE-APACHE b/actix-web-actors/LICENSE-APACHE new file mode 120000 index 000000000..965b606f3 --- /dev/null +++ b/actix-web-actors/LICENSE-APACHE @@ -0,0 +1 @@ +../LICENSE-APACHE \ No newline at end of file diff --git a/actix-web-actors/LICENSE-MIT b/actix-web-actors/LICENSE-MIT new file mode 120000 index 000000000..76219eb72 --- /dev/null +++ b/actix-web-actors/LICENSE-MIT @@ -0,0 +1 @@ +../LICENSE-MIT \ No newline at end of file diff --git a/awc/LICENSE-APACHE b/awc/LICENSE-APACHE new file mode 120000 index 000000000..965b606f3 --- /dev/null +++ b/awc/LICENSE-APACHE @@ -0,0 +1 @@ +../LICENSE-APACHE \ No newline at end of file diff --git a/awc/LICENSE-MIT b/awc/LICENSE-MIT new file mode 120000 index 000000000..76219eb72 --- /dev/null +++ b/awc/LICENSE-MIT @@ -0,0 +1 @@ +../LICENSE-MIT \ No newline at end of file diff --git a/test-server/LICENSE-APACHE b/test-server/LICENSE-APACHE new file mode 120000 index 000000000..965b606f3 --- /dev/null +++ b/test-server/LICENSE-APACHE @@ -0,0 +1 @@ +../LICENSE-APACHE \ No newline at end of file diff --git a/test-server/LICENSE-MIT b/test-server/LICENSE-MIT new file mode 120000 index 000000000..76219eb72 --- /dev/null +++ b/test-server/LICENSE-MIT @@ -0,0 +1 @@ +../LICENSE-MIT \ No newline at end of file From 666756bfbe1a6ed5e17cee567320f603af7b3cf9 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Sat, 1 Jun 2019 17:57:25 +0600 Subject: [PATCH 4/5] body helpers --- actix-http/CHANGES.md | 10 +++++++++ actix-http/src/body.rs | 25 +++++++++++++++++++--- actix-http/src/response.rs | 19 +++++++++++++++++ actix-http/tests/test_server.rs | 37 +++++++++++++++------------------ 4 files changed, 68 insertions(+), 23 deletions(-) diff --git a/actix-http/CHANGES.md b/actix-http/CHANGES.md index edc075b92..e677c3fa6 100644 --- a/actix-http/CHANGES.md +++ b/actix-http/CHANGES.md @@ -1,5 +1,15 @@ # Changes +### Added + +* Debug impl for ResponseBuilder + +* From SizedStream and BodyStream for Body + +### Changed + +* SizedStream accepts u64 + ## [0.2.2] - 2019-05-29 ### Fixed diff --git a/actix-http/src/body.rs b/actix-http/src/body.rs index 0652dd274..e728cdb98 100644 --- a/actix-http/src/body.rs +++ b/actix-http/src/body.rs @@ -234,6 +234,25 @@ impl From for Body { } } +impl From> for Body +where + S: Stream + 'static, +{ + fn from(s: SizedStream) -> Body { + Body::from_message(s) + } +} + +impl From> for Body +where + S: Stream + 'static, + E: Into + 'static, +{ + fn from(s: BodyStream) -> Body { + Body::from_message(s) + } +} + impl MessageBody for Bytes { fn size(&self) -> BodySize { BodySize::Sized(self.len()) @@ -366,7 +385,7 @@ where /// Type represent streaming body. This body implementation should be used /// if total size of stream is known. Data get sent as is without using transfer encoding. pub struct SizedStream { - size: usize, + size: u64, stream: S, } @@ -374,7 +393,7 @@ impl SizedStream where S: Stream, { - pub fn new(size: usize, stream: S) -> Self { + pub fn new(size: u64, stream: S) -> Self { SizedStream { size, stream } } } @@ -384,7 +403,7 @@ where S: Stream, { fn size(&self) -> BodySize { - BodySize::Sized(self.size) + BodySize::Sized64(self.size) } fn poll_next(&mut self) -> Poll, Error> { diff --git a/actix-http/src/response.rs b/actix-http/src/response.rs index fd51e54c7..ce986a472 100644 --- a/actix-http/src/response.rs +++ b/actix-http/src/response.rs @@ -764,6 +764,25 @@ impl IntoFuture for ResponseBuilder { } } +impl fmt::Debug for ResponseBuilder { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + let head = self.head.as_ref().unwrap(); + + let res = writeln!( + f, + "\nResponseBuilder {:?} {}{}", + head.version, + head.status, + head.reason.unwrap_or(""), + ); + let _ = writeln!(f, " headers:"); + for (key, val) in head.headers.iter() { + let _ = writeln!(f, " {:?}: {:?}", key, val); + } + res + } +} + /// Helper converters impl, E: Into> From> for Response { fn from(res: Result) -> Self { diff --git a/actix-http/tests/test_server.rs b/actix-http/tests/test_server.rs index a299f58d7..4a679f4b9 100644 --- a/actix-http/tests/test_server.rs +++ b/actix-http/tests/test_server.rs @@ -12,7 +12,6 @@ use futures::stream::{once, Stream}; use regex::Regex; use tokio_timer::sleep; -use actix_http::body::Body; use actix_http::error::PayloadError; use actix_http::{ body, error, http, http::header, Error, HttpService, KeepAlive, Request, Response, @@ -218,30 +217,28 @@ fn test_expect_continue_h1() { #[test] fn test_chunked_payload() { - let chunk_sizes = vec![ 32768, 32, 32768 ]; + let chunk_sizes = vec![32768, 32, 32768]; let total_size: usize = chunk_sizes.iter().sum(); let srv = TestServer::new(|| { - HttpService::build() - .h1(|mut request: Request| { - request.take_payload() - .map_err(|e| panic!(format!("Error reading payload: {}", e))) - .fold(0usize, |acc, chunk| { - future::ok::<_, ()>(acc + chunk.len()) - }) - .map(|req_size| { - Response::Ok().body(format!("size={}", req_size)) - }) - }) + HttpService::build().h1(|mut request: Request| { + request + .take_payload() + .map_err(|e| panic!(format!("Error reading payload: {}", e))) + .fold(0usize, |acc, chunk| future::ok::<_, ()>(acc + chunk.len())) + .map(|req_size| Response::Ok().body(format!("size={}", req_size))) + }) }); let returned_size = { let mut stream = net::TcpStream::connect(srv.addr()).unwrap(); - let _ = stream.write_all(b"POST /test HTTP/1.1\r\nTransfer-Encoding: chunked\r\n\r\n"); + let _ = stream + .write_all(b"POST /test HTTP/1.1\r\nTransfer-Encoding: chunked\r\n\r\n"); for chunk_size in chunk_sizes.iter() { let mut bytes = Vec::new(); - let random_bytes: Vec = (0..*chunk_size).map(|_| rand::random::()).collect(); + let random_bytes: Vec = + (0..*chunk_size).map(|_| rand::random::()).collect(); bytes.extend(format!("{:X}\r\n", chunk_size).as_bytes()); bytes.extend(&random_bytes[..]); @@ -826,8 +823,7 @@ fn test_h1_body_length() { HttpService::build().h1(|_| { let body = once(Ok(Bytes::from_static(STR.as_ref()))); ok::<_, ()>( - Response::Ok() - .body(Body::from_message(body::SizedStream::new(STR.len(), body))), + Response::Ok().body(body::SizedStream::new(STR.len() as u64, body)), ) }) }); @@ -852,9 +848,10 @@ fn test_h2_body_length() { HttpService::build() .h2(|_| { let body = once(Ok(Bytes::from_static(STR.as_ref()))); - ok::<_, ()>(Response::Ok().body(Body::from_message( - body::SizedStream::new(STR.len(), body), - ))) + ok::<_, ()>( + Response::Ok() + .body(body::SizedStream::new(STR.len() as u64, body)), + ) }) .map_err(|_| ()), ) From 15cdc680f6f1b1ba6454974838f6022e7e20b3e3 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Sat, 1 Jun 2019 17:57:40 +0600 Subject: [PATCH 5/5] Static files are incorrectly served as both chunked and with length #812 --- actix-files/CHANGES.md | 4 ++++ actix-files/Cargo.toml | 1 + actix-files/src/named.rs | 3 ++- src/lib.rs | 4 ++-- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/actix-files/CHANGES.md b/actix-files/CHANGES.md index 021f8dc63..c77494575 100644 --- a/actix-files/CHANGES.md +++ b/actix-files/CHANGES.md @@ -1,5 +1,9 @@ # Changes +## [0.1.1] - 2019-06-01 + +* Static files are incorrectly served as both chunked and with length #812 + ## [0.1.0] - 2019-05-25 * NamedFile last-modified check always fails due to nano-seconds diff --git a/actix-files/Cargo.toml b/actix-files/Cargo.toml index 9ffbf0e7a..fa48fff08 100644 --- a/actix-files/Cargo.toml +++ b/actix-files/Cargo.toml @@ -19,6 +19,7 @@ path = "src/lib.rs" [dependencies] actix-web = "1.0.0-rc" +actix-http = "0.2.2" actix-service = "0.4.0" bitflags = "1" bytes = "0.4" diff --git a/actix-files/src/named.rs b/actix-files/src/named.rs index 2298e35af..29e9eee41 100644 --- a/actix-files/src/named.rs +++ b/actix-files/src/named.rs @@ -11,6 +11,7 @@ use bitflags::bitflags; use mime; use mime_guess::guess_mime_type; +use actix_http::body::SizedStream; use actix_web::http::header::{ self, ContentDisposition, DispositionParam, DispositionType, }; @@ -434,7 +435,7 @@ impl Responder for NamedFile { if offset != 0 || length != self.md.len() { return Ok(resp.status(StatusCode::PARTIAL_CONTENT).streaming(reader)); }; - Ok(resp.streaming(reader)) + Ok(resp.body(SizedStream::new(length, reader))) } } } diff --git a/src/lib.rs b/src/lib.rs index f84dbd5be..0e4a421ed 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -111,7 +111,7 @@ pub use actix_web_codegen::*; // re-export for convenience pub use actix_http::Response as HttpResponse; -pub use actix_http::{cookie, http, Error, HttpMessage, ResponseError, Result}; +pub use actix_http::{body, cookie, http, Error, HttpMessage, ResponseError, Result}; pub use crate::app::App; pub use crate::extract::FromRequest; @@ -143,7 +143,7 @@ pub mod dev { pub use crate::types::json::JsonBody; pub use crate::types::readlines::Readlines; - pub use actix_http::body::{Body, BodySize, MessageBody, ResponseBody}; + pub use actix_http::body::{Body, BodySize, MessageBody, ResponseBody, SizedStream}; pub use actix_http::encoding::Decoder as Decompress; pub use actix_http::ResponseBuilder as HttpResponseBuilder; pub use actix_http::{