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

session, redis, and httpauth pre-v4 releases (#162)

This commit is contained in:
Rob Ede
2021-03-21 09:38:29 +00:00
committed by GitHub
parent 8d635f71fb
commit 5a72dd33d5
18 changed files with 113 additions and 159 deletions

View File

@ -1,11 +1,16 @@
# Changes
## Unreleased - 2020-xx-xx
## 0.9.2 - 2020-03-21
* Implement `std::error::Error` for `Error` [#135]
* Allow the removal of Max-Age for session-only cookies. [#161]
[#135]: https://github.com/actix/actix-extras/pull/135
[#161]: https://github.com/actix/actix-extras/pull/161
## 0.9.1 - 2020-09-12
* Enforce minimum redis-async version of 0.6.3 to workaround breaking patch change.

View File

@ -1,8 +1,8 @@
[package]
name = "actix-redis"
version = "0.9.1"
version = "0.9.2"
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
description = "Redis integration for Actix web"
description = "Redis integration for Actix and session store for Actix Web"
license = "MIT OR Apache-2.0"
readme = "README.md"
keywords = ["actix", "redis", "async", "session"]
@ -38,10 +38,10 @@ actix-utils = "2.0.0"
log = "0.4.6"
backoff = "0.2.1"
derive_more = "0.99.2"
futures-util = { version = "0.3.5", default-features = false }
futures-util = { version = "0.3.7", default-features = false }
redis-async = "0.6.3"
actix-rt = "1.1.1"
time = "0.2.9"
time = "0.2.23"
tokio = "0.2.6"
tokio-util = "0.3.0"

View File

@ -1,21 +1,19 @@
# actix-redis
[![crates.io](https://img.shields.io/crates/v/actix-redis)](https://crates.io/crates/actix-redis)
[![Documentation](https://docs.rs/actix-redis/badge.svg)](https://docs.rs/actix-redis)
[![Dependency Status](https://deps.rs/crate/actix-redis/0.8.1/status.svg)](https://deps.rs/crate/actix-redis/0.8.1)
> Redis integration for Actix and session store for Actix Web.
[![crates.io](https://img.shields.io/crates/v/actix-redis?label=latest)](https://crates.io/crates/actix-redis)
[![Documentation](https://docs.rs/actix-redis/badge.svg?version=0.9.2)](https://docs.rs/actix-redis/0.9.2)
![Apache 2.0 or MIT licensed](https://img.shields.io/crates/l/actix-redis)
[![Join the chat at https://gitter.im/actix/actix](https://badges.gitter.im/actix/actix.svg)](https://gitter.im/actix/actix?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Dependency Status](https://deps.rs/crate/actix-redis/0.9.2/status.svg)](https://deps.rs/crate/actix-redis/0.9.2)
> Redis integration for actix framework.
## Documentation & Resources
## Documentation
- [API Documentation](https://docs.rs/actix-cors)
- [Example Project](https://github.com/actix/examples/tree/HEAD/session/redis-session)
- Minimum Supported Rust Version (MSRV): 1.42.0
* [API Documentation](https://actix.rs/actix-extras/actix_redis/)
* [Chat on gitter](https://gitter.im/actix/actix)
* Cargo package: [actix-redis](https://crates.io/crates/actix-redis)
* Minimum supported Rust version: 1.40 or later
## Redis session backend
## Redis Session Backend
Use redis as session storage.
@ -49,18 +47,3 @@ async fn main() -> std::io::Result {
.await
}
```
## License
This project is licensed under either of
* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or [https://www.apache.org/licenses/LICENSE-2.0](https://www.apache.org/licenses/LICENSE-2.0))
* MIT license ([LICENSE-MIT](LICENSE-MIT) or [https://opensource.org/licenses/MIT](https://opensource.org/licenses/MIT))
at your option.
## Code of Conduct
Contribution to the actix-redis crate is organized under the terms of the
Contributor Covenant, the maintainer of actix-redis, @fafhrd91, promises to
intervene to uphold that code of conduct.

View File

@ -1,11 +1,4 @@
//! Redis integration for Actix framework.
//!
//! ## Documentation
//! * [API Documentation (Development)](http://actix.github.io/actix-redis/actix_redis/)
//! * [API Documentation (Releases)](https://docs.rs/actix-redis/)
//! * [Chat on gitter](https://gitter.im/actix/actix)
//! * Cargo package: [actix-redis](https://crates.io/crates/actix-redis)
//! * Minimum supported Rust version: 1.40.0 or later
//! Redis integration for Actix and session store for Actix Web.
#![deny(rust_2018_idioms)]

View File

@ -43,62 +43,70 @@ impl RedisSession {
secure: false,
max_age: Some(Duration::days(7)),
same_site: None,
http_only: Some(true),
http_only: true,
}))
}
/// Set time to live in seconds for session value
/// Set time to live in seconds for session value.
pub fn ttl(mut self, ttl: u32) -> Self {
Rc::get_mut(&mut self.0).unwrap().ttl = format!("{}", ttl);
self
}
/// Set custom cookie name for session id
/// 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
}
/// Set custom cookie path
/// Set custom cookie path.
pub fn cookie_path(mut self, path: &str) -> Self {
Rc::get_mut(&mut self.0).unwrap().path = path.to_owned();
self
}
/// Set custom cookie domain
/// Set custom cookie domain.
pub fn cookie_domain(mut self, domain: &str) -> Self {
Rc::get_mut(&mut self.0).unwrap().domain = Some(domain.to_owned());
self
}
/// Set custom cookie secure
/// Set custom cookie secure.
///
/// If the `secure` field is set, a cookie will only be transmitted when the
/// connection is secure - i.e. `https`
/// connection is secure - i.e. `https`.
///
/// Default is false.
pub fn cookie_secure(mut self, secure: bool) -> Self {
Rc::get_mut(&mut self.0).unwrap().secure = secure;
self
}
/// Set custom cookie max-age
/// Use `None` for session-only cookies
/// Set custom cookie max-age.
///
/// Use `None` for session-only cookies.
pub fn cookie_max_age(mut self, max_age: impl Into<Option<Duration>>) -> Self {
Rc::get_mut(&mut self.0).unwrap().max_age = max_age.into();
self
}
/// Set custom cookie SameSite
/// Set custom cookie `SameSite` attribute.
///
/// By default, the attribute is omitted.
pub fn cookie_same_site(mut self, same_site: SameSite) -> Self {
Rc::get_mut(&mut self.0).unwrap().same_site = Some(same_site);
self
}
/// Set custom cookie HttpOnly policy
/// Set custom cookie `HttpOnly` policy.
///
/// Default is true.
pub fn cookie_http_only(mut self, http_only: bool) -> Self {
Rc::get_mut(&mut self.0).unwrap().http_only = Some(http_only);
Rc::get_mut(&mut self.0).unwrap().http_only = http_only;
self
}
/// Set a custom cache key generation strategy, expecting session key as input
/// Set a custom cache key generation strategy, expecting session key as input.
pub fn cache_keygen(mut self, keygen: Box<dyn Fn(&str) -> String>) -> Self {
Rc::get_mut(&mut self.0).unwrap().cache_keygen = keygen;
self
@ -214,7 +222,7 @@ struct Inner {
secure: bool,
max_age: Option<Duration>,
same_site: Option<SameSite>,
http_only: Option<bool>,
http_only: bool,
}
impl Inner {
@ -293,7 +301,7 @@ impl Inner {
let mut cookie = Cookie::new(self.name.clone(), value.clone());
cookie.set_path(self.path.clone());
cookie.set_secure(self.secure);
cookie.set_http_only(self.http_only.unwrap_or(true));
cookie.set_http_only(self.http_only);
if let Some(ref domain) = self.domain {
cookie.set_domain(domain.clone());