1
0
mirror of https://github.com/actix/actix-extras.git synced 2025-06-26 10:27:42 +02:00

actix-web beta 15 updates (#216)

This commit is contained in:
Rob Ede
2021-12-18 03:37:23 +00:00
committed by GitHub
parent c047cd5653
commit 6676a50944
26 changed files with 101 additions and 82 deletions

View File

@ -1,6 +1,4 @@
use std::{
collections::HashSet, convert::TryInto, error::Error as StdError, iter::FromIterator, rc::Rc,
};
use std::{collections::HashSet, convert::TryInto, iter::FromIterator, rc::Rc};
use actix_utils::future::{self, Ready};
use actix_web::{
@ -490,8 +488,9 @@ impl<S, B> Transform<S, ServiceRequest> for Cors
where
S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
S::Future: 'static,
B: MessageBody + 'static,
B::Error: StdError,
B::Error: Into<Error>,
{
type Response = ServiceResponse<EitherBody<B>>;
type Error = Error;
@ -636,7 +635,7 @@ mod test {
#[actix_rt::test]
async fn middleware_generic_over_body_type() {
let srv = fn_service(|req: ServiceRequest| async move {
Ok(req.into_response(HttpResponse::Ok().message_body(body::None::new())?))
Ok(req.into_response(HttpResponse::with_body(StatusCode::OK, body::None::new())))
});
Cors::default().new_transform(srv).await.unwrap();

View File

@ -1,15 +1,14 @@
use std::{collections::HashSet, convert::TryInto, error::Error as StdError, rc::Rc};
use std::{collections::HashSet, convert::TryInto, rc::Rc};
use actix_utils::future::ok;
use actix_web::{
body::{EitherBody, MessageBody},
dev::{Service, ServiceRequest, ServiceResponse},
error::{Error, Result},
http::{
header::{self, HeaderValue},
Method,
},
HttpResponse,
Error, HttpResponse, Result,
};
use futures_util::future::{FutureExt as _, LocalBoxFuture};
use log::debug;
@ -138,8 +137,9 @@ impl<S, B> Service<ServiceRequest> for CorsMiddleware<S>
where
S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
S::Future: 'static,
B: MessageBody + 'static,
B::Error: StdError,
B::Error: Into<Error>,
{
type Response = ServiceResponse<EitherBody<B>>;
type Error = Error;
@ -172,7 +172,7 @@ where
if origin.is_some() {
Ok(Self::augment_response(&inner, res?))
} else {
res
res.map_err(Into::into)
}
.map(|res| res.map_into_left_body())
}