diff --git a/CHANGES.md b/CHANGES.md index 87729eb6a..a20713107 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,21 @@ # Changes -## [1.0.1] - 2019-06-xx +## [1.0.3] - unreleased + +### Changed + +* Use `encoding_rs` crate instead of unmaintained `encoding` crate + +## [1.0.2] - 2019-06-17 + +### Changed + +* Move cors middleware to `actix-cors` crate. + +* Move identity middleware to `actix-identity` crate. + + +## [1.0.1] - 2019-06-17 ### Add @@ -8,7 +23,7 @@ * Add `middleware::identity::RequestIdentity` trait to `get_identity` from `HttpMessage`. -### Changes +### Changed * Move cors middleware to `actix-cors` crate. @@ -38,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 @@ -56,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. @@ -71,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 8531a93ac..4f8cd745d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "actix-web" -version = "1.0.0" +version = "1.0.2" authors = ["Nikolay Kim "] description = "Actix web is a simple, pragmatic and extremely fast web framework for Rust." readme = "README.md" @@ -43,7 +43,7 @@ members = [ ] [features] -default = ["brotli", "flate2-zlib", "client", "fail", "depracated"] +default = ["brotli", "flate2-zlib", "client", "fail"] # http client client = ["awc"] @@ -68,31 +68,24 @@ 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.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" 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.14" -encoding = "0.2" +derive_more = "0.15.0" +encoding_rs = "0.8" futures = "0.1.25" -hashbrown = "0.3.1" +hashbrown = "0.5.0" log = "0.4" mime = "0.3" net2 = "0.2.33" @@ -110,8 +103,8 @@ 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-test = { version = "0.2.0", features=["ssl"] } +actix-http = { version = "0.2.4", features=["ssl", "brotli", "flate2-zlib"] } +actix-http-test = { version = "0.2.2", features=["ssl"] } rand = "0.6" env_logger = "0.6" serde_derive = "1.0" @@ -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/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. 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" 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-http/CHANGES.md b/actix-http/CHANGES.md index d0c75da76..891967f10 100644 --- a/actix-http/CHANGES.md +++ b/actix-http/CHANGES.md @@ -1,5 +1,18 @@ # Changes +## [0.2.5] - unreleased + +### Changed + +* Use `encoding_rs` crate instead of unmaintained `encoding` crate + +## [0.2.4] - 2019-06-16 + +### Fixed + +* Do not compress NoContent (204) responses #918 + + ## [0.2.3] - 2019-06-02 ### Added @@ -76,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 1847a5ba2..c3930a7a6 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" @@ -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" +encoding_rs = "0.8" 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..fa95d798a 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); 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); 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/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/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() } 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; 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))) 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"