Merge pull request #6 from pxp9/main
Serde for CookieStoreMutex and CookieStoreRwlock
This commit is contained in:
commit
7c7ca659e5
2 changed files with 9 additions and 0 deletions
|
@ -16,11 +16,16 @@ categories = ["web-programming::http-client", "web-programming"] # https://crat
|
||||||
all-features = true
|
all-features = true
|
||||||
rustdoc-args = ["--cfg", "docsrs"]
|
rustdoc-args = ["--cfg", "docsrs"]
|
||||||
|
|
||||||
|
[features]
|
||||||
|
serde = ["dep:serde" , "dep:serde_derive"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bytes = "1.0.1"
|
bytes = "1.0.1"
|
||||||
cookie_store = "^0.20"
|
cookie_store = "^0.20"
|
||||||
reqwest = { version = "^0.11", default-features = false, features = ["cookies"] }
|
reqwest = { version = "^0.11", default-features = false, features = ["cookies"] }
|
||||||
url = "2.2.2"
|
url = "2.2.2"
|
||||||
|
serde = {version = "1.0.147", optional = true}
|
||||||
|
serde_derive = {version = "1.0.147" , optional = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
tokio-test = "0.4.1"
|
tokio-test = "0.4.1"
|
||||||
|
|
|
@ -87,6 +87,8 @@ use std::{
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
pub use cookie_store::{CookieStore, RawCookie, RawCookieParseError};
|
pub use cookie_store::{CookieStore, RawCookie, RawCookieParseError};
|
||||||
use reqwest::header::HeaderValue;
|
use reqwest::header::HeaderValue;
|
||||||
|
#[cfg(feature = "serde")]
|
||||||
|
use serde_derive::{Deserialize, Serialize};
|
||||||
use url;
|
use url;
|
||||||
|
|
||||||
fn set_cookies(
|
fn set_cookies(
|
||||||
|
@ -121,6 +123,7 @@ fn cookies(cookie_store: &CookieStore, url: &url::Url) -> Option<HeaderValue> {
|
||||||
/// A [`cookie_store::CookieStore`] wrapped internally by a [`std::sync::Mutex`], suitable for use in
|
/// A [`cookie_store::CookieStore`] wrapped internally by a [`std::sync::Mutex`], suitable for use in
|
||||||
/// async/concurrent contexts.
|
/// async/concurrent contexts.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub struct CookieStoreMutex(Mutex<CookieStore>);
|
pub struct CookieStoreMutex(Mutex<CookieStore>);
|
||||||
|
|
||||||
impl Default for CookieStoreMutex {
|
impl Default for CookieStoreMutex {
|
||||||
|
@ -164,6 +167,7 @@ impl reqwest::cookie::CookieStore for CookieStoreMutex {
|
||||||
/// A [`cookie_store::CookieStore`] wrapped internally by a [`std::sync::RwLock`], suitable for use in
|
/// A [`cookie_store::CookieStore`] wrapped internally by a [`std::sync::RwLock`], suitable for use in
|
||||||
/// async/concurrent contexts.
|
/// async/concurrent contexts.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub struct CookieStoreRwLock(RwLock<CookieStore>);
|
pub struct CookieStoreRwLock(RwLock<CookieStore>);
|
||||||
|
|
||||||
impl Default for CookieStoreRwLock {
|
impl Default for CookieStoreRwLock {
|
||||||
|
|
Loading…
Reference in a new issue