mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-23 23:51:06 +01:00
session, redis, and httpauth pre-v4 releases (#162)
This commit is contained in:
parent
8d635f71fb
commit
5a72dd33d5
19
.github/workflows/msrv.yml
vendored
19
.github/workflows/msrv.yml
vendored
@ -35,24 +35,9 @@ jobs:
|
|||||||
profile: minimal
|
profile: minimal
|
||||||
override: true
|
override: true
|
||||||
|
|
||||||
- name: tests (1.40.0)
|
- name: tests
|
||||||
if: matrix.version == '1.40.0'
|
|
||||||
uses: actions-rs/cargo@v1
|
uses: actions-rs/cargo@v1
|
||||||
timeout-minutes: 40
|
timeout-minutes: 40
|
||||||
with:
|
with:
|
||||||
command: test
|
command: test
|
||||||
args: --package=actix-cors
|
args: --workspace --all-features --no-fail-fast -- --nocapture
|
||||||
--package=actix-identity
|
|
||||||
--package=actix-redis
|
|
||||||
--package=actix-session
|
|
||||||
--package=actix-web-httpauth
|
|
||||||
--all-features --no-fail-fast -- --nocapture
|
|
||||||
|
|
||||||
- name: tests (1.42.0)
|
|
||||||
if: matrix.version == '1.42.0'
|
|
||||||
uses: actions-rs/cargo@v1
|
|
||||||
timeout-minutes: 40
|
|
||||||
with:
|
|
||||||
command: test
|
|
||||||
args: --package=actix-protobuf
|
|
||||||
--all-features --no-fail-fast -- --nocapture
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
> A collection of additional crates supporting the [actix-web] and [actix] frameworks.
|
> A collection of additional crates supporting the [actix-web] and [actix] frameworks.
|
||||||
|
|
||||||
[![build status](https://github.com/actix/actix-extras/workflows/CI%20%28Linux%29/badge.svg?branch=master&event=push)](https://github.com/actix/actix-extras/actions)
|
[![build status](https://github.com/actix/actix-extras/workflows/CI%20%28Linux%29/badge.svg?branch=master&event=push)](https://github.com/actix/actix-extras/actions)
|
||||||
[![Join the chat at https://gitter.im/actix/actix-web](https://badges.gitter.im/actix/actix-web.svg)](https://gitter.im/actix/actix-web?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
[![Chat on Discord](https://img.shields.io/discord/771444961383153695?label=chat&logo=discord)](https://discord.gg/5Ux4QGChWc)
|
||||||
|
|
||||||
## Crates by @actix
|
## Crates by @actix
|
||||||
|
|
||||||
|
@ -2,15 +2,14 @@
|
|||||||
|
|
||||||
> Cross-origin resource sharing (CORS) for Actix Web.
|
> Cross-origin resource sharing (CORS) for Actix Web.
|
||||||
|
|
||||||
[![crates.io](https://img.shields.io/crates/v/actix-cors)](https://crates.io/crates/actix-cors)
|
[![crates.io](https://img.shields.io/crates/v/actix-cors?label=latest)](https://crates.io/crates/actix-cors)
|
||||||
[![Documentation](https://docs.rs/actix-cors/badge.svg?version=0.5.4)](https://docs.rs/actix-cors/0.5.4)
|
[![Documentation](https://docs.rs/actix-cors/badge.svg?version=0.5.4)](https://docs.rs/actix-cors/0.5.4)
|
||||||
![Apache 2.0 or MIT licensed](https://img.shields.io/crates/l/actix-cors)
|
![Apache 2.0 or MIT licensed](https://img.shields.io/crates/l/actix-cors)
|
||||||
[![Dependency Status](https://deps.rs/crate/actix-cors/0.5.4/status.svg)](https://deps.rs/crate/actix-cors/0.5.4)
|
[![Dependency Status](https://deps.rs/crate/actix-cors/0.5.4/status.svg)](https://deps.rs/crate/actix-cors/0.5.4)
|
||||||
[![Join the chat at https://gitter.im/actix/actix-web](https://badges.gitter.im/actix/actix-web.svg)](https://gitter.im/actix/actix-web?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
|
||||||
|
|
||||||
## Documentation & Resources
|
## Documentation & Resources
|
||||||
|
|
||||||
- [API Documentation](https://docs.rs/actix-cors/)
|
- [API Documentation](https://docs.rs/actix-cors)
|
||||||
- [Example Project](https://github.com/actix/examples/tree/master/security/web-cors)
|
- [Example Project](https://github.com/actix/examples/tree/master/security/web-cors)
|
||||||
- [Chat on Gitter](https://gitter.im/actix/actix-web)
|
- [Chat on Gitter](https://gitter.im/actix/actix-web)
|
||||||
- Minimum Supported Rust Version (MSRV): 1.42.0
|
- Minimum Supported Rust Version (MSRV): 1.42.0
|
||||||
|
@ -16,4 +16,4 @@
|
|||||||
* [API Documentation](https://docs.rs/actix-identity/)
|
* [API Documentation](https://docs.rs/actix-identity/)
|
||||||
* [Chat on gitter](https://gitter.im/actix/actix)
|
* [Chat on gitter](https://gitter.im/actix/actix)
|
||||||
* Cargo package: [actix-identity](https://crates.io/crates/actix-identity)
|
* Cargo package: [actix-identity](https://crates.io/crates/actix-identity)
|
||||||
* Minimum supported Rust version: 1.40 or later
|
* Minimum Supported Rust Version (MSRV): 1.42.0
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
> Protobuf support for actix-web framework.
|
> Protobuf support for actix-web framework.
|
||||||
|
|
||||||
* Minimum supported Rust version: 1.40.0 or later
|
* Minimum supported Rust version: 1.42.0 or later
|
||||||
|
|
||||||
## Example
|
## Example
|
||||||
|
|
||||||
|
@ -1,11 +1,16 @@
|
|||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
## Unreleased - 2020-xx-xx
|
## Unreleased - 2020-xx-xx
|
||||||
|
|
||||||
|
|
||||||
|
## 0.9.2 - 2020-03-21
|
||||||
* Implement `std::error::Error` for `Error` [#135]
|
* Implement `std::error::Error` for `Error` [#135]
|
||||||
* Allow the removal of Max-Age for session-only cookies. [#161]
|
* 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
|
[#161]: https://github.com/actix/actix-extras/pull/161
|
||||||
|
|
||||||
|
|
||||||
## 0.9.1 - 2020-09-12
|
## 0.9.1 - 2020-09-12
|
||||||
* Enforce minimum redis-async version of 0.6.3 to workaround breaking patch change.
|
* Enforce minimum redis-async version of 0.6.3 to workaround breaking patch change.
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "actix-redis"
|
name = "actix-redis"
|
||||||
version = "0.9.1"
|
version = "0.9.2"
|
||||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
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"
|
license = "MIT OR Apache-2.0"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
keywords = ["actix", "redis", "async", "session"]
|
keywords = ["actix", "redis", "async", "session"]
|
||||||
@ -38,10 +38,10 @@ actix-utils = "2.0.0"
|
|||||||
log = "0.4.6"
|
log = "0.4.6"
|
||||||
backoff = "0.2.1"
|
backoff = "0.2.1"
|
||||||
derive_more = "0.99.2"
|
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"
|
redis-async = "0.6.3"
|
||||||
actix-rt = "1.1.1"
|
actix-rt = "1.1.1"
|
||||||
time = "0.2.9"
|
time = "0.2.23"
|
||||||
tokio = "0.2.6"
|
tokio = "0.2.6"
|
||||||
tokio-util = "0.3.0"
|
tokio-util = "0.3.0"
|
||||||
|
|
||||||
|
@ -1,21 +1,19 @@
|
|||||||
# actix-redis
|
# actix-redis
|
||||||
|
|
||||||
[![crates.io](https://img.shields.io/crates/v/actix-redis)](https://crates.io/crates/actix-redis)
|
> Redis integration for Actix and session store for Actix Web.
|
||||||
[![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)
|
[![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)
|
![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/)
|
## Redis Session Backend
|
||||||
* [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
|
|
||||||
|
|
||||||
Use redis as session storage.
|
Use redis as session storage.
|
||||||
|
|
||||||
@ -49,18 +47,3 @@ async fn main() -> std::io::Result {
|
|||||||
.await
|
.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.
|
|
||||||
|
@ -1,11 +1,4 @@
|
|||||||
//! Redis integration for Actix framework.
|
//! Redis integration for Actix and session store for Actix Web.
|
||||||
//!
|
|
||||||
//! ## 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
|
|
||||||
|
|
||||||
#![deny(rust_2018_idioms)]
|
#![deny(rust_2018_idioms)]
|
||||||
|
|
||||||
|
@ -43,62 +43,70 @@ impl RedisSession {
|
|||||||
secure: false,
|
secure: false,
|
||||||
max_age: Some(Duration::days(7)),
|
max_age: Some(Duration::days(7)),
|
||||||
same_site: None,
|
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 {
|
pub fn ttl(mut self, ttl: u32) -> Self {
|
||||||
Rc::get_mut(&mut self.0).unwrap().ttl = format!("{}", ttl);
|
Rc::get_mut(&mut self.0).unwrap().ttl = format!("{}", ttl);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set custom cookie name for session id
|
/// Set custom cookie name for session ID.
|
||||||
pub fn cookie_name(mut self, name: &str) -> Self {
|
pub fn cookie_name(mut self, name: &str) -> Self {
|
||||||
Rc::get_mut(&mut self.0).unwrap().name = name.to_owned();
|
Rc::get_mut(&mut self.0).unwrap().name = name.to_owned();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set custom cookie path
|
/// Set custom cookie path.
|
||||||
pub fn cookie_path(mut self, path: &str) -> Self {
|
pub fn cookie_path(mut self, path: &str) -> Self {
|
||||||
Rc::get_mut(&mut self.0).unwrap().path = path.to_owned();
|
Rc::get_mut(&mut self.0).unwrap().path = path.to_owned();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set custom cookie domain
|
/// Set custom cookie domain.
|
||||||
pub fn cookie_domain(mut self, domain: &str) -> Self {
|
pub fn cookie_domain(mut self, domain: &str) -> Self {
|
||||||
Rc::get_mut(&mut self.0).unwrap().domain = Some(domain.to_owned());
|
Rc::get_mut(&mut self.0).unwrap().domain = Some(domain.to_owned());
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set custom cookie secure
|
/// Set custom cookie secure.
|
||||||
|
///
|
||||||
/// If the `secure` field is set, a cookie will only be transmitted when the
|
/// 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 {
|
pub fn cookie_secure(mut self, secure: bool) -> Self {
|
||||||
Rc::get_mut(&mut self.0).unwrap().secure = secure;
|
Rc::get_mut(&mut self.0).unwrap().secure = secure;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set custom cookie max-age
|
/// Set custom cookie max-age.
|
||||||
/// Use `None` for session-only cookies
|
///
|
||||||
|
/// Use `None` for session-only cookies.
|
||||||
pub fn cookie_max_age(mut self, max_age: impl Into<Option<Duration>>) -> Self {
|
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();
|
Rc::get_mut(&mut self.0).unwrap().max_age = max_age.into();
|
||||||
self
|
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 {
|
pub fn cookie_same_site(mut self, same_site: SameSite) -> Self {
|
||||||
Rc::get_mut(&mut self.0).unwrap().same_site = Some(same_site);
|
Rc::get_mut(&mut self.0).unwrap().same_site = Some(same_site);
|
||||||
self
|
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 {
|
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
|
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 {
|
pub fn cache_keygen(mut self, keygen: Box<dyn Fn(&str) -> String>) -> Self {
|
||||||
Rc::get_mut(&mut self.0).unwrap().cache_keygen = keygen;
|
Rc::get_mut(&mut self.0).unwrap().cache_keygen = keygen;
|
||||||
self
|
self
|
||||||
@ -214,7 +222,7 @@ struct Inner {
|
|||||||
secure: bool,
|
secure: bool,
|
||||||
max_age: Option<Duration>,
|
max_age: Option<Duration>,
|
||||||
same_site: Option<SameSite>,
|
same_site: Option<SameSite>,
|
||||||
http_only: Option<bool>,
|
http_only: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Inner {
|
impl Inner {
|
||||||
@ -293,7 +301,7 @@ impl Inner {
|
|||||||
let mut cookie = Cookie::new(self.name.clone(), value.clone());
|
let mut cookie = Cookie::new(self.name.clone(), value.clone());
|
||||||
cookie.set_path(self.path.clone());
|
cookie.set_path(self.path.clone());
|
||||||
cookie.set_secure(self.secure);
|
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 {
|
if let Some(ref domain) = self.domain {
|
||||||
cookie.set_domain(domain.clone());
|
cookie.set_domain(domain.clone());
|
||||||
|
@ -1,8 +1,14 @@
|
|||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
## Unreleased - 2020-xx-xx
|
## Unreleased - 2020-xx-xx
|
||||||
* `Session::set_session` takes a `IntoIterator` instead of `Iterator`
|
|
||||||
* Fix calls to `session.purge()` from paths other than the one specified in the cookie
|
|
||||||
|
## 0.4.1 - 2020-03-21
|
||||||
|
* `Session::set_session` takes a `IntoIterator` instead of `Iterator`. [#105]
|
||||||
|
* Fix calls to `session.purge()` from paths other than the one specified in the cookie. [#129]
|
||||||
|
|
||||||
|
[#105]: https://github.com/actix/actix-extras/pull/105
|
||||||
|
[#129]: https://github.com/actix/actix-extras/pull/129
|
||||||
|
|
||||||
|
|
||||||
## 0.4.0 - 2020-09-11
|
## 0.4.0 - 2020-09-11
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "actix-session"
|
name = "actix-session"
|
||||||
version = "0.4.0"
|
version = "0.4.1"
|
||||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
||||||
description = "Sessions for Actix web"
|
description = "Sessions for Actix web"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
@ -23,10 +23,10 @@ cookie-session = ["actix-web/secure-cookies"]
|
|||||||
actix-web = { version = "3.0.0", default_features = false }
|
actix-web = { version = "3.0.0", default_features = false }
|
||||||
actix-service = "1.0.6"
|
actix-service = "1.0.6"
|
||||||
derive_more = "0.99.2"
|
derive_more = "0.99.2"
|
||||||
futures-util = { version = "0.3.4", default-features = false }
|
futures-util = { version = "0.3.7", default-features = false }
|
||||||
serde = "1.0"
|
serde = "1.0"
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
time = { version = "0.2.7", default-features = false, features = ["std"] }
|
time = { version = "0.2.23", default-features = false, features = ["std"] }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
actix-rt = "1"
|
actix-rt = "1"
|
||||||
|
@ -1,19 +1,15 @@
|
|||||||
# actix-session
|
# actix-session
|
||||||
|
|
||||||
[![crates.io](https://img.shields.io/crates/v/actix-session)](https://crates.io/crates/actix-session)
|
> Sessions for Actix Web.
|
||||||
[![Documentation](https://docs.rs/actix-session/badge.svg)](https://docs.rs/actix-session)
|
|
||||||
[![Dependency Status](https://deps.rs/crate/actix-session/0.3.0/status.svg)](https://deps.rs/crate/actix-session/0.3.0)
|
[![crates.io](https://img.shields.io/crates/v/actix-session?label=latest)](https://crates.io/crates/actix-session)
|
||||||
[![Build Status](https://travis-ci.org/actix/actix-session.svg?branch=master)](https://travis-ci.org/actix/actix-session)
|
[![Documentation](https://docs.rs/actix-session/badge.svg?version=0.4.1)](https://docs.rs/actix-session/0.4.1)
|
||||||
[![codecov](https://codecov.io/gh/actix/actix-session/branch/master/graph/badge.svg)](https://codecov.io/gh/actix/actix-session)
|
|
||||||
![Apache 2.0 or MIT licensed](https://img.shields.io/crates/l/actix-session)
|
![Apache 2.0 or MIT licensed](https://img.shields.io/crates/l/actix-session)
|
||||||
[![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-session/0.4.1/status.svg)](https://deps.rs/crate/actix-session/0.4.1)
|
||||||
|
|
||||||
> Session for actix-web framework.
|
|
||||||
|
|
||||||
## Documentation & community resources
|
## Documentation & Resources
|
||||||
|
|
||||||
* [User Guide](https://actix.rs/docs/)
|
- [API Documentation](https://docs.rs/actix-session)
|
||||||
* [API Documentation](https://docs.rs/actix-session/)
|
- [Example Projects](https://github.com/actix/examples/tree/HEAD/session)
|
||||||
* [Chat on gitter](https://gitter.im/actix/actix)
|
- Minimum Supported Rust Version (MSRV): 1.42.0
|
||||||
* Cargo package: [actix-session](https://crates.io/crates/actix-session)
|
|
||||||
* Minimum supported Rust version: 1.40 or later
|
|
||||||
|
@ -1,19 +1,4 @@
|
|||||||
//! Cookie session.
|
//! Cookie based sessions. See docs for [`CookieSession`].
|
||||||
//!
|
|
||||||
//! [**CookieSession**](struct.CookieSession.html)
|
|
||||||
//! uses cookies as session storage. `CookieSession` creates sessions
|
|
||||||
//! which are limited to storing fewer than 4000 bytes of data, as the payload
|
|
||||||
//! must fit into a single cookie. An internal server error is generated if a
|
|
||||||
//! session contains more than 4000 bytes.
|
|
||||||
//!
|
|
||||||
//! A cookie may have a security policy of *signed* or *private*. Each has
|
|
||||||
//! a respective `CookieSession` constructor.
|
|
||||||
//!
|
|
||||||
//! A *signed* cookie may be viewed but not modified by the client. A *private*
|
|
||||||
//! cookie may neither be viewed nor modified by the client.
|
|
||||||
//!
|
|
||||||
//! The constructors take a key as an argument. This is the private key
|
|
||||||
//! for cookie session - when this value is changed, all session data is lost.
|
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
@ -180,7 +165,7 @@ impl CookieSessionInner {
|
|||||||
/// than 4000 bytes.
|
/// than 4000 bytes.
|
||||||
///
|
///
|
||||||
/// A cookie may have a security policy of *signed* or *private*. Each has a
|
/// A cookie may have a security policy of *signed* or *private*. Each has a
|
||||||
/// respective `CookieSessionBackend` constructor.
|
/// respective `CookieSession` constructor.
|
||||||
///
|
///
|
||||||
/// A *signed* cookie is stored on the client as plaintext alongside
|
/// A *signed* cookie is stored on the client as plaintext alongside
|
||||||
/// a signature such that the cookie may be viewed but not modified by the
|
/// a signature such that the cookie may be viewed but not modified by the
|
||||||
@ -198,9 +183,8 @@ impl CookieSessionInner {
|
|||||||
/// By default all cookies are percent encoded, but certain symbols may
|
/// By default all cookies are percent encoded, but certain symbols may
|
||||||
/// cause troubles when reading cookie, if they are not properly percent encoded.
|
/// cause troubles when reading cookie, if they are not properly percent encoded.
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Examples
|
||||||
///
|
/// ```
|
||||||
/// ```rust
|
|
||||||
/// use actix_session::CookieSession;
|
/// use actix_session::CookieSession;
|
||||||
/// use actix_web::{web, App, HttpResponse, HttpServer};
|
/// use actix_web::{web, App, HttpResponse, HttpServer};
|
||||||
///
|
///
|
||||||
@ -215,7 +199,7 @@ impl CookieSessionInner {
|
|||||||
pub struct CookieSession(Rc<CookieSessionInner>);
|
pub struct CookieSession(Rc<CookieSessionInner>);
|
||||||
|
|
||||||
impl CookieSession {
|
impl CookieSession {
|
||||||
/// Construct new *signed* `CookieSessionBackend` instance.
|
/// Construct new *signed* `CookieSession` instance.
|
||||||
///
|
///
|
||||||
/// Panics if key length is less than 32 bytes.
|
/// Panics if key length is less than 32 bytes.
|
||||||
pub fn signed(key: &[u8]) -> CookieSession {
|
pub fn signed(key: &[u8]) -> CookieSession {
|
||||||
@ -225,7 +209,7 @@ impl CookieSession {
|
|||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Construct new *private* `CookieSessionBackend` instance.
|
/// Construct new *private* `CookieSession` instance.
|
||||||
///
|
///
|
||||||
/// Panics if key length is less than 32 bytes.
|
/// Panics if key length is less than 32 bytes.
|
||||||
pub fn private(key: &[u8]) -> CookieSession {
|
pub fn private(key: &[u8]) -> CookieSession {
|
||||||
|
@ -1,18 +1,16 @@
|
|||||||
//! User sessions.
|
//! Sessions for Actix Web.
|
||||||
//!
|
//!
|
||||||
//! Actix provides a general solution for session management. Session
|
//! Provides a general solution for session management. Session middleware could provide different
|
||||||
//! middlewares could provide different implementations which could
|
//! implementations which could be accessed via general session API.
|
||||||
//! be accessed via general session api.
|
|
||||||
//!
|
//!
|
||||||
//! By default, only cookie session backend is implemented. Other
|
//! This crate provides a general solution for session management and includes a cookie backend.
|
||||||
//! backend implementations can be added.
|
//! Other backend implementations can be built to use persistent or key-value stores, for example.
|
||||||
//!
|
//!
|
||||||
//! In general, you insert a *session* middleware and initialize it
|
//! In general, some session middleware, such as a [`CookieSession`] is initialized and applied.
|
||||||
//! , such as a `CookieSessionBackend`. To access session data,
|
//! To access session data, the [`Session`] extractor must be used. This extractor allows reading
|
||||||
//! [*Session*](struct.Session.html) extractor must be used. Session
|
//! modifying session data.
|
||||||
//! extractor allows us to get or set session data.
|
|
||||||
//!
|
//!
|
||||||
//! ```rust,no_run
|
//! ```no_run
|
||||||
//! use actix_web::{web, App, HttpServer, HttpResponse, Error};
|
//! use actix_web::{web, App, HttpServer, HttpResponse, Error};
|
||||||
//! use actix_session::{Session, CookieSession};
|
//! use actix_session::{Session, CookieSession};
|
||||||
//!
|
//!
|
||||||
@ -20,7 +18,7 @@
|
|||||||
//! // access session data
|
//! // access session data
|
||||||
//! if let Some(count) = session.get::<i32>("counter")? {
|
//! if let Some(count) = session.get::<i32>("counter")? {
|
||||||
//! println!("SESSION value: {}", count);
|
//! println!("SESSION value: {}", count);
|
||||||
//! session.set("counter", count+1)?;
|
//! session.set("counter", count + 1)?;
|
||||||
//! } else {
|
//! } else {
|
||||||
//! session.set("counter", 1)?;
|
//! session.set("counter", 1)?;
|
||||||
//! }
|
//! }
|
||||||
@ -31,12 +29,11 @@
|
|||||||
//! #[actix_rt::main]
|
//! #[actix_rt::main]
|
||||||
//! async fn main() -> std::io::Result<()> {
|
//! async fn main() -> std::io::Result<()> {
|
||||||
//! HttpServer::new(
|
//! HttpServer::new(
|
||||||
//! || App::new().wrap(
|
//! || App::new()
|
||||||
//! CookieSession::signed(&[0; 32]) // <- create cookie based session middleware
|
//! // create cookie based session middleware
|
||||||
//! .secure(false)
|
//! .wrap(CookieSession::signed(&[0; 32]).secure(false))
|
||||||
//! )
|
//! .default_service(web::to(|| HttpResponse::Ok())))
|
||||||
//! .service(web::resource("/").to(|| HttpResponse::Ok())))
|
//! .bind(("127.0.0.1", 8080))?
|
||||||
//! .bind("127.0.0.1:59880")?
|
|
||||||
//! .run()
|
//! .run()
|
||||||
//! .await
|
//! .await
|
||||||
//! }
|
//! }
|
||||||
@ -44,17 +41,14 @@
|
|||||||
|
|
||||||
#![deny(rust_2018_idioms)]
|
#![deny(rust_2018_idioms)]
|
||||||
|
|
||||||
use std::cell::RefCell;
|
use std::{cell::RefCell, collections::HashMap, rc::Rc};
|
||||||
use std::collections::HashMap;
|
|
||||||
use std::rc::Rc;
|
|
||||||
|
|
||||||
use actix_web::dev::{
|
use actix_web::dev::{
|
||||||
Extensions, Payload, RequestHead, ServiceRequest, ServiceResponse,
|
Extensions, Payload, RequestHead, ServiceRequest, ServiceResponse,
|
||||||
};
|
};
|
||||||
use actix_web::{Error, FromRequest, HttpMessage, HttpRequest};
|
use actix_web::{Error, FromRequest, HttpMessage, HttpRequest};
|
||||||
use futures_util::future::{ok, Ready};
|
use futures_util::future::{ok, Ready};
|
||||||
use serde::de::DeserializeOwned;
|
use serde::{de::DeserializeOwned, Serialize};
|
||||||
use serde::Serialize;
|
|
||||||
|
|
||||||
#[cfg(feature = "cookie-session")]
|
#[cfg(feature = "cookie-session")]
|
||||||
mod cookie;
|
mod cookie;
|
||||||
@ -63,16 +57,14 @@ pub use crate::cookie::CookieSession;
|
|||||||
|
|
||||||
/// The high-level interface you use to modify session data.
|
/// The high-level interface you use to modify session data.
|
||||||
///
|
///
|
||||||
/// Session object could be obtained with
|
/// Session object is obtained with [`UserSession::get_session`]. The [`UserSession`] trait is
|
||||||
/// [`UserSession::get_session`](trait.UserSession.html#tymethod.get_session)
|
/// implemented for `HttpRequest`, `ServiceRequest`, and `RequestHead`.
|
||||||
/// method. The `UserSession` trait is implemented for `HttpRequest`, `ServiceRequest`, and
|
|
||||||
/// `RequestHead`.
|
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```
|
||||||
/// use actix_session::Session;
|
/// use actix_session::Session;
|
||||||
/// use actix_web::*;
|
/// use actix_web::Result;
|
||||||
///
|
///
|
||||||
/// fn index(session: Session) -> Result<&'static str> {
|
/// async fn index(session: Session) -> Result<&'static str> {
|
||||||
/// // access session data
|
/// // access session data
|
||||||
/// if let Some(count) = session.get::<i32>("counter")? {
|
/// if let Some(count) = session.get::<i32>("counter")? {
|
||||||
/// session.set("counter", count + 1)?;
|
/// session.set("counter", count + 1)?;
|
||||||
@ -82,11 +74,10 @@ pub use crate::cookie::CookieSession;
|
|||||||
///
|
///
|
||||||
/// Ok("Welcome!")
|
/// Ok("Welcome!")
|
||||||
/// }
|
/// }
|
||||||
/// # fn main() {}
|
|
||||||
/// ```
|
/// ```
|
||||||
pub struct Session(Rc<RefCell<SessionInner>>);
|
pub struct Session(Rc<RefCell<SessionInner>>);
|
||||||
|
|
||||||
/// Helper trait that allows to get session
|
/// Extraction of a [`Session`] object.
|
||||||
pub trait UserSession {
|
pub trait UserSession {
|
||||||
fn get_session(&self) -> Session;
|
fn get_session(&self) -> Session;
|
||||||
}
|
}
|
||||||
@ -188,12 +179,10 @@ impl Session {
|
|||||||
/// Values that match keys already existing on the session will be overwritten. Values should
|
/// Values that match keys already existing on the session will be overwritten. Values should
|
||||||
/// already be JSON serialized.
|
/// already be JSON serialized.
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Examples
|
||||||
///
|
|
||||||
/// ```
|
/// ```
|
||||||
/// # use actix_session::Session;
|
/// # use actix_session::Session;
|
||||||
/// # use actix_web::test;
|
/// # use actix_web::test;
|
||||||
/// #
|
|
||||||
/// let mut req = test::TestRequest::default().to_srv_request();
|
/// let mut req = test::TestRequest::default().to_srv_request();
|
||||||
///
|
///
|
||||||
/// Session::set_session(
|
/// Session::set_session(
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
## Unreleased - 2020-xx-xx
|
## Unreleased - 2020-xx-xx
|
||||||
|
|
||||||
|
|
||||||
|
## 0.5.1 - 2020-03-21
|
||||||
* Correct error handling when extracting auth details from request. [#128]
|
* Correct error handling when extracting auth details from request. [#128]
|
||||||
|
|
||||||
[#128]: https://github.com/actix/actix-web-httpauth/pull/128
|
[#128]: https://github.com/actix/actix-extras/pull/128
|
||||||
|
|
||||||
|
|
||||||
## 0.5.0 - 2020-09-11
|
## 0.5.0 - 2020-09-11
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "actix-web-httpauth"
|
name = "actix-web-httpauth"
|
||||||
version = "0.5.0"
|
version = "0.5.1"
|
||||||
authors = [
|
authors = [
|
||||||
"svartalf <self@svartalf.info>",
|
"svartalf <self@svartalf.info>",
|
||||||
"Yuki Okushi <huyuumi.dev@gmail.com>",
|
"Yuki Okushi <huyuumi.dev@gmail.com>",
|
||||||
@ -22,7 +22,7 @@ path = "src/lib.rs"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
actix-web = { version = "3.0.0", default_features = false }
|
actix-web = { version = "3.0.0", default_features = false }
|
||||||
base64 = "0.13"
|
base64 = "0.13"
|
||||||
futures-util = { version = "0.3", default-features = false }
|
futures-util = { version = "0.3.7", default-features = false }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
actix-cors = "0.5"
|
actix-cors = "0.5"
|
||||||
|
@ -2,12 +2,15 @@
|
|||||||
|
|
||||||
> HTTP authentication schemes for [actix-web](https://github.com/actix/actix-web).
|
> HTTP authentication schemes for [actix-web](https://github.com/actix/actix-web).
|
||||||
|
|
||||||
[![crates.io](https://img.shields.io/crates/v/actix-web-httpauth)](https://crates.io/crates/actix-web-httpauth)
|
[![crates.io](https://img.shields.io/crates/v/actix-web-httpauth?label=latest)](https://crates.io/crates/actix-web-httpauth)
|
||||||
[![Documentation](https://docs.rs/actix-web-httpauth/badge.svg)](https://docs.rs/actix-web-httpauth)
|
[![Documentation](https://docs.rs/actix-web-httpauth/badge.svg?version=0.5.1)](https://docs.rs/actix-web-httpauth/0.5.1)
|
||||||
[![Dependency Status](https://deps.rs/crate/actix-web-httpauth/0.5.0/status.svg)](https://deps.rs/crate/actix-web-httpauth/0.5.0)
|
|
||||||
![Apache 2.0 or MIT licensed](https://img.shields.io/crates/l/actix-web-httpauth)
|
![Apache 2.0 or MIT licensed](https://img.shields.io/crates/l/actix-web-httpauth)
|
||||||
[![Join the chat at https://gitter.im/actix/actix-web](https://badges.gitter.im/actix/actix-web.svg)](https://gitter.im/actix/actix-web?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
[![Dependency Status](https://deps.rs/crate/actix-web-httpauth/0.5.1/status.svg)](https://deps.rs/crate/actix-web-httpauth/0.5.1)
|
||||||
|
|
||||||
|
## Documentation & Resources
|
||||||
|
|
||||||
|
- [API Documentation](https://docs.rs/actix-cors)
|
||||||
|
- Minimum Supported Rust Version (MSRV): 1.42.0
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
- Typed [Authorization] and [WWW-Authenticate] headers
|
- Typed [Authorization] and [WWW-Authenticate] headers
|
||||||
|
Loading…
Reference in New Issue
Block a user