mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-23 23:51:06 +01:00
update actix; prep release
This commit is contained in:
parent
8f97550c7a
commit
9b0a0f451b
@ -1,6 +1,10 @@
|
||||
# Changes
|
||||
|
||||
## 0.8.0-alpha.1 (2019-12-16)
|
||||
## [0.8.0] 2019-12-20
|
||||
|
||||
* Release
|
||||
|
||||
## [0.8.0-alpha.1] 2019-12-16
|
||||
|
||||
* Migrate to actix 0.9
|
||||
|
||||
|
10
Cargo.toml
10
Cargo.toml
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "actix-redis"
|
||||
version = "0.8.0-alpha.1"
|
||||
version = "0.8.0"
|
||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
||||
description = "Redis integration for actix framework"
|
||||
license = "MIT/Apache-2.0"
|
||||
@ -28,7 +28,7 @@ default = ["web"]
|
||||
web = ["actix/http", "actix-service", "actix-web", "actix-session/cookie-session", "rand", "serde", "serde_json"]
|
||||
|
||||
[dependencies]
|
||||
actix = "0.9.0-alpha.2"
|
||||
actix = "0.9.0"
|
||||
actix-utils = "1.0.3"
|
||||
|
||||
log = "0.4.6"
|
||||
@ -38,13 +38,13 @@ futures = "0.3.1"
|
||||
redis-async = "0.6.1"
|
||||
actix-rt = "1.0.0"
|
||||
time = "0.1.42"
|
||||
tokio = "0.2.4"
|
||||
tokio = "0.2.6"
|
||||
tokio-util = "0.2.0"
|
||||
|
||||
# actix web session
|
||||
actix-web = { version = "2.0.0-alpha.6", optional = true }
|
||||
actix-web = { version = "2.0.0-rc", optional = true }
|
||||
actix-service = { version = "1.0.0", optional = true }
|
||||
actix-session = { version = "0.3.0-alpha", optional = true }
|
||||
actix-session = { version = "0.3.0", optional = true }
|
||||
rand = { version = "0.7.0", optional = true }
|
||||
serde = { version = "1.0.101", optional = true, features = ["derive"] }
|
||||
serde_json = { version = "1.0.40", optional = true }
|
||||
|
@ -139,7 +139,7 @@ impl Handler<Command> for RedisActor {
|
||||
let _ = tx.send(Err(Error::NotConnected));
|
||||
}
|
||||
|
||||
Box::new(rx.map(|res| match res {
|
||||
Box::pin(rx.map(|res| match res {
|
||||
Ok(res) => res,
|
||||
Err(_) => Err(Error::Disconnected),
|
||||
}))
|
||||
|
124
src/session.rs
124
src/session.rs
@ -210,8 +210,7 @@ impl Inner {
|
||||
async fn load(
|
||||
&self,
|
||||
req: &ServiceRequest,
|
||||
) -> Result<Option<(HashMap<String, String>, String)>, Error>
|
||||
{
|
||||
) -> Result<Option<(HashMap<String, String>, String)>, Error> {
|
||||
if let Ok(cookies) = req.cookies() {
|
||||
for cookie in cookies.iter() {
|
||||
if cookie.name() == self.name {
|
||||
@ -220,45 +219,39 @@ impl Inner {
|
||||
if let Some(cookie) = jar.signed(&self.key).get(&self.name) {
|
||||
let value = cookie.value().to_owned();
|
||||
let cachekey = (self.cache_keygen)(&cookie.value());
|
||||
return
|
||||
match self.addr.send(Command(resp_array!["GET", cachekey]))
|
||||
.await {
|
||||
Err(e) => Err(Error::from(e)),
|
||||
Ok(res) => match res {
|
||||
Ok(val) => {
|
||||
match val {
|
||||
RespValue::Error(err) => {
|
||||
return Err(
|
||||
error::ErrorInternalServerError(
|
||||
err,
|
||||
),
|
||||
);
|
||||
}
|
||||
RespValue::SimpleString(s) => {
|
||||
if let Ok(val) =
|
||||
serde_json::from_str(&s)
|
||||
{
|
||||
return Ok(Some((val, value)));
|
||||
}
|
||||
}
|
||||
RespValue::BulkString(s) => {
|
||||
if let Ok(val) =
|
||||
serde_json::from_slice(&s)
|
||||
{
|
||||
return Ok(Some((val, value)));
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
return match self
|
||||
.addr
|
||||
.send(Command(resp_array!["GET", cachekey]))
|
||||
.await
|
||||
{
|
||||
Err(e) => Err(Error::from(e)),
|
||||
Ok(res) => match res {
|
||||
Ok(val) => {
|
||||
match val {
|
||||
RespValue::Error(err) => {
|
||||
return Err(
|
||||
error::ErrorInternalServerError(err),
|
||||
);
|
||||
}
|
||||
Ok(None)
|
||||
RespValue::SimpleString(s) => {
|
||||
if let Ok(val) = serde_json::from_str(&s) {
|
||||
return Ok(Some((val, value)));
|
||||
}
|
||||
}
|
||||
RespValue::BulkString(s) => {
|
||||
if let Ok(val) = serde_json::from_slice(&s) {
|
||||
return Ok(Some((val, value)));
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
Err(err) => {
|
||||
Err(error::ErrorInternalServerError(err))
|
||||
}
|
||||
},
|
||||
}
|
||||
Ok(None)
|
||||
}
|
||||
Err(err) => Err(error::ErrorInternalServerError(err)),
|
||||
},
|
||||
};
|
||||
} else {
|
||||
return Ok(None)
|
||||
return Ok(None);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -311,25 +304,26 @@ impl Inner {
|
||||
match serde_json::to_string(&state) {
|
||||
Err(e) => Err(e.into()),
|
||||
Ok(body) => {
|
||||
match self.addr
|
||||
match self
|
||||
.addr
|
||||
.send(Command(resp_array!["SET", cachekey, body, "EX", &self.ttl]))
|
||||
.await {
|
||||
Err(e) => Err(Error::from(e)),
|
||||
Ok(redis_result) => match redis_result {
|
||||
Ok(_) => {
|
||||
if let Some(jar) = jar {
|
||||
for cookie in jar.delta() {
|
||||
let val =
|
||||
HeaderValue::from_str(&cookie.to_string())?;
|
||||
res.headers_mut()
|
||||
.append(header::SET_COOKIE, val);
|
||||
}
|
||||
.await
|
||||
{
|
||||
Err(e) => Err(Error::from(e)),
|
||||
Ok(redis_result) => match redis_result {
|
||||
Ok(_) => {
|
||||
if let Some(jar) = jar {
|
||||
for cookie in jar.delta() {
|
||||
let val =
|
||||
HeaderValue::from_str(&cookie.to_string())?;
|
||||
res.headers_mut().append(header::SET_COOKIE, val);
|
||||
}
|
||||
Ok(res)
|
||||
}
|
||||
Err(err) => Err(error::ErrorInternalServerError(err)),
|
||||
},
|
||||
}
|
||||
Ok(res)
|
||||
}
|
||||
Err(err) => Err(error::ErrorInternalServerError(err)),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -338,20 +332,18 @@ impl Inner {
|
||||
async fn clear_cache(&self, key: String) -> Result<(), Error> {
|
||||
let cachekey = (self.cache_keygen)(&key);
|
||||
|
||||
match self.addr
|
||||
.send(Command(resp_array!["DEL", cachekey]))
|
||||
.await {
|
||||
Err(e) => Err(Error::from(e)),
|
||||
Ok(res) => {
|
||||
match res {
|
||||
// redis responds with number of deleted records
|
||||
Ok(RespValue::Integer(x)) if x > 0 => Ok(()),
|
||||
_ => Err(error::ErrorInternalServerError(
|
||||
"failed to remove session from cache",
|
||||
)),
|
||||
}
|
||||
match self.addr.send(Command(resp_array!["DEL", cachekey])).await {
|
||||
Err(e) => Err(Error::from(e)),
|
||||
Ok(res) => {
|
||||
match res {
|
||||
// redis responds with number of deleted records
|
||||
Ok(RespValue::Integer(x)) if x > 0 => Ok(()),
|
||||
_ => Err(error::ErrorInternalServerError(
|
||||
"failed to remove session from cache",
|
||||
)),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// invalidates session cookie
|
||||
|
Loading…
Reference in New Issue
Block a user