diff --git a/Cargo.toml b/Cargo.toml index 0ea803bb8..b074f2f72 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -88,7 +88,7 @@ actix-web-codegen = "0.4.0" actix-http = "2.2.0" awc = { version = "2.0.3", default-features = false } -bytes = "0.6" +bytes = "1" derive_more = "0.99.5" encoding_rs = "0.8" futures-channel = { version = "0.3.5", default-features = false } @@ -141,7 +141,6 @@ actix-tls = { git = "https://github.com/fakeshadow/actix-net.git", branch = "mio actix-connect = { git = "https://github.com/fakeshadow/actix-net.git", branch = "mio-0.7.3" } actix-utils = { git = "https://github.com/fakeshadow/actix-net.git", branch = "mio-0.7.3" } actix-codec = { git = "https://github.com/fakeshadow/actix-net.git", branch = "mio-0.7.3" } -h2 = { git = "https://github.com/hyperium/h2.git" } http = { git = "https://github.com/fakeshadow/http.git" } [[bench]] diff --git a/actix-files/CHANGES.md b/actix-files/CHANGES.md index 1b19ca8b2..e3f246488 100644 --- a/actix-files/CHANGES.md +++ b/actix-files/CHANGES.md @@ -1,7 +1,7 @@ # Changes ## Unreleased - 2020-xx-xx -* Update `Bytes` to 0.6. +* Update `bytes` to `1`. ## 0.4.1 - 2020-11-24 diff --git a/actix-files/Cargo.toml b/actix-files/Cargo.toml index 24634bd6a..3cd76215c 100644 --- a/actix-files/Cargo.toml +++ b/actix-files/Cargo.toml @@ -20,7 +20,7 @@ path = "src/lib.rs" actix-web = { version = "3.0.0", default-features = false } actix-service = "1.0.6" bitflags = "1" -bytes = "0.6" +bytes = "1" futures-core = { version = "0.3.7", default-features = false } futures-util = { version = "0.3.7", default-features = false, features = ["sink"] } derive_more = "0.99.2" diff --git a/actix-files/src/files.rs b/actix-files/src/files.rs index 642579cd5..a99b4699e 100644 --- a/actix-files/src/files.rs +++ b/actix-files/src/files.rs @@ -125,9 +125,8 @@ impl Files { /// Set custom directory renderer pub fn files_listing_renderer(mut self, f: F) -> Self where - for<'r, 's> F: - Fn(&'r Directory, &'s HttpRequest) -> Result - + 'static, + for<'r, 's> F: Fn(&'r Directory, &'s HttpRequest) -> Result + + 'static, { self.renderer = Rc::new(f); self @@ -201,11 +200,11 @@ impl Files { where F: IntoServiceFactory, U: ServiceFactory< - Config = (), - Request = ServiceRequest, - Response = ServiceResponse, - Error = Error, - > + 'static, + Config = (), + Request = ServiceRequest, + Response = ServiceResponse, + Error = Error, + > + 'static, { // create and configure default resource self.default = Rc::new(RefCell::new(Some(Rc::new(boxed::factory( diff --git a/actix-http-test/CHANGES.md b/actix-http-test/CHANGES.md index cf2f43308..01f6a4455 100644 --- a/actix-http-test/CHANGES.md +++ b/actix-http-test/CHANGES.md @@ -1,7 +1,7 @@ # Changes ## Unreleased - 2020-xx-xx -* Update `Bytes` to 0.6. +* Update `bytes` to `1`. ## 2.1.0 - 2020-11-25 diff --git a/actix-http-test/Cargo.toml b/actix-http-test/Cargo.toml index c08ac79cc..0655aabb8 100644 --- a/actix-http-test/Cargo.toml +++ b/actix-http-test/Cargo.toml @@ -39,9 +39,9 @@ actix-testing = "1.0.0" awc = "2.0.0" base64 = "0.13" -bytes = "0.6" +bytes = "1" futures-core = { version = "0.3.5", default-features = false } -http = "0.2.0" +http = "0.2.2" log = "0.4" socket2 = "0.3" serde = "1.0" diff --git a/actix-http/CHANGES.md b/actix-http/CHANGES.md index a2a849034..14c9adb70 100644 --- a/actix-http/CHANGES.md +++ b/actix-http/CHANGES.md @@ -3,6 +3,8 @@ ## Unreleased - 2020-xx-xx ### Changed * Bumped `rand` to `0.8` +* Upgrade `bytes` to `1` +* Upgrade `h2` to `0.3` ## 2.2.0 - 2020-11-25 ### Added diff --git a/actix-http/Cargo.toml b/actix-http/Cargo.toml index b6ed7be07..e6af20694 100644 --- a/actix-http/Cargo.toml +++ b/actix-http/Cargo.toml @@ -51,7 +51,7 @@ actix = { version = "0.10.0", optional = true } base64 = "0.13" bitflags = "1.2" -bytes = "0.6" +bytes = "1" cookie = { version = "0.14.1", features = ["percent-encode"] } copyless = "0.1.4" derive_more = "0.99.2" @@ -62,7 +62,7 @@ futures-core = { version = "0.3.5", default-features = false } futures-util = { version = "0.3.5", default-features = false, features = ["sink"] } fxhash = "0.2.1" h2 = "0.3.0" -http = "0.2.1" +http = "0.2.2" httparse = "1.3" indexmap = "1.3" itoa = "0.4" diff --git a/actix-http/src/client/connector.rs b/actix-http/src/client/connector.rs index 09cbf5b0f..e1aed6382 100644 --- a/actix-http/src/client/connector.rs +++ b/actix-http/src/client/connector.rs @@ -62,10 +62,10 @@ impl Connector<(), ()> { #[allow(clippy::new_ret_no_self, clippy::let_unit_value)] pub fn new() -> Connector< impl Service< - Request = TcpConnect, - Response = TcpConnection, - Error = actix_connect::ConnectError, - > + Clone, + Request = TcpConnect, + Response = TcpConnection, + Error = actix_connect::ConnectError, + > + Clone, TcpStream, > { Connector { @@ -117,10 +117,10 @@ impl Connector { where U1: AsyncRead + AsyncWrite + Unpin + fmt::Debug, T1: Service< - Request = TcpConnect, - Response = TcpConnection, - Error = actix_connect::ConnectError, - > + Clone, + Request = TcpConnect, + Response = TcpConnection, + Error = actix_connect::ConnectError, + > + Clone, { Connector { connector, @@ -135,10 +135,10 @@ impl Connector where U: AsyncRead + AsyncWrite + Unpin + fmt::Debug + 'static, T: Service< - Request = TcpConnect, - Response = TcpConnection, - Error = actix_connect::ConnectError, - > + Clone + Request = TcpConnect, + Response = TcpConnection, + Error = actix_connect::ConnectError, + > + Clone + 'static, { /// Connection timeout, i.e. max time to connect to remote host including dns name resolution. diff --git a/actix-http/src/client/pool.rs b/actix-http/src/client/pool.rs index 93bab6c9c..d1125e4ea 100644 --- a/actix-http/src/client/pool.rs +++ b/actix-http/src/client/pool.rs @@ -388,8 +388,10 @@ where } } +#[pin_project::pin_project] struct CloseConnection { io: T, + #[pin] timeout: Sleep, } @@ -412,11 +414,11 @@ where type Output = (); fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<()> { - let this = self.get_mut(); + let this = self.project(); - match Pin::new(&mut this.timeout).poll(cx) { + match this.timeout.poll(cx) { Poll::Ready(_) => Poll::Ready(()), - Poll::Pending => match Pin::new(&mut this.io).poll_shutdown(cx) { + Poll::Pending => match Pin::new(this.io).poll_shutdown(cx) { Poll::Ready(_) => Poll::Ready(()), Poll::Pending => Poll::Pending, }, diff --git a/actix-http/src/h1/dispatcher.rs b/actix-http/src/h1/dispatcher.rs index 853d4eb86..5009fc892 100644 --- a/actix-http/src/h1/dispatcher.rs +++ b/actix-http/src/h1/dispatcher.rs @@ -108,6 +108,8 @@ where messages: VecDeque, ka_expire: Instant, + + #[pin] ka_timer: Option, io: Option, @@ -644,7 +646,7 @@ where // shutdown timeout if this.flags.contains(Flags::SHUTDOWN) { if let Some(interval) = this.codec.config().client_disconnect_timer() { - *this.ka_timer = Some(sleep_until(interval)); + this.ka_timer.set(Some(sleep_until(interval))); } else { this.flags.insert(Flags::READ_DISCONNECT); if let Some(mut payload) = this.payload.take() { @@ -657,12 +659,14 @@ where } } - match Pin::new(&mut this.ka_timer.as_mut().unwrap()).poll(cx) { + match this.ka_timer.as_mut().as_pin_mut().unwrap().poll(cx) { Poll::Ready(()) => { // if we get timeout during shutdown, drop connection if this.flags.contains(Flags::SHUTDOWN) { return Err(DispatchError::DisconnectTimeout); - } else if this.ka_timer.as_mut().unwrap().deadline() >= *this.ka_expire { + } else if this.ka_timer.as_mut().as_pin_mut().unwrap().deadline() + >= *this.ka_expire + { // check for any outstanding tasks if this.state.is_empty() && this.write_buf.is_empty() { if this.flags.contains(Flags::STARTED) { @@ -673,9 +677,15 @@ where if let Some(deadline) = this.codec.config().client_disconnect_timer() { - if let Some(mut timer) = this.ka_timer.as_mut() { + if let Some(timer) = this.ka_timer.as_mut().as_pin_mut() + { timer.reset(deadline); - let _ = Pin::new(&mut timer).poll(cx); + let _ = this + .ka_timer + .as_mut() + .as_pin_mut() + .unwrap() + .poll(cx); } } else { // no shutdown timeout, drop socket @@ -700,14 +710,15 @@ where } else if let Some(deadline) = this.codec.config().keep_alive_expire() { - if let Some(mut timer) = this.ka_timer.as_mut() { + if let Some(timer) = this.ka_timer.as_mut().as_pin_mut() { timer.reset(deadline); - let _ = Pin::new(&mut timer).poll(cx); + let _ = + this.ka_timer.as_mut().as_pin_mut().unwrap().poll(cx); } } - } else if let Some(mut timer) = this.ka_timer.as_mut() { + } else if let Some(timer) = this.ka_timer.as_mut().as_pin_mut() { timer.reset(*this.ka_expire); - let _ = Pin::new(&mut timer).poll(cx); + let _ = this.ka_timer.as_mut().as_pin_mut().unwrap().poll(cx); } } Poll::Pending => (), diff --git a/actix-http/src/h1/encoder.rs b/actix-http/src/h1/encoder.rs index b7648eff1..5fbf7c987 100644 --- a/actix-http/src/h1/encoder.rs +++ b/actix-http/src/h1/encoder.rs @@ -135,7 +135,7 @@ pub(crate) trait MessageType: Sized { let mut has_date = false; - let mut buf = dst.bytes_mut().as_mut_ptr() as *mut u8; + let mut buf = dst.chunk_mut().as_mut_ptr() as *mut u8; let mut remaining = dst.capacity() - dst.len(); // tracks bytes written since last buffer resize @@ -177,7 +177,7 @@ pub(crate) trait MessageType: Sized { // re-assign buf raw pointer since it's possible that the buffer was // reallocated and/or resized - buf = dst.bytes_mut().as_mut_ptr() as *mut u8; + buf = dst.chunk_mut().as_mut_ptr() as *mut u8; } // SAFETY: on each write, it is enough to ensure that the advancement of the @@ -224,7 +224,7 @@ pub(crate) trait MessageType: Sized { // re-assign buf raw pointer since it's possible that the buffer was // reallocated and/or resized - buf = dst.bytes_mut().as_mut_ptr() as *mut u8; + buf = dst.chunk_mut().as_mut_ptr() as *mut u8; } // SAFETY: on each write, it is enough to ensure that the advancement of diff --git a/actix-http/src/test.rs b/actix-http/src/test.rs index 5dc146b30..3f08bb7ee 100644 --- a/actix-http/src/test.rs +++ b/actix-http/src/test.rs @@ -358,11 +358,15 @@ impl AsyncRead for TestSeqBuffer { fn poll_read( self: Pin<&mut Self>, _: &mut Context<'_>, - buf: &mut [u8], - ) -> Poll> { - let r = self.get_mut().read(buf); + buf: &mut ReadBuf<'_>, + ) -> Poll> { + let dst = buf.initialize_unfilled(); + let r = self.get_mut().read(dst); match r { - Ok(n) => Poll::Ready(Ok(n)), + Ok(n) => { + buf.advance(n); + Poll::Ready(Ok(())) + } Err(err) if err.kind() == io::ErrorKind::WouldBlock => Poll::Pending, Err(err) => Poll::Ready(Err(err)), } diff --git a/actix-multipart/CHANGES.md b/actix-multipart/CHANGES.md index 174c4ddb7..7a148213f 100644 --- a/actix-multipart/CHANGES.md +++ b/actix-multipart/CHANGES.md @@ -2,7 +2,7 @@ ## Unreleased - 2020-xx-xx * Fix multipart consuming payload before header checks #1513 -* Update `Bytes` to 0.6 +* Update `bytes` to `1` ## 3.0.0 - 2020-09-11 diff --git a/actix-multipart/Cargo.toml b/actix-multipart/Cargo.toml index 40691e6a8..d651d8ee9 100644 --- a/actix-multipart/Cargo.toml +++ b/actix-multipart/Cargo.toml @@ -19,7 +19,8 @@ path = "src/lib.rs" actix-web = { version = "3.0.0", default-features = false } actix-service = "1.0.6" actix-utils = "2.0.0" -bytes = "0.6" + +bytes = "1" derive_more = "0.99.2" httparse = "1.3" futures-util = { version = "0.3.5", default-features = false } diff --git a/actix-web-actors/CHANGES.md b/actix-web-actors/CHANGES.md index 502685f1b..e07ec8608 100644 --- a/actix-web-actors/CHANGES.md +++ b/actix-web-actors/CHANGES.md @@ -2,7 +2,7 @@ ## Unreleased - 2020-xx-xx * Upgrade `pin-project` to `1.0`. -* Update `Bytes` to 0.6. +* Update `bytes` to `1`. ## 3.0.0 - 2020-09-11 * No significant changes from `3.0.0-beta.2`. diff --git a/actix-web-actors/Cargo.toml b/actix-web-actors/Cargo.toml index 6b6259843..29ab08eef 100644 --- a/actix-web-actors/Cargo.toml +++ b/actix-web-actors/Cargo.toml @@ -20,7 +20,7 @@ actix = "0.10.0" actix-web = { version = "3.0.0", default-features = false } actix-http = "2.0.0" actix-codec = "0.3.0" -bytes = "0.6" +bytes = "1" futures-channel = { version = "0.3.5", default-features = false } futures-core = { version = "0.3.5", default-features = false } pin-project = "1.0.0" diff --git a/awc/CHANGES.md b/awc/CHANGES.md index 8814259f8..0b348d845 100644 --- a/awc/CHANGES.md +++ b/awc/CHANGES.md @@ -2,7 +2,7 @@ ## Unreleased - 2020-xx-xx ### Changed -* Upgrade `bytes` to `0.6`. +* Upgrade `bytes` to `1`. * Bumped `rand` to `0.8` diff --git a/awc/Cargo.toml b/awc/Cargo.toml index c1b765a41..c8cf553f1 100644 --- a/awc/Cargo.toml +++ b/awc/Cargo.toml @@ -43,7 +43,7 @@ actix-http = "2.2.0" actix-rt = "1.0.0" base64 = "0.13" -bytes = "0.6" +bytes = "1" cfg-if = "1.0" derive_more = "0.99.2" futures-core = { version = "0.3.5", default-features = false } diff --git a/awc/src/sender.rs b/awc/src/sender.rs index 923d32a22..b5ff61da5 100644 --- a/awc/src/sender.rs +++ b/awc/src/sender.rs @@ -56,7 +56,8 @@ impl Into for PrepForSendingError { pub enum SendClientRequest { Fut( Pin>>>, - Option, + // FIXME: use a pinned Sleep instead of box. + Option>>, bool, ), Err(Option), @@ -68,7 +69,7 @@ impl SendClientRequest { response_decompress: bool, timeout: Option, ) -> SendClientRequest { - let delay = timeout.map(sleep); + let delay = timeout.map(|d| Box::pin(sleep(d))); SendClientRequest::Fut(send, delay, response_decompress) } } diff --git a/awc/src/ws.rs b/awc/src/ws.rs index dd43d08b3..eaa681344 100644 --- a/awc/src/ws.rs +++ b/awc/src/ws.rs @@ -71,7 +71,6 @@ impl WebsocketsRequest { { let mut err = None; - #[allow(clippy::field_reassign_with_default)] let mut head = { let mut head = RequestHead::default(); head.method = Method::GET; diff --git a/src/app.rs b/src/app.rs index e5e76b20c..8dd86f7ec 100644 --- a/src/app.rs +++ b/src/app.rs @@ -270,11 +270,11 @@ where where F: IntoServiceFactory, U: ServiceFactory< - Config = (), - Request = ServiceRequest, - Response = ServiceResponse, - Error = Error, - > + 'static, + Config = (), + Request = ServiceRequest, + Response = ServiceResponse, + Error = Error, + > + 'static, U::InitError: fmt::Debug, { // create and configure default resource diff --git a/src/config.rs b/src/config.rs index 3eea23ff0..01959daa1 100644 --- a/src/config.rs +++ b/src/config.rs @@ -107,12 +107,12 @@ impl AppService { ) where F: IntoServiceFactory, S: ServiceFactory< - Config = (), - Request = ServiceRequest, - Response = ServiceResponse, - Error = Error, - InitError = (), - > + 'static, + Config = (), + Request = ServiceRequest, + Response = ServiceResponse, + Error = Error, + InitError = (), + > + 'static, { self.services.push(( rdef, diff --git a/src/handler.rs b/src/handler.rs index 84c72a619..0dc06b3ce 100644 --- a/src/handler.rs +++ b/src/handler.rs @@ -156,10 +156,10 @@ impl Extract { impl ServiceFactory for Extract where S: Service< - Request = (T, HttpRequest), - Response = ServiceResponse, - Error = Infallible, - > + Clone, + Request = (T, HttpRequest), + Response = ServiceResponse, + Error = Infallible, + > + Clone, { type Request = ServiceRequest; type Response = ServiceResponse; @@ -185,10 +185,10 @@ pub struct ExtractService { impl Service for ExtractService where S: Service< - Request = (T, HttpRequest), - Response = ServiceResponse, - Error = Infallible, - > + Clone, + Request = (T, HttpRequest), + Response = ServiceResponse, + Error = Infallible, + > + Clone, { type Request = ServiceRequest; type Response = ServiceResponse; diff --git a/src/resource.rs b/src/resource.rs index 72617f21d..501e40174 100644 --- a/src/resource.rs +++ b/src/resource.rs @@ -347,11 +347,11 @@ where where F: IntoServiceFactory, U: ServiceFactory< - Config = (), - Request = ServiceRequest, - Response = ServiceResponse, - Error = Error, - > + 'static, + Config = (), + Request = ServiceRequest, + Response = ServiceResponse, + Error = Error, + > + 'static, U::InitError: fmt::Debug, { // create and configure default resource @@ -368,12 +368,12 @@ where impl HttpServiceFactory for Resource where T: ServiceFactory< - Config = (), - Request = ServiceRequest, - Response = ServiceResponse, - Error = Error, - InitError = (), - > + 'static, + Config = (), + Request = ServiceRequest, + Response = ServiceResponse, + Error = Error, + InitError = (), + > + 'static, { fn register(mut self, config: &mut AppService) { let guards = if self.guards.is_empty() { diff --git a/src/scope.rs b/src/scope.rs index 013b54756..681d142be 100644 --- a/src/scope.rs +++ b/src/scope.rs @@ -287,11 +287,11 @@ where where F: IntoServiceFactory, U: ServiceFactory< - Config = (), - Request = ServiceRequest, - Response = ServiceResponse, - Error = Error, - > + 'static, + Config = (), + Request = ServiceRequest, + Response = ServiceResponse, + Error = Error, + > + 'static, U::InitError: fmt::Debug, { // create and configure default resource @@ -410,12 +410,12 @@ where impl HttpServiceFactory for Scope where T: ServiceFactory< - Config = (), - Request = ServiceRequest, - Response = ServiceResponse, - Error = Error, - InitError = (), - > + 'static, + Config = (), + Request = ServiceRequest, + Response = ServiceResponse, + Error = Error, + InitError = (), + > + 'static, { fn register(mut self, config: &mut AppService) { // update default resource if needed diff --git a/src/service.rs b/src/service.rs index 11865fbcc..189ba5554 100644 --- a/src/service.rs +++ b/src/service.rs @@ -488,12 +488,12 @@ impl WebService { where F: IntoServiceFactory, T: ServiceFactory< - Config = (), - Request = ServiceRequest, - Response = ServiceResponse, - Error = Error, - InitError = (), - > + 'static, + Config = (), + Request = ServiceRequest, + Response = ServiceResponse, + Error = Error, + InitError = (), + > + 'static, { WebServiceImpl { srv: service.into_factory(), @@ -514,12 +514,12 @@ struct WebServiceImpl { impl HttpServiceFactory for WebServiceImpl where T: ServiceFactory< - Config = (), - Request = ServiceRequest, - Response = ServiceResponse, - Error = Error, - InitError = (), - > + 'static, + Config = (), + Request = ServiceRequest, + Response = ServiceResponse, + Error = Error, + InitError = (), + > + 'static, { fn register(mut self, config: &mut AppService) { let guards = if self.guards.is_empty() { diff --git a/src/types/json.rs b/src/types/json.rs index 95613a0ce..74138ca56 100644 --- a/src/types/json.rs +++ b/src/types/json.rs @@ -183,7 +183,7 @@ where let config = JsonConfig::from_req(req); let limit = config.limit; - let ctype = config.content_type.clone(); + let ctype = config.content_type.as_deref(); let err_handler = config.err_handler.clone(); JsonExtractFut { @@ -361,13 +361,13 @@ where pub fn new( req: &HttpRequest, payload: &mut Payload, - ctype: Option bool + Send + Sync>>, + ctype: Option<&(dyn Fn(mime::Mime) -> bool + Send + Sync)>, ) -> Self { // check content-type let json = if let Ok(Some(mime)) = req.mime_type() { mime.subtype() == mime::JSON || mime.suffix() == Some(mime::JSON) - || ctype.as_ref().map_or(false, |predicate| predicate(mime)) + || ctype.map_or(false, |predicate| predicate(mime)) } else { false }; diff --git a/tests/test_server.rs b/tests/test_server.rs index cd23e9fb1..2f8ce625e 100644 --- a/tests/test_server.rs +++ b/tests/test_server.rs @@ -45,7 +45,7 @@ const STR: &str = "Hello World Hello World Hello World Hello World Hello World \ struct TestBody { data: Bytes, chunk_size: usize, - delay: actix_rt::time::Sleep, + delay: Pin>, } impl TestBody { @@ -53,7 +53,7 @@ impl TestBody { TestBody { data, chunk_size, - delay: actix_rt::time::sleep(std::time::Duration::from_millis(10)), + delay: Box::pin(actix_rt::time::sleep(std::time::Duration::from_millis(10))), } } } @@ -67,7 +67,8 @@ impl futures_core::stream::Stream for TestBody { ) -> Poll> { ready!(Pin::new(&mut self.delay).poll(cx)); - self.delay = actix_rt::time::sleep(std::time::Duration::from_millis(10)); + self.delay = + Box::pin(actix_rt::time::sleep(std::time::Duration::from_millis(10))); let chunk_size = std::cmp::min(self.chunk_size, self.data.len()); let chunk = self.data.split_to(chunk_size); if chunk.is_empty() {