From 7c0f57084559ce9c97fb09a49047e8c9059551f8 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Sun, 16 Jun 2019 21:54:17 +0600 Subject: [PATCH 01/11] Do not compress NoContent (204) responses #918 --- Cargo.toml | 4 ++-- actix-http/CHANGES.md | 7 +++++++ actix-http/Cargo.toml | 4 ++-- actix-http/src/encoding/encoder.rs | 2 ++ 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8531a93ac..a18635684 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -89,10 +89,10 @@ actix-cors = { version = "0.1.0", optional = true } actix-identity = { version = "0.1.0", optional = true } bytes = "0.4" -derive_more = "0.14" +derive_more = "0.15.0" encoding = "0.2" futures = "0.1.25" -hashbrown = "0.3.1" +hashbrown = "0.5.0" log = "0.4" mime = "0.3" net2 = "0.2.33" diff --git a/actix-http/CHANGES.md b/actix-http/CHANGES.md index d0c75da76..93c352898 100644 --- a/actix-http/CHANGES.md +++ b/actix-http/CHANGES.md @@ -1,5 +1,12 @@ # Changes +## [0.2.4] - 2019-06-16 + +### Fixed + +* Do not compress NoContent (204) responses #918 + + ## [0.2.3] - 2019-06-02 ### Added diff --git a/actix-http/Cargo.toml b/actix-http/Cargo.toml index 1847a5ba2..4411bdf6d 100644 --- a/actix-http/Cargo.toml +++ b/actix-http/Cargo.toml @@ -56,11 +56,11 @@ bitflags = "1.0" bytes = "0.4" byteorder = "1.2" copyless = "0.1.2" -derive_more = "0.14" +derive_more = "0.15.0" either = "1.5.2" encoding = "0.2" futures = "0.1.25" -hashbrown = "0.3.0" +hashbrown = "0.5.0" h2 = "0.1.16" http = "0.1.17" httparse = "1.3" diff --git a/actix-http/src/encoding/encoder.rs b/actix-http/src/encoding/encoder.rs index aabce292a..d793eb4c7 100644 --- a/actix-http/src/encoding/encoder.rs +++ b/actix-http/src/encoding/encoder.rs @@ -33,6 +33,7 @@ impl Encoder { ) -> ResponseBody> { let can_encode = !(head.headers().contains_key(&CONTENT_ENCODING) || head.status == StatusCode::SWITCHING_PROTOCOLS + || head.status == StatusCode::NO_CONTENT || encoding == ContentEncoding::Identity || encoding == ContentEncoding::Auto); @@ -122,6 +123,7 @@ impl MessageBody for Encoder { Async::NotReady => return Ok(Async::NotReady), Async::Ready(Some(chunk)) => { if let Some(mut encoder) = self.encoder.take() { + self.encoded += chunk.len(); if chunk.len() < INPLACE { encoder.write(&chunk)?; let chunk = encoder.take(); From d2b6502c7a743bed3f10eea269aa4031930a1972 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Sun, 16 Jun 2019 21:59:22 +0600 Subject: [PATCH 02/11] prepare actix-http release --- actix-http/Cargo.toml | 2 +- actix-http/src/encoding/encoder.rs | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/actix-http/Cargo.toml b/actix-http/Cargo.toml index 4411bdf6d..2da410130 100644 --- a/actix-http/Cargo.toml +++ b/actix-http/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "actix-http" -version = "0.2.3" +version = "0.2.4" authors = ["Nikolay Kim "] description = "Actix http primitives" readme = "README.md" diff --git a/actix-http/src/encoding/encoder.rs b/actix-http/src/encoding/encoder.rs index d793eb4c7..fa95d798a 100644 --- a/actix-http/src/encoding/encoder.rs +++ b/actix-http/src/encoding/encoder.rs @@ -123,7 +123,6 @@ impl MessageBody for Encoder { Async::NotReady => return Ok(Async::NotReady), Async::Ready(Some(chunk)) => { if let Some(mut encoder) = self.encoder.take() { - self.encoded += chunk.len(); if chunk.len() < INPLACE { encoder.write(&chunk)?; let chunk = encoder.take(); From 686e5f1595b4a740d695d94c23cd5c8bb3b35872 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Sun, 16 Jun 2019 22:10:22 +0600 Subject: [PATCH 03/11] update deps --- Cargo.toml | 6 +++--- actix-files/Cargo.toml | 6 +++--- actix-multipart/Cargo.toml | 6 +++--- actix-session/Cargo.toml | 8 ++++---- actix-web-actors/Cargo.toml | 4 ++-- actix-web-codegen/Cargo.toml | 4 ++-- awc/Cargo.toml | 10 +++++----- test-server/CHANGES.md | 4 ++++ test-server/Cargo.toml | 8 ++++---- 9 files changed, 30 insertions(+), 26 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a18635684..a4c37cfa4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -73,12 +73,12 @@ depracated = ["actix-cors", "actix-identity"] [dependencies] actix-codec = "0.1.2" -actix-service = "0.4.0" +actix-service = "0.4.1" actix-utils = "0.4.1" actix-router = "0.1.5" actix-rt = "0.2.2" actix-web-codegen = "0.1.2" -actix-http = "0.2.3" +actix-http = "0.2.4" actix-server = "0.5.1" actix-server-config = "0.1.1" actix-threadpool = "0.1.1" @@ -110,7 +110,7 @@ rustls = { version = "0.15", optional = true } [dev-dependencies] actix = { version = "0.8.3" } -actix-http = { version = "0.2.3", features=["ssl", "brotli", "flate2-zlib"] } +actix-http = { version = "0.2.4", features=["ssl", "brotli", "flate2-zlib"] } actix-http-test = { version = "0.2.0", features=["ssl"] } rand = "0.6" env_logger = "0.6" diff --git a/actix-files/Cargo.toml b/actix-files/Cargo.toml index b1428a22b..9df93834a 100644 --- a/actix-files/Cargo.toml +++ b/actix-files/Cargo.toml @@ -19,12 +19,12 @@ path = "src/lib.rs" [dependencies] actix-web = { version = "1.0.0", default-features = false } -actix-http = "0.2.3" -actix-service = "0.4.0" +actix-http = "0.2.4" +actix-service = "0.4.1" bitflags = "1" bytes = "0.4" futures = "0.1.25" -derive_more = "0.14" +derive_more = "0.15.0" log = "0.4" mime = "0.3" mime_guess = "2.0.0-alpha" diff --git a/actix-multipart/Cargo.toml b/actix-multipart/Cargo.toml index d377be1f4..b26681e25 100644 --- a/actix-multipart/Cargo.toml +++ b/actix-multipart/Cargo.toml @@ -19,9 +19,9 @@ path = "src/lib.rs" [dependencies] actix-web = { version = "1.0.0", default-features = false } -actix-service = "0.4.0" +actix-service = "0.4.1" bytes = "0.4" -derive_more = "0.14" +derive_more = "0.15.0" httparse = "1.3" futures = "0.1.25" log = "0.4" @@ -31,4 +31,4 @@ twoway = "0.2" [dev-dependencies] actix-rt = "0.2.2" -actix-http = "0.2.2" \ No newline at end of file +actix-http = "0.2.4" \ No newline at end of file diff --git a/actix-session/Cargo.toml b/actix-session/Cargo.toml index 1101ceffc..4c1d66570 100644 --- a/actix-session/Cargo.toml +++ b/actix-session/Cargo.toml @@ -24,12 +24,12 @@ default = ["cookie-session"] cookie-session = ["actix-web/secure-cookies"] [dependencies] -actix-web = "1.0.0-rc" -actix-service = "0.4.0" +actix-web = "1.0.0" +actix-service = "0.4.1" bytes = "0.4" -derive_more = "0.14" +derive_more = "0.15.0" futures = "0.1.25" -hashbrown = "0.3.0" +hashbrown = "0.5.0" serde = "1.0" serde_json = "1.0" time = "0.1.42" diff --git a/actix-web-actors/Cargo.toml b/actix-web-actors/Cargo.toml index 565b53a57..90d0a00f9 100644 --- a/actix-web-actors/Cargo.toml +++ b/actix-web-actors/Cargo.toml @@ -19,8 +19,8 @@ path = "src/lib.rs" [dependencies] actix = "0.8.3" -actix-web = "1.0.0-rc" -actix-http = "0.2.2" +actix-web = "1.0.0" +actix-http = "0.2.4" actix-codec = "0.1.2" bytes = "0.4" futures = "0.1.25" diff --git a/actix-web-codegen/Cargo.toml b/actix-web-codegen/Cargo.toml index 23e9a432f..29abb4897 100644 --- a/actix-web-codegen/Cargo.toml +++ b/actix-web-codegen/Cargo.toml @@ -16,7 +16,7 @@ quote = "0.6.12" syn = { version = "0.15.34", features = ["full", "parsing", "extra-traits"] } [dev-dependencies] -actix-web = { version = "1.0.0-rc" } -actix-http = { version = "0.2.2", features=["ssl"] } +actix-web = { version = "1.0.0" } +actix-http = { version = "0.2.4", features=["ssl"] } actix-http-test = { version = "0.2.0", features=["ssl"] } futures = { version = "0.1" } diff --git a/awc/Cargo.toml b/awc/Cargo.toml index cad52033e..d0629f4fa 100644 --- a/awc/Cargo.toml +++ b/awc/Cargo.toml @@ -40,11 +40,11 @@ flate2-rust = ["actix-http/flate2-rust"] [dependencies] actix-codec = "0.1.2" -actix-service = "0.4.0" -actix-http = "0.2.3" +actix-service = "0.4.1" +actix-http = "0.2.4" base64 = "0.10.1" bytes = "0.4" -derive_more = "0.14" +derive_more = "0.15.0" futures = "0.1.25" log =" 0.4" mime = "0.3" @@ -58,8 +58,8 @@ openssl = { version="0.10", optional = true } [dev-dependencies] actix-rt = "0.2.2" -actix-web = { version = "1.0.0-rc", features=["ssl"] } -actix-http = { version = "0.2.3", features=["ssl"] } +actix-web = { version = "1.0.0", features=["ssl"] } +actix-http = { version = "0.2.4", features=["ssl"] } actix-http-test = { version = "0.2.0", features=["ssl"] } actix-utils = "0.4.1" actix-server = { version = "0.5.1", features=["ssl"] } diff --git a/test-server/CHANGES.md b/test-server/CHANGES.md index a31937909..e7292c0ec 100644 --- a/test-server/CHANGES.md +++ b/test-server/CHANGES.md @@ -1,5 +1,9 @@ # Changes +## [0.2.2] - 2019-06-16 + +* Add .put() and .sput() methods + ## [0.2.1] - 2019-06-05 * Add license files diff --git a/test-server/Cargo.toml b/test-server/Cargo.toml index a8f4425ba..4231b17bf 100644 --- a/test-server/Cargo.toml +++ b/test-server/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "actix-http-test" -version = "0.2.1" +version = "0.2.2" authors = ["Nikolay Kim "] description = "Actix http test server" readme = "README.md" @@ -32,7 +32,7 @@ ssl = ["openssl", "actix-server/ssl", "awc/ssl"] [dependencies] actix-codec = "0.1.2" actix-rt = "0.2.2" -actix-service = "0.4.0" +actix-service = "0.4.1" actix-server = "0.5.1" actix-utils = "0.4.1" awc = "0.2.1" @@ -55,5 +55,5 @@ tokio-timer = "0.2" openssl = { version="0.10", optional = true } [dev-dependencies] -actix-web = "1.0.0-rc" -actix-http = "0.2.3" +actix-web = "1.0.0" +actix-http = "0.2.4" From acda1c075a000a8b94f04b25b8d3668954d7938e Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Mon, 17 Jun 2019 12:23:30 +0600 Subject: [PATCH 04/11] prepare actix-web release --- CHANGES.md | 2 +- Cargo.toml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 87729eb6a..385264139 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,6 @@ # Changes -## [1.0.1] - 2019-06-xx +## [1.0.1] - 2019-06-17 ### Add diff --git a/Cargo.toml b/Cargo.toml index a4c37cfa4..d8a143d63 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "actix-web" -version = "1.0.0" +version = "1.0.1" authors = ["Nikolay Kim "] description = "Actix web is a simple, pragmatic and extremely fast web framework for Rust." readme = "README.md" @@ -111,7 +111,7 @@ rustls = { version = "0.15", optional = true } [dev-dependencies] actix = { version = "0.8.3" } actix-http = { version = "0.2.4", features=["ssl", "brotli", "flate2-zlib"] } -actix-http-test = { version = "0.2.0", features=["ssl"] } +actix-http-test = { version = "0.2.2", features=["ssl"] } rand = "0.6" env_logger = "0.6" serde_derive = "1.0" From 546a8a58db0e9f985310ae1ed56878a089f7ba09 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Mon, 17 Jun 2019 12:33:00 +0600 Subject: [PATCH 05/11] remove cors and identity middlewares --- CHANGES.md | 9 +++++++++ Cargo.toml | 11 ++--------- src/middleware/mod.rs | 14 -------------- 3 files changed, 11 insertions(+), 23 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 385264139..9f899ea9d 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,14 @@ # Changes +## [1.0.2] - 2019-06-17 + +### Changes + +* Move cors middleware to `actix-cors` crate. + +* Move identity middleware to `actix-identity` crate. + + ## [1.0.1] - 2019-06-17 ### Add diff --git a/Cargo.toml b/Cargo.toml index d8a143d63..996d9470b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,7 +43,7 @@ members = [ ] [features] -default = ["brotli", "flate2-zlib", "client", "fail", "depracated"] +default = ["brotli", "flate2-zlib", "client", "fail"] # http client client = ["awc"] @@ -68,9 +68,6 @@ ssl = ["openssl", "actix-server/ssl", "awc/ssl"] # rustls rust-tls = ["rustls", "actix-server/rust-tls"] -# deprecated middlewares -depracated = ["actix-cors", "actix-identity"] - [dependencies] actix-codec = "0.1.2" actix-service = "0.4.1" @@ -84,10 +81,6 @@ actix-server-config = "0.1.1" actix-threadpool = "0.1.1" awc = { version = "0.2.1", optional = true } -# deprecated middlewares -actix-cors = { version = "0.1.0", optional = true } -actix-identity = { version = "0.1.0", optional = true } - bytes = "0.4" derive_more = "0.15.0" encoding = "0.2" @@ -125,7 +118,7 @@ opt-level = 3 codegen-units = 1 [patch.crates-io] -# actix-web = { path = "." } +actix-web = { path = "." } actix-http = { path = "actix-http" } actix-http-test = { path = "test-server" } actix-web-codegen = { path = "actix-web-codegen" } diff --git a/src/middleware/mod.rs b/src/middleware/mod.rs index c2001e00f..814993f0c 100644 --- a/src/middleware/mod.rs +++ b/src/middleware/mod.rs @@ -10,17 +10,3 @@ mod normalize; pub use self::defaultheaders::DefaultHeaders; pub use self::logger::Logger; pub use self::normalize::NormalizePath; - -#[cfg(feature = "deprecated")] -#[deprecated( - since = "1.0.1", - note = "please use `actix_cors` instead. support will be removed in actix-web 1.0.2" -)] -pub use actix_cors as cors; - -#[cfg(feature = "deprecated")] -#[deprecated( - since = "1.0.1", - note = "please use `actix_identity` instead. support will be removed in actix-web 1.0.2" -)] -pub use actix_identity as identity; From ad0e6f73b3edd666fced6c29e8dd74f3991dab66 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Mon, 17 Jun 2019 12:35:00 +0600 Subject: [PATCH 06/11] update version --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 996d9470b..9f7f8776a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "actix-web" -version = "1.0.1" +version = "1.0.2" authors = ["Nikolay Kim "] description = "Actix web is a simple, pragmatic and extremely fast web framework for Rust." readme = "README.md" From d7780d53c929fcd650710c35d9d276aeab822af3 Mon Sep 17 00:00:00 2001 From: Joe Roberts Date: Tue, 18 Jun 2019 02:27:23 +0100 Subject: [PATCH 07/11] Fix typo in `actix_web::web::Data::get_ref docstring` (#921) --- src/data.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/data.rs b/src/data.rs index 9fd8b67fc..bd166b79c 100644 --- a/src/data.rs +++ b/src/data.rs @@ -73,7 +73,7 @@ impl Data { Data(Arc::new(state)) } - /// Get referecnce to inner app data. + /// Get reference to inner app data. pub fn get_ref(&self) -> &T { self.0.as_ref() } From 313ac4876586472ca070cabc647d164971688b76 Mon Sep 17 00:00:00 2001 From: messense Date: Tue, 18 Jun 2019 14:43:25 +0800 Subject: [PATCH 08/11] Use encoding_rs crate instead of unmaintained encoding crate (#922) * Use encoding_rs crate instead of unmaintained encoding crate * Update changelog --- CHANGES.md | 16 +++++++++++----- Cargo.toml | 2 +- actix-http/CHANGES.md | 8 +++++++- actix-http/Cargo.toml | 2 +- actix-http/src/httpmessage.rs | 15 +++++++-------- src/types/form.rs | 13 ++++++------- src/types/payload.rs | 11 +++++------ src/types/readlines.rs | 35 +++++++++++++++++++---------------- 8 files changed, 57 insertions(+), 45 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 9f899ea9d..a20713107 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,8 +1,14 @@ # Changes +## [1.0.3] - unreleased + +### Changed + +* Use `encoding_rs` crate instead of unmaintained `encoding` crate + ## [1.0.2] - 2019-06-17 -### Changes +### Changed * Move cors middleware to `actix-cors` crate. @@ -17,7 +23,7 @@ * Add `middleware::identity::RequestIdentity` trait to `get_identity` from `HttpMessage`. -### Changes +### Changed * Move cors middleware to `actix-cors` crate. @@ -47,7 +53,7 @@ * Add macros for head, options, trace, connect and patch http methods -### Changes +### Changed * Drop an unnecessary `Option<_>` indirection around `ServerBuilder` from `HttpServer`. #863 @@ -65,7 +71,7 @@ * Add `Query::from_query()` to extract parameters from a query string. #846 * `QueryConfig`, similar to `JsonConfig` for customizing error handling of query extractors. -### Changes +### Changed * `JsonConfig` is now `Send + Sync`, this implies that `error_handler` must be `Send + Sync` too. @@ -80,7 +86,7 @@ * Allow to set/override app data on scope level -### Changes +### Changed * `App::configure` take an `FnOnce` instead of `Fn` * Upgrade actix-net crates diff --git a/Cargo.toml b/Cargo.toml index 9f7f8776a..4f8cd745d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -83,7 +83,7 @@ awc = { version = "0.2.1", optional = true } bytes = "0.4" derive_more = "0.15.0" -encoding = "0.2" +encoding_rs = "0.8" futures = "0.1.25" hashbrown = "0.5.0" log = "0.4" diff --git a/actix-http/CHANGES.md b/actix-http/CHANGES.md index 93c352898..891967f10 100644 --- a/actix-http/CHANGES.md +++ b/actix-http/CHANGES.md @@ -1,5 +1,11 @@ # Changes +## [0.2.5] - unreleased + +### Changed + +* Use `encoding_rs` crate instead of unmaintained `encoding` crate + ## [0.2.4] - 2019-06-16 ### Fixed @@ -83,7 +89,7 @@ ## [0.1.1] - 2019-04-19 -### Changes +### Changed * Cookie::max_age() accepts value in seconds diff --git a/actix-http/Cargo.toml b/actix-http/Cargo.toml index 2da410130..c3930a7a6 100644 --- a/actix-http/Cargo.toml +++ b/actix-http/Cargo.toml @@ -58,7 +58,7 @@ byteorder = "1.2" copyless = "0.1.2" derive_more = "0.15.0" either = "1.5.2" -encoding = "0.2" +encoding_rs = "0.8" futures = "0.1.25" hashbrown = "0.5.0" h2 = "0.1.16" diff --git a/actix-http/src/httpmessage.rs b/actix-http/src/httpmessage.rs index 1534973a8..05d668c10 100644 --- a/actix-http/src/httpmessage.rs +++ b/actix-http/src/httpmessage.rs @@ -1,9 +1,7 @@ use std::cell::{Ref, RefMut}; use std::str; -use encoding::all::UTF_8; -use encoding::label::encoding_from_whatwg_label; -use encoding::EncodingRef; +use encoding_rs::{Encoding, UTF_8}; use http::header; use mime::Mime; @@ -59,10 +57,12 @@ pub trait HttpMessage: Sized { /// Get content type encoding /// /// UTF-8 is used by default, If request charset is not set. - fn encoding(&self) -> Result { + fn encoding(&self) -> Result<&'static Encoding, ContentTypeError> { if let Some(mime_type) = self.mime_type()? { if let Some(charset) = mime_type.get_param("charset") { - if let Some(enc) = encoding_from_whatwg_label(charset.as_str()) { + if let Some(enc) = + Encoding::for_label_no_replacement(charset.as_str().as_bytes()) + { Ok(enc) } else { Err(ContentTypeError::UnknownEncoding) @@ -166,8 +166,7 @@ where #[cfg(test)] mod tests { use bytes::Bytes; - use encoding::all::ISO_8859_2; - use encoding::Encoding; + use encoding_rs::ISO_8859_2; use mime; use super::*; @@ -223,7 +222,7 @@ mod tests { "application/json; charset=ISO-8859-2", ) .finish(); - assert_eq!(ISO_8859_2.name(), req.encoding().unwrap().name()); + assert_eq!(ISO_8859_2, req.encoding().unwrap()); } #[test] diff --git a/src/types/form.rs b/src/types/form.rs index 0bc6a0303..32d0edb69 100644 --- a/src/types/form.rs +++ b/src/types/form.rs @@ -5,9 +5,7 @@ use std::{fmt, ops}; use actix_http::{Error, HttpMessage, Payload}; use bytes::BytesMut; -use encoding::all::UTF_8; -use encoding::types::{DecoderTrap, Encoding}; -use encoding::EncodingRef; +use encoding_rs::{Encoding, UTF_8}; use futures::{Future, Poll, Stream}; use serde::de::DeserializeOwned; @@ -187,7 +185,7 @@ pub struct UrlEncoded { stream: Option>, limit: usize, length: Option, - encoding: EncodingRef, + encoding: &'static Encoding, err: Option, fut: Option>>, } @@ -286,13 +284,14 @@ where } }) .and_then(move |body| { - if (encoding as *const Encoding) == UTF_8 { + if encoding == UTF_8 { serde_urlencoded::from_bytes::(&body) .map_err(|_| UrlencodedError::Parse) } else { let body = encoding - .decode(&body, DecoderTrap::Strict) - .map_err(|_| UrlencodedError::Parse)?; + .decode_without_bom_handling_and_without_replacement(&body) + .map(|s| s.into_owned()) + .ok_or(UrlencodedError::Parse)?; serde_urlencoded::from_str::(&body) .map_err(|_| UrlencodedError::Parse) } diff --git a/src/types/payload.rs b/src/types/payload.rs index 8e4dd7030..a8e85e4f3 100644 --- a/src/types/payload.rs +++ b/src/types/payload.rs @@ -4,8 +4,7 @@ use std::str; use actix_http::error::{Error, ErrorBadRequest, PayloadError}; use actix_http::HttpMessage; use bytes::{Bytes, BytesMut}; -use encoding::all::UTF_8; -use encoding::types::{DecoderTrap, Encoding}; +use encoding_rs::UTF_8; use futures::future::{err, Either, FutureResult}; use futures::{Future, Poll, Stream}; use mime::Mime; @@ -208,15 +207,15 @@ impl FromRequest for String { .limit(limit) .from_err() .and_then(move |body| { - let enc: *const Encoding = encoding as *const Encoding; - if enc == UTF_8 { + if encoding == UTF_8 { Ok(str::from_utf8(body.as_ref()) .map_err(|_| ErrorBadRequest("Can not decode body"))? .to_owned()) } else { Ok(encoding - .decode(&body, DecoderTrap::Strict) - .map_err(|_| ErrorBadRequest("Can not decode body"))?) + .decode_without_bom_handling_and_without_replacement(&body) + .map(|s| s.into_owned()) + .ok_or_else(|| ErrorBadRequest("Can not decode body"))?) } }), )) diff --git a/src/types/readlines.rs b/src/types/readlines.rs index c23b84434..cea63e43b 100644 --- a/src/types/readlines.rs +++ b/src/types/readlines.rs @@ -1,9 +1,8 @@ +use std::borrow::Cow; use std::str; use bytes::{Bytes, BytesMut}; -use encoding::all::UTF_8; -use encoding::types::{DecoderTrap, Encoding}; -use encoding::EncodingRef; +use encoding_rs::{Encoding, UTF_8}; use futures::{Async, Poll, Stream}; use crate::dev::Payload; @@ -16,7 +15,7 @@ pub struct Readlines { buff: BytesMut, limit: usize, checked_buff: bool, - encoding: EncodingRef, + encoding: &'static Encoding, err: Option, } @@ -87,15 +86,17 @@ where if ind + 1 > self.limit { return Err(ReadlinesError::LimitOverflow); } - let enc: *const Encoding = self.encoding as *const Encoding; - let line = if enc == UTF_8 { + let line = if self.encoding == UTF_8 { str::from_utf8(&self.buff.split_to(ind + 1)) .map_err(|_| ReadlinesError::EncodingError)? .to_owned() } else { self.encoding - .decode(&self.buff.split_to(ind + 1), DecoderTrap::Strict) - .map_err(|_| ReadlinesError::EncodingError)? + .decode_without_bom_handling_and_without_replacement( + &self.buff.split_to(ind + 1), + ) + .map(Cow::into_owned) + .ok_or(ReadlinesError::EncodingError)? }; return Ok(Async::Ready(Some(line))); } @@ -117,15 +118,17 @@ where if ind + 1 > self.limit { return Err(ReadlinesError::LimitOverflow); } - let enc: *const Encoding = self.encoding as *const Encoding; - let line = if enc == UTF_8 { + let line = if self.encoding == UTF_8 { str::from_utf8(&bytes.split_to(ind + 1)) .map_err(|_| ReadlinesError::EncodingError)? .to_owned() } else { self.encoding - .decode(&bytes.split_to(ind + 1), DecoderTrap::Strict) - .map_err(|_| ReadlinesError::EncodingError)? + .decode_without_bom_handling_and_without_replacement( + &bytes.split_to(ind + 1), + ) + .map(Cow::into_owned) + .ok_or(ReadlinesError::EncodingError)? }; // extend buffer with rest of the bytes; self.buff.extend_from_slice(&bytes); @@ -143,15 +146,15 @@ where if self.buff.len() > self.limit { return Err(ReadlinesError::LimitOverflow); } - let enc: *const Encoding = self.encoding as *const Encoding; - let line = if enc == UTF_8 { + let line = if self.encoding == UTF_8 { str::from_utf8(&self.buff) .map_err(|_| ReadlinesError::EncodingError)? .to_owned() } else { self.encoding - .decode(&self.buff, DecoderTrap::Strict) - .map_err(|_| ReadlinesError::EncodingError)? + .decode_without_bom_handling_and_without_replacement(&self.buff) + .map(Cow::into_owned) + .ok_or(ReadlinesError::EncodingError)? }; self.buff.clear(); Ok(Async::Ready(Some(line))) From 47fab0e393802030808c842565c918c06c22c278 Mon Sep 17 00:00:00 2001 From: messense Date: Wed, 19 Jun 2019 18:41:42 +0800 Subject: [PATCH 09/11] Bump derive_more crate version to 0.15.0 in actix-cors (#927) --- actix-cors/CHANGES.md | 4 ++++ actix-cors/Cargo.toml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/actix-cors/CHANGES.md b/actix-cors/CHANGES.md index 1e842f37e..10e408ede 100644 --- a/actix-cors/CHANGES.md +++ b/actix-cors/CHANGES.md @@ -1,5 +1,9 @@ # Changes +## [0.1.1] - unreleased + +* Bump `derive_more` crate version to 0.15.0 + ## [0.1.0] - 2019-06-15 * Move cors middleware to separate crate diff --git a/actix-cors/Cargo.toml b/actix-cors/Cargo.toml index 98ed67a2a..091c94044 100644 --- a/actix-cors/Cargo.toml +++ b/actix-cors/Cargo.toml @@ -19,5 +19,5 @@ path = "src/lib.rs" [dependencies] actix-web = "1.0.0" actix-service = "0.4.0" -derive_more = "0.14.1" +derive_more = "0.15.0" futures = "0.1.25" From 1a24ff871728bacaf4853c4000a9d2be665abd56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Vis=C3=A9e?= Date: Fri, 21 Jun 2019 09:06:29 +0200 Subject: [PATCH 10/11] Add builder function for HTTP 429 Too Many Requests status (#931) --- actix-http/src/httpcodes.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/actix-http/src/httpcodes.rs b/actix-http/src/httpcodes.rs index e7eda2da8..3cac35eb7 100644 --- a/actix-http/src/httpcodes.rs +++ b/actix-http/src/httpcodes.rs @@ -61,6 +61,7 @@ impl Response { STATIC_RESP!(RangeNotSatisfiable, StatusCode::RANGE_NOT_SATISFIABLE); STATIC_RESP!(ExpectationFailed, StatusCode::EXPECTATION_FAILED); STATIC_RESP!(UnprocessableEntity, StatusCode::UNPROCESSABLE_ENTITY); + STATIC_RESP!(TooManyRequests, StatusCode::TOO_MANY_REQUESTS); STATIC_RESP!(InternalServerError, StatusCode::INTERNAL_SERVER_ERROR); STATIC_RESP!(NotImplemented, StatusCode::NOT_IMPLEMENTED); From b948f74b540c70036cef60d16cba554ffb71f0cd Mon Sep 17 00:00:00 2001 From: Dustin Bensing Date: Mon, 24 Jun 2019 03:16:04 +0200 Subject: [PATCH 11/11] Extractor configuration Migration (#937) added guide for Extractor configuration in MIGRATION.md --- MIGRATION.md | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/MIGRATION.md b/MIGRATION.md index 5273a0135..2f0f369ad 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -31,6 +31,64 @@ ## 1.0.0 +* Extractor configuration. In version 1.0 this is handled with the new `Data` mechanism for both setting and retrieving the configuration + + instead of + + ```rust + + #[derive(Default)] + struct ExtractorConfig { + config: String, + } + + impl FromRequest for YourExtractor { + type Config = ExtractorConfig; + type Result = Result; + + fn from_request(req: &HttpRequest, cfg: &Self::Config) -> Self::Result { + println!("use the config: {:?}", cfg.config); + ... + } + } + + App::new().resource("/route_with_config", |r| { + r.post().with_config(handler_fn, |cfg| { + cfg.0.config = "test".to_string(); + }) + }) + + ``` + + use the HttpRequest to get the configuration like any other `Data` with `req.app_data::()` and set it with the `data()` method on the `resource` + + ```rust + #[derive(Default)] + struct ExtractorConfig { + config: String, + } + + impl FromRequest for YourExtractor { + type Error = Error; + type Future = Result; + type Config = ExtractorConfig; + + fn from_request(req: &HttpRequest, payload: &mut Payload) -> Self::Future { + let cfg = req.app_data::(); + println!("config data?: {:?}", cfg.unwrap().role); + ... + } + } + + App::new().service( + resource("/route_with_config") + .data(ExtractorConfig { + config: "test".to_string(), + }) + .route(post().to(handler_fn)), + ) + ``` + * Resource registration. 1.0 version uses generalized resource registration via `.service()` method.