From 74ec115161a72776ebaed11593ffc3b91ca44ba2 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Sat, 11 Dec 2021 16:05:21 +0000 Subject: [PATCH] migrate to actix-web beta 14 (#209) --- actix-cors/CHANGES.md | 3 ++ actix-cors/Cargo.toml | 2 +- actix-cors/src/builder.rs | 42 +++++++------------ actix-cors/src/error.rs | 18 ++++---- actix-cors/src/inner.rs | 5 ++- actix-cors/src/middleware.rs | 41 ++++++++++-------- actix-cors/tests/tests.rs | 5 ++- actix-identity/CHANGES.md | 3 ++ actix-identity/Cargo.toml | 5 ++- actix-identity/src/cookie.rs | 15 +++++-- actix-identity/src/identity.rs | 8 ++-- actix-identity/src/lib.rs | 8 +++- actix-identity/src/middleware.rs | 17 ++++---- actix-protobuf/CHANGES.md | 3 ++ actix-protobuf/Cargo.toml | 2 +- .../examples/prost-example/Cargo.toml | 2 +- actix-protobuf/src/lib.rs | 3 ++ actix-redis/CHANGES.md | 3 ++ actix-redis/Cargo.toml | 7 ++-- actix-redis/src/redis.rs | 10 ++--- actix-session/CHANGES.md | 4 ++ actix-session/Cargo.toml | 2 +- actix-session/src/cookie.rs | 12 +++--- actix-session/src/lib.rs | 22 +--------- actix-web-httpauth/CHANGES.md | 3 ++ actix-web-httpauth/Cargo.toml | 2 +- actix-web-httpauth/src/middleware.rs | 15 +++---- 27 files changed, 134 insertions(+), 128 deletions(-) diff --git a/actix-cors/CHANGES.md b/actix-cors/CHANGES.md index 24f57ac5e..cfcc4b73d 100644 --- a/actix-cors/CHANGES.md +++ b/actix-cors/CHANGES.md @@ -1,6 +1,9 @@ # Changes ## Unreleased - 2021-xx-xx +* Update `actix-web` dependency to `4.0.0.beta-14`. [#209] + +[#209]: https://github.com/actix/actix-extras/pull/209 ## 0.6.0-beta.4 - 2021-11-22 diff --git a/actix-cors/Cargo.toml b/actix-cors/Cargo.toml index ec388b3eb..862fd9366 100644 --- a/actix-cors/Cargo.toml +++ b/actix-cors/Cargo.toml @@ -19,7 +19,7 @@ path = "src/lib.rs" [dependencies] actix-service = "2.0.0" actix-utils = "3" -actix-web = { version = "4.0.0-beta.10", default-features = false } +actix-web = { version = "4.0.0-beta.14", default-features = false } derive_more = "0.99.5" futures-util = { version = "0.3.7", default-features = false } diff --git a/actix-cors/src/builder.rs b/actix-cors/src/builder.rs index da23d5196..6131fa297 100644 --- a/actix-cors/src/builder.rs +++ b/actix-cors/src/builder.rs @@ -4,11 +4,14 @@ use std::{ use actix_utils::future::{self, Ready}; use actix_web::{ - body::MessageBody, + body::{EitherBody, MessageBody}, dev::{RequestHead, Service, ServiceRequest, ServiceResponse, Transform}, - error::{Error, Result}, - http::{self, header::HeaderName, Error as HttpError, HeaderValue, Method, Uri}, - Either, + error::HttpError, + http::{ + header::{HeaderName, HeaderValue}, + Method, Uri, + }, + Either, Error, Result, }; use log::error; use once_cell::sync::Lazy; @@ -20,7 +23,7 @@ use crate::{AllOrSome, CorsError, CorsMiddleware, Inner, OriginFn}; /// Additionally, always causes first error (if any) to be reported during initialization. fn cors<'a>( inner: &'a mut Rc, - err: &Option>, + err: &Option>, ) -> Option<&'a mut Inner> { if err.is_some() { return None; @@ -74,7 +77,7 @@ static ALL_METHODS_SET: Lazy> = Lazy::new(|| { #[derive(Debug)] pub struct Cors { inner: Rc, - error: Option>, + error: Option>, } impl Cors { @@ -490,7 +493,7 @@ where B: MessageBody + 'static, B::Error: StdError, { - type Response = ServiceResponse; + type Response = ServiceResponse>; type Error = Error; type InitError = (); type Transform = CorsMiddleware; @@ -571,15 +574,13 @@ where #[cfg(test)] mod test { use std::convert::{Infallible, TryInto}; - use std::pin::Pin; - use std::task::{Context, Poll}; use actix_web::{ - body::{BodySize, MessageBody}, + body, dev::{fn_service, Transform}, - http::{HeaderName, StatusCode}, + http::{header::HeaderName, StatusCode}, test::{self, TestRequest}, - web::{Bytes, HttpResponse}, + web::HttpResponse, }; use super::*; @@ -634,23 +635,8 @@ mod test { #[actix_rt::test] async fn middleware_generic_over_body_type() { - struct Foo; - - impl MessageBody for Foo { - type Error = std::io::Error; - fn size(&self) -> BodySize { - BodySize::None - } - fn poll_next( - self: Pin<&mut Self>, - _: &mut Context<'_>, - ) -> Poll>> { - Poll::Ready(None) - } - } - let srv = fn_service(|req: ServiceRequest| async move { - Ok(req.into_response(HttpResponse::Ok().message_body(Foo)?)) + Ok(req.into_response(HttpResponse::Ok().message_body(body::None::new())?)) }); Cors::default().new_transform(srv).await.unwrap(); diff --git a/actix-cors/src/error.rs b/actix-cors/src/error.rs index 9caf9a4a8..5da672c81 100644 --- a/actix-cors/src/error.rs +++ b/actix-cors/src/error.rs @@ -7,35 +7,35 @@ use derive_more::{Display, Error}; #[non_exhaustive] pub enum CorsError { /// Allowed origin argument must not be wildcard (`*`). - #[display(fmt = "`allowed_origin` argument must not be wildcard (`*`).")] + #[display(fmt = "`allowed_origin` argument must not be wildcard (`*`)")] WildcardOrigin, /// Request header `Origin` is required but was not provided. - #[display(fmt = "Request header `Origin` is required but was not provided.")] + #[display(fmt = "Request header `Origin` is required but was not provided")] MissingOrigin, /// Request header `Access-Control-Request-Method` is required but is missing. - #[display(fmt = "Request header `Access-Control-Request-Method` is required but is missing.")] + #[display(fmt = "Request header `Access-Control-Request-Method` is required but is missing")] MissingRequestMethod, /// Request header `Access-Control-Request-Method` has an invalid value. - #[display(fmt = "Request header `Access-Control-Request-Method` has an invalid value.")] + #[display(fmt = "Request header `Access-Control-Request-Method` has an invalid value")] BadRequestMethod, /// Request header `Access-Control-Request-Headers` has an invalid value. - #[display(fmt = "Request header `Access-Control-Request-Headers` has an invalid value.")] + #[display(fmt = "Request header `Access-Control-Request-Headers` has an invalid value")] BadRequestHeaders, /// Origin is not allowed to make this request. - #[display(fmt = "Origin is not allowed to make this request.")] + #[display(fmt = "Origin is not allowed to make this request")] OriginNotAllowed, /// Request method is not allowed. - #[display(fmt = "Requested method is not allowed.")] + #[display(fmt = "Requested method is not allowed")] MethodNotAllowed, /// One or more request headers are not allowed. - #[display(fmt = "One or more request headers are not allowed.")] + #[display(fmt = "One or more request headers are not allowed")] HeadersNotAllowed, } @@ -45,6 +45,6 @@ impl ResponseError for CorsError { } fn error_response(&self) -> HttpResponse { - HttpResponse::with_body(StatusCode::BAD_REQUEST, self.to_string().into()) + HttpResponse::with_body(StatusCode::BAD_REQUEST, self.to_string()).map_into_boxed_body() } } diff --git a/actix-cors/src/inner.rs b/actix-cors/src/inner.rs index 6be83b322..6af485814 100644 --- a/actix-cors/src/inner.rs +++ b/actix-cors/src/inner.rs @@ -205,7 +205,10 @@ mod test { use actix_web::{ dev::Transform, - http::{header, HeaderValue, Method, StatusCode}, + http::{ + header::{self, HeaderValue}, + Method, StatusCode, + }, test::{self, TestRequest}, }; diff --git a/actix-cors/src/middleware.rs b/actix-cors/src/middleware.rs index a38cf524c..e07b7cbdf 100644 --- a/actix-cors/src/middleware.rs +++ b/actix-cors/src/middleware.rs @@ -1,8 +1,8 @@ use std::{collections::HashSet, convert::TryInto, error::Error as StdError, rc::Rc}; -use actix_utils::future::{ok, Either, Ready}; +use actix_utils::future::ok; use actix_web::{ - body::{AnyBody, MessageBody}, + body::{EitherBody, MessageBody}, dev::{Service, ServiceRequest, ServiceResponse}, error::{Error, Result}, http::{ @@ -11,7 +11,7 @@ use actix_web::{ }, HttpResponse, }; -use futures_util::future::{FutureExt as _, LocalBoxFuture, TryFutureExt as _}; +use futures_util::future::{FutureExt as _, LocalBoxFuture}; use log::debug; use crate::{builder::intersperse_header_values, AllOrSome, Inner}; @@ -134,11 +134,6 @@ impl CorsMiddleware { } } -type CorsMiddlewareServiceFuture = Either< - Ready>, - LocalBoxFuture<'static, Result>, ->; - impl Service for CorsMiddleware where S: Service, Error = Error>, @@ -146,9 +141,9 @@ where B: MessageBody + 'static, B::Error: StdError, { - type Response = ServiceResponse; + type Response = ServiceResponse>; type Error = Error; - type Future = CorsMiddlewareServiceFuture; + type Future = LocalBoxFuture<'static, Result>, Error>>; actix_service::forward_ready!(service); @@ -156,7 +151,7 @@ where if self.inner.preflight && req.method() == Method::OPTIONS { let inner = Rc::clone(&self.inner); let res = Self::handle_preflight(&inner, req); - Either::left(ok(res)) + ok(res.map_into_right_body()).boxed_local() } else { let origin = req.headers().get(header::ORIGIN).cloned(); @@ -164,27 +159,37 @@ where // Only check requests with a origin header. if let Err(err) = self.inner.validate_origin(req.head()) { debug!("origin validation failed; inner service is not called"); - return Either::left(ok(req.error_response(err))); + return ok(req.error_response(err).map_into_right_body()).boxed_local(); } } + let (req, pl) = req.into_parts(); + let req2 = req.clone(); + let req = ServiceRequest::from_parts(req, pl); + let inner = Rc::clone(&self.inner); let fut = self.service.call(req); - let res = async move { + async move { let res = fut.await; if origin.is_some() { - let res = res?; + let res = match res { + Ok(res) => res, + Err(err) => { + let res = HttpResponse::from_error(err); + let res = ServiceResponse::new(req2, res); + return Ok(res.map_into_right_body()); + } + }; + Ok(Self::augment_response(&inner, res)) } else { res } + .map(|res| res.map_into_left_body()) } - .map_ok(|res| res.map_body(|_, body| AnyBody::new_boxed(body))) - .boxed_local(); - - Either::right(res) + .boxed_local() } } } diff --git a/actix-cors/tests/tests.rs b/actix-cors/tests/tests.rs index 00d5a2f1c..6c82c2103 100644 --- a/actix-cors/tests/tests.rs +++ b/actix-cors/tests/tests.rs @@ -2,7 +2,10 @@ use actix_service::fn_service; use actix_utils::future::ok; use actix_web::{ dev::{ServiceRequest, Transform}, - http::{header, HeaderValue, Method, StatusCode}, + http::{ + header::{self, HeaderValue}, + Method, StatusCode, + }, test::{self, TestRequest}, HttpResponse, }; diff --git a/actix-identity/CHANGES.md b/actix-identity/CHANGES.md index b5df2f7a3..e09d72bbf 100644 --- a/actix-identity/CHANGES.md +++ b/actix-identity/CHANGES.md @@ -1,6 +1,9 @@ # Changes ## Unreleased - 2021-xx-xx +* Update `actix-web` dependency to `4.0.0.beta-14`. [#209] + +[#209]: https://github.com/actix/actix-extras/pull/209 ## 0.4.0-beta.4 - 2021-11-22 diff --git a/actix-identity/Cargo.toml b/actix-identity/Cargo.toml index 56020e1f5..941d5efbc 100644 --- a/actix-identity/Cargo.toml +++ b/actix-identity/Cargo.toml @@ -16,12 +16,13 @@ path = "src/lib.rs" [dependencies] actix-service = "2.0.0" actix-utils = "3" -actix-web = { version = "4.0.0-beta.10", default-features = false, features = ["cookies", "secure-cookies"] } +actix-web = { version = "4.0.0-beta.14", default-features = false, features = ["cookies", "secure-cookies"] } + futures-util = { version = "0.3.7", default-features = false } serde = "1.0" serde_json = "1.0" time = "0.2.23" [dev-dependencies] -actix-http = "3.0.0-beta.11" +actix-http = "3.0.0-beta.15" actix-rt = "2" diff --git a/actix-identity/src/cookie.rs b/actix-identity/src/cookie.rs index 91b889f55..bedef1a53 100644 --- a/actix-identity/src/cookie.rs +++ b/actix-identity/src/cookie.rs @@ -371,6 +371,7 @@ mod tests { use std::{borrow::Borrow, time::SystemTime}; use actix_web::{ + body::{BoxBody, EitherBody}, cookie::{Cookie, CookieJar, Key, SameSite}, dev::ServiceResponse, http::{header, StatusCode}, @@ -408,7 +409,7 @@ mod tests { } fn assert_login_cookie( - response: &mut ServiceResponse, + response: &mut ServiceResponse>, identity: &str, login_timestamp: LoginTimestampCheck, visit_timestamp: VisitTimeStampCheck, @@ -577,13 +578,19 @@ mod tests { jar.get(COOKIE_NAME).unwrap().clone() } - async fn assert_logged_in(response: ServiceResponse, identity: Option<&str>) { + async fn assert_logged_in( + response: ServiceResponse>, + identity: Option<&str>, + ) { let bytes = test::read_body(response).await; let resp: Option = serde_json::from_slice(&bytes[..]).unwrap(); assert_eq!(resp.as_ref().map(|s| s.borrow()), identity); } - fn assert_legacy_login_cookie(response: &mut ServiceResponse, identity: &str) { + fn assert_legacy_login_cookie( + response: &mut ServiceResponse>, + identity: &str, + ) { let mut cookies = CookieJar::new(); for cookie in response.headers().get_all(header::SET_COOKIE) { cookies.add(Cookie::parse(cookie.to_str().unwrap().to_string()).unwrap()); @@ -595,7 +602,7 @@ mod tests { assert_eq!(cookie.value(), identity); } - fn assert_no_login_cookie(response: &mut ServiceResponse) { + fn assert_no_login_cookie(response: &mut ServiceResponse>) { let mut cookies = CookieJar::new(); for cookie in response.headers().get_all(header::SET_COOKIE) { cookies.add(Cookie::parse(cookie.to_str().unwrap().to_string()).unwrap()); diff --git a/actix-identity/src/identity.rs b/actix-identity/src/identity.rs index 8c8075579..a2cf6bc8d 100644 --- a/actix-identity/src/identity.rs +++ b/actix-identity/src/identity.rs @@ -1,8 +1,8 @@ +use actix_utils::future::{ready, Ready}; use actix_web::{ dev::{Extensions, Payload}, Error, FromRequest, HttpRequest, }; -use actix_utils::future::{ready, Ready}; pub(crate) struct IdentityItem { pub(crate) id: Option, @@ -48,12 +48,12 @@ impl Identity { /// Return the claimed identity of the user associated request or `None` if no identity can be /// found associated with the request. pub fn identity(&self) -> Option { - Identity::get_identity(&self.0.extensions()) + Identity::get_identity(&self.0.req_data()) } /// Remember identity. pub fn remember(&self, identity: String) { - if let Some(id) = self.0.extensions_mut().get_mut::() { + if let Some(id) = self.0.req_data_mut().get_mut::() { id.id = Some(identity); id.changed = true; } @@ -61,7 +61,7 @@ impl Identity { /// This method is used to 'forget' the current identity on subsequent requests. pub fn forget(&self) { - if let Some(id) = self.0.extensions_mut().get_mut::() { + if let Some(id) = self.0.req_data_mut().get_mut::() { id.id = None; id.changed = true; } diff --git a/actix-identity/src/lib.rs b/actix-identity/src/lib.rs index 24391358a..b76d6f5ba 100644 --- a/actix-identity/src/lib.rs +++ b/actix-identity/src/lib.rs @@ -103,7 +103,11 @@ where mod tests { use std::time::SystemTime; - use actix_web::{dev::ServiceResponse, test, web, App, Error}; + use actix_web::{ + body::{BoxBody, EitherBody}, + dev::ServiceResponse, + test, web, App, Error, + }; use super::*; @@ -130,7 +134,7 @@ mod tests { f: F, ) -> impl actix_service::Service< actix_http::Request, - Response = ServiceResponse, + Response = ServiceResponse>, Error = Error, > { test::init_service( diff --git a/actix-identity/src/middleware.rs b/actix-identity/src/middleware.rs index 7bcfb61e8..b768e098e 100644 --- a/actix-identity/src/middleware.rs +++ b/actix-identity/src/middleware.rs @@ -2,11 +2,11 @@ use std::{error::Error as StdError, rc::Rc}; use actix_utils::future::{ready, Ready}; use actix_web::{ - body::{AnyBody, MessageBody}, + body::{EitherBody, MessageBody}, dev::{Service, ServiceRequest, ServiceResponse, Transform}, Error, HttpMessage, Result, }; -use futures_util::future::{FutureExt as _, LocalBoxFuture, TryFutureExt as _}; +use futures_util::future::{FutureExt as _, LocalBoxFuture}; use crate::{identity::IdentityItem, IdentityPolicy}; @@ -46,7 +46,7 @@ where B: MessageBody + 'static, B::Error: StdError, { - type Response = ServiceResponse; + type Response = ServiceResponse>; type Error = Error; type InitError = (); type Transform = IdentityServiceMiddleware; @@ -82,7 +82,7 @@ where B: MessageBody + 'static, B::Error: StdError, { - type Response = ServiceResponse; + type Response = ServiceResponse>; type Error = Error; type Future = LocalBoxFuture<'static, Result>; @@ -104,17 +104,16 @@ where if let Some(id) = id { match backend.to_response(id.id, id.changed, &mut res).await { - Ok(_) => Ok(res.map_body(|_, body| AnyBody::new_boxed(body))), - Err(e) => Ok(res.error_response(e)), + Ok(_) => Ok(res.map_into_left_body()), + Err(err) => Ok(res.error_response(err).map_into_right_body()), } } else { - Ok(res.map_body(|_, body| AnyBody::new_boxed(body))) + Ok(res.map_into_left_body()) } } - Err(err) => Ok(req.error_response(err)), + Err(err) => Ok(req.error_response(err).map_into_right_body()), } } - .map_ok(|res| res.map_body(|_, body| AnyBody::new_boxed(body))) .boxed_local() } } diff --git a/actix-protobuf/CHANGES.md b/actix-protobuf/CHANGES.md index 8763c0a4e..c52089463 100644 --- a/actix-protobuf/CHANGES.md +++ b/actix-protobuf/CHANGES.md @@ -1,6 +1,9 @@ # Changes ## Unreleased - 2021-xx-xx +* Update `actix-web` dependency to `4.0.0.beta-14`. [#209] + +[#209]: https://github.com/actix/actix-extras/pull/209 ## 0.7.0-beta.2 - 2021-10-21 diff --git a/actix-protobuf/Cargo.toml b/actix-protobuf/Cargo.toml index 0cf95e716..9eb490268 100644 --- a/actix-protobuf/Cargo.toml +++ b/actix-protobuf/Cargo.toml @@ -19,7 +19,7 @@ path = "src/lib.rs" [dependencies] actix-rt = "2" -actix-web = { version = "4.0.0-beta.10", default_features = false } +actix-web = { version = "4.0.0-beta.14", default_features = false } derive_more = "0.99.5" futures-util = { version = "0.3.7", default-features = false } prost = { version = "0.8", default_features = false } diff --git a/actix-protobuf/examples/prost-example/Cargo.toml b/actix-protobuf/examples/prost-example/Cargo.toml index 081f75795..a159eb349 100644 --- a/actix-protobuf/examples/prost-example/Cargo.toml +++ b/actix-protobuf/examples/prost-example/Cargo.toml @@ -8,7 +8,7 @@ authors = [ ] [dependencies] -actix-web = "4.0.0-beta.10" +actix-web = "4.0.0-beta.14" actix-protobuf = { path = "../../" } env_logger = "0.8" diff --git a/actix-protobuf/src/lib.rs b/actix-protobuf/src/lib.rs index 387abe926..63cef2da2 100644 --- a/actix-protobuf/src/lib.rs +++ b/actix-protobuf/src/lib.rs @@ -11,6 +11,7 @@ use std::{ }; use actix_web::{ + body::BoxBody, dev::Payload, error::PayloadError, http::header::{CONTENT_LENGTH, CONTENT_TYPE}, @@ -145,6 +146,8 @@ where } impl Responder for ProtoBuf { + type Body = BoxBody; + fn respond_to(self, _: &HttpRequest) -> HttpResponse { let mut buf = Vec::new(); match self.0.encode(&mut buf) { diff --git a/actix-redis/CHANGES.md b/actix-redis/CHANGES.md index 1a47f61b7..c41b64b1a 100644 --- a/actix-redis/CHANGES.md +++ b/actix-redis/CHANGES.md @@ -1,6 +1,9 @@ # Changes ## Unreleased - 2021-xx-xx +* Update `actix-web` dependency to `4.0.0.beta-14`. [#209] + +[#209]: https://github.com/actix/actix-extras/pull/209 ## 0.10.0-beta.3 - 2021-10-21 diff --git a/actix-redis/Cargo.toml b/actix-redis/Cargo.toml index c8e46fadb..b6b6d2dc7 100644 --- a/actix-redis/Cargo.toml +++ b/actix-redis/Cargo.toml @@ -32,7 +32,7 @@ web = [ actix = { version = "0.12.0", default-features = false } actix-rt = { version = "2.1", default-features = false } actix-service = "2.0.0" -actix-tls = { version = "3.0.0-rc.1", default-features = false, features = ["connect"] } +actix-tls = { version = "3.0.0-rc.2", default-features = false, features = ["connect"] } log = "0.4.6" backoff = "0.2.1" @@ -45,15 +45,14 @@ tokio = { version = "1", features = ["sync"] } tokio-util = "0.6.1" # actix-session -actix-web = { version = "4.0.0-beta.10", default_features = false, optional = true } +actix-web = { version = "4.0.0-beta.14", default_features = false, optional = true } actix-session = { version = "0.5.0-beta.4", optional = true } rand = { version = "0.8.0", optional = true } serde = { version = "1.0.101", optional = true } serde_json = { version = "1.0.40", optional = true } [dev-dependencies] -actix-test = "0.1.0-beta.5" -actix-http = "3.0.0-beta.11" +actix-test = "0.1.0-beta.8" actix-rt = "2.1" env_logger = "0.8" serde = { version = "1.0.101", features = ["derive"] } diff --git a/actix-redis/src/redis.rs b/actix-redis/src/redis.rs index 6cbc90996..979a941f0 100644 --- a/actix-redis/src/redis.rs +++ b/actix-redis/src/redis.rs @@ -3,8 +3,8 @@ use std::io; use actix::prelude::*; use actix_rt::net::TcpStream; -use actix_service::boxed::{service, BoxService}; -use actix_tls::connect::{ConnectError, ConnectInfo as Connect, Connection, Connector}; +use actix_service::boxed::{self, BoxService}; +use actix_tls::connect::{ConnectError, ConnectInfo, Connection, ConnectorService}; use backoff::backoff::Backoff; use backoff::ExponentialBackoff; use log::{error, info, warn}; @@ -27,7 +27,7 @@ impl Message for Command { /// Redis communication actor pub struct RedisActor { addr: String, - connector: BoxService, Connection, ConnectError>, + connector: BoxService, Connection, ConnectError>, backoff: ExponentialBackoff, cell: Option, RespCodec>>, queue: VecDeque>>, @@ -45,7 +45,7 @@ impl RedisActor { Supervisor::start(|_| RedisActor { addr, - connector: service(Connector::default().service()), + connector: boxed::service(ConnectorService::default()), cell: None, backoff, queue: VecDeque::new(), @@ -57,7 +57,7 @@ impl Actor for RedisActor { type Context = Context; fn started(&mut self, ctx: &mut Context) { - let req = Connect::new(self.addr.to_owned()); + let req = ConnectInfo::new(self.addr.to_owned()); self.connector .call(req) .into_actor(self) diff --git a/actix-session/CHANGES.md b/actix-session/CHANGES.md index 8a80e11db..1ad2520ea 100644 --- a/actix-session/CHANGES.md +++ b/actix-session/CHANGES.md @@ -1,6 +1,10 @@ # Changes ## Unreleased - 2021-xx-xx +* Update `actix-web` dependency to `4.0.0.beta-14`. [#209] +* Remove `UserSession` implementation for `RequestHead`. [#209] + +[#209]: https://github.com/actix/actix-extras/pull/209 ## 0.5.0-beta.4 - 2021-11-22 diff --git a/actix-session/Cargo.toml b/actix-session/Cargo.toml index 5ca7ad0b9..d82cf1109 100644 --- a/actix-session/Cargo.toml +++ b/actix-session/Cargo.toml @@ -20,7 +20,7 @@ cookie-session = ["actix-web/secure-cookies"] [dependencies] actix-service = "2.0.0" actix-utils = "3" -actix-web = { version = "4.0.0-beta.10", default_features = false, features = ["cookies"] } +actix-web = { version = "4.0.0-beta.14", default_features = false, features = ["cookies"] } derive_more = "0.99.5" futures-util = { version = "0.3.7", default-features = false } diff --git a/actix-session/src/cookie.rs b/actix-session/src/cookie.rs index 01888f494..504bf5367 100644 --- a/actix-session/src/cookie.rs +++ b/actix-session/src/cookie.rs @@ -4,10 +4,10 @@ use std::{collections::HashMap, error::Error as StdError, rc::Rc}; use actix_utils::future::{ok, Ready}; use actix_web::{ - body::{AnyBody, MessageBody}, + body::{EitherBody, MessageBody}, cookie::{Cookie, CookieJar, Key, SameSite}, dev::{Service, ServiceRequest, ServiceResponse, Transform}, - http::{header::SET_COOKIE, HeaderValue}, + http::header::{HeaderValue, SET_COOKIE}, Error, ResponseError, }; use derive_more::Display; @@ -303,7 +303,7 @@ where B: MessageBody + 'static, B::Error: StdError, { - type Response = ServiceResponse; + type Response = ServiceResponse>; type Error = S::Error; type InitError = (); type Transform = CookieSessionMiddleware; @@ -331,7 +331,7 @@ where B: MessageBody + 'static, B::Error: StdError, { - type Response = ServiceResponse; + type Response = ServiceResponse>; type Error = S::Error; type Future = LocalBoxFuture<'static, Result>; @@ -379,8 +379,8 @@ where }; match result { - Ok(()) => Ok(res.map_body(|_, body| AnyBody::new_boxed(body))), - Err(error) => Ok(res.error_response(error)), + Ok(()) => Ok(res.map_into_left_body()), + Err(error) => Ok(res.error_response(error).map_into_right_body()), } } .boxed_local() diff --git a/actix-session/src/lib.rs b/actix-session/src/lib.rs index 2989377eb..dd3eb1dcf 100644 --- a/actix-session/src/lib.rs +++ b/actix-session/src/lib.rs @@ -51,7 +51,7 @@ use std::{ use actix_utils::future::{ok, Ready}; use actix_web::{ - dev::{Extensions, Payload, RequestHead, ServiceRequest, ServiceResponse}, + dev::{Extensions, Payload, ServiceRequest, ServiceResponse}, Error, FromRequest, HttpMessage, HttpRequest, }; use serde::{de::DeserializeOwned, Serialize}; @@ -101,12 +101,6 @@ impl UserSession for ServiceRequest { } } -impl UserSession for RequestHead { - fn get_session(&self) -> Session { - Session::get_session(&mut *self.extensions_mut()) - } -} - /// Status of a [`Session`]. #[derive(PartialEq, Clone, Debug)] pub enum SessionStatus { @@ -355,20 +349,6 @@ mod tests { assert_eq!(res, Some(true)); } - #[actix_web::test] - async fn get_session_from_request_head() { - let mut req = test::TestRequest::default().to_srv_request(); - - Session::set_session( - &mut req, - vec![("key".to_string(), serde_json::to_string(&10).unwrap())], - ); - - let session = req.head_mut().get_session(); - let res = session.get::("key").unwrap(); - assert_eq!(res, Some(10)); - } - #[actix_web::test] async fn purge_session() { let req = test::TestRequest::default().to_srv_request(); diff --git a/actix-web-httpauth/CHANGES.md b/actix-web-httpauth/CHANGES.md index 3211a77f4..de65b0b48 100644 --- a/actix-web-httpauth/CHANGES.md +++ b/actix-web-httpauth/CHANGES.md @@ -1,6 +1,9 @@ # Changes ## Unreleased - 2021-xx-xx +* Update `actix-web` dependency to `4.0.0.beta-14`. [#209] + +[#209]: https://github.com/actix/actix-extras/pull/209 ## 0.6.0-beta.4 - 2021-11-22 diff --git a/actix-web-httpauth/Cargo.toml b/actix-web-httpauth/Cargo.toml index 53c05d236..581ca5c4c 100644 --- a/actix-web-httpauth/Cargo.toml +++ b/actix-web-httpauth/Cargo.toml @@ -20,7 +20,7 @@ path = "src/lib.rs" [dependencies] actix-service = "2.0.0" actix-utils = "3" -actix-web = { version = "4.0.0-beta.10", default_features = false } +actix-web = { version = "4.0.0-beta.14", default_features = false } base64 = "0.13" futures-util = { version = "0.3.7", default-features = false } diff --git a/actix-web-httpauth/src/middleware.rs b/actix-web-httpauth/src/middleware.rs index 987d46253..fa6d5651b 100644 --- a/actix-web-httpauth/src/middleware.rs +++ b/actix-web-httpauth/src/middleware.rs @@ -11,7 +11,7 @@ use std::{ }; use actix_web::{ - body::{AnyBody, MessageBody}, + body::{EitherBody, MessageBody}, dev::{Service, ServiceRequest, ServiceResponse, Transform}, Error, }; @@ -127,7 +127,7 @@ where B: MessageBody + 'static, B::Error: StdError, { - type Response = ServiceResponse; + type Response = ServiceResponse>; type Error = Error; type Transform = AuthenticationMiddleware; type InitError = (); @@ -162,9 +162,9 @@ where B: MessageBody + 'static, B::Error: StdError, { - type Response = ServiceResponse; + type Response = ServiceResponse>; type Error = S::Error; - type Future = LocalBoxFuture<'static, Result>; + type Future = LocalBoxFuture<'static, Result>; actix_service::forward_ready!(service); @@ -177,7 +177,7 @@ where let (req, credentials) = match Extract::::new(req).await { Ok(req) => req, Err((err, req)) => { - return Ok(req.error_response(err)); + return Ok(req.error_response(err).map_into_right_body()); } }; @@ -185,10 +185,7 @@ where // middleware to do their thing (eg. cors adding headers) let req = process_fn(req, credentials).await?; - service - .call(req) - .await - .map(|res| res.map_body(|_, body| AnyBody::new_boxed(body))) + service.call(req).await.map(|res| res.map_into_left_body()) } .boxed_local() }