1
0
mirror of https://github.com/actix/actix-extras.git synced 2025-06-26 18:37:41 +02:00

migrate to actix-web beta 14 (#209)

This commit is contained in:
Rob Ede
2021-12-11 16:05:21 +00:00
committed by GitHub
parent 700d90b68b
commit 74ec115161
27 changed files with 134 additions and 128 deletions

View File

@ -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<EitherBody<B>>;
type Error = S::Error;
type InitError = ();
type Transform = CookieSessionMiddleware<S>;
@ -331,7 +331,7 @@ where
B: MessageBody + 'static,
B::Error: StdError,
{
type Response = ServiceResponse;
type Response = ServiceResponse<EitherBody<B>>;
type Error = S::Error;
type Future = LocalBoxFuture<'static, Result<Self::Response, Self::Error>>;
@ -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()

View File

@ -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::<u32>("key").unwrap();
assert_eq!(res, Some(10));
}
#[actix_web::test]
async fn purge_session() {
let req = test::TestRequest::default().to_srv_request();