mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-28 01:32:57 +01:00
session code cleanup
This commit is contained in:
parent
7910c7b511
commit
5b9b8c6dd9
@ -27,11 +27,7 @@ pub struct RedisSession {
|
||||
impl SessionImpl for RedisSession {
|
||||
|
||||
fn get(&self, key: &str) -> Option<&str> {
|
||||
if let Some(s) = self.state.get(key) {
|
||||
Some(s)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
self.state.get(key).map(|s| s.as_str())
|
||||
}
|
||||
|
||||
fn set(&mut self, key: &str, value: String) {
|
||||
@ -88,6 +84,7 @@ impl RedisSessionBackend {
|
||||
self
|
||||
}
|
||||
|
||||
/// Set custom cookie name for session id
|
||||
pub fn cookie_name(mut self, name: &str) -> Self {
|
||||
Rc::get_mut(&mut self.0).unwrap().name = name.to_owned();
|
||||
self
|
||||
@ -108,15 +105,13 @@ impl<S> SessionBackend<S> for RedisSessionBackend {
|
||||
changed: false,
|
||||
inner: inner,
|
||||
state: state,
|
||||
value: Some(value),
|
||||
}
|
||||
value: Some(value) }
|
||||
} else {
|
||||
RedisSession {
|
||||
changed: false,
|
||||
inner: inner,
|
||||
state: HashMap::new(),
|
||||
value: None,
|
||||
}
|
||||
value: None }
|
||||
}
|
||||
}))
|
||||
}
|
||||
@ -130,8 +125,10 @@ struct Inner {
|
||||
}
|
||||
|
||||
impl Inner {
|
||||
#[cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
|
||||
fn load<S>(&self, req: &mut HttpRequest<S>)
|
||||
-> Box<Future<Item=Option<(HashMap<String, String>, String)>, Error=Error>> {
|
||||
-> Box<Future<Item=Option<(HashMap<String, String>, String)>, Error=Error>>
|
||||
{
|
||||
if let Ok(cookies) = req.cookies() {
|
||||
for cookie in cookies {
|
||||
if cookie.name() == self.name {
|
||||
@ -142,8 +139,7 @@ impl Inner {
|
||||
return Box::new(
|
||||
self.addr.call_fut(Command(resp_array!["GET", cookie.value()]))
|
||||
.map_err(Error::from)
|
||||
.and_then(move |res| {
|
||||
match res {
|
||||
.and_then(move |res| match res {
|
||||
Ok(val) => {
|
||||
match val {
|
||||
RespValue::Error(err) =>
|
||||
@ -163,7 +159,6 @@ impl Inner {
|
||||
Ok(None)
|
||||
},
|
||||
Err(err) => Err(error::ErrorInternalServerError(err).into())
|
||||
}
|
||||
}))
|
||||
} else {
|
||||
return Box::new(FutOk(None))
|
||||
@ -198,13 +193,11 @@ impl Inner {
|
||||
Box::new(
|
||||
match serde_json::to_string(state) {
|
||||
Err(e) => Either::A(FutErr(e.into())),
|
||||
Ok(body) => {
|
||||
Either::B(
|
||||
Ok(body) => Either::B(
|
||||
self.addr.call_fut(
|
||||
Command(resp_array!["SET", value, body,"EX", &self.ttl]))
|
||||
.map_err(Error::from)
|
||||
.and_then(move |res| {
|
||||
match res {
|
||||
.and_then(move |res| match res {
|
||||
Ok(_) => {
|
||||
if let Some(jar) = jar {
|
||||
for cookie in jar.delta() {
|
||||
@ -216,9 +209,7 @@ impl Inner {
|
||||
Ok(resp)
|
||||
},
|
||||
Err(err) => Err(error::ErrorInternalServerError(err).into())
|
||||
}
|
||||
}))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user