Merge pull request #6 from pxp9/main

Serde for CookieStoreMutex and CookieStoreRwlock
This commit is contained in:
pfernie 2023-08-28 20:32:33 -04:00 committed by GitHub
commit 7c7ca659e5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 0 deletions

View file

@ -16,11 +16,16 @@ categories = ["web-programming::http-client", "web-programming"] # https://crat
all-features = true
rustdoc-args = ["--cfg", "docsrs"]
[features]
serde = ["dep:serde" , "dep:serde_derive"]
[dependencies]
bytes = "1.0.1"
cookie_store = "^0.20"
reqwest = { version = "^0.11", default-features = false, features = ["cookies"] }
url = "2.2.2"
serde = {version = "1.0.147", optional = true}
serde_derive = {version = "1.0.147" , optional = true }
[dev-dependencies]
tokio-test = "0.4.1"

View file

@ -87,6 +87,8 @@ use std::{
use bytes::Bytes;
pub use cookie_store::{CookieStore, RawCookie, RawCookieParseError};
use reqwest::header::HeaderValue;
#[cfg(feature = "serde")]
use serde_derive::{Deserialize, Serialize};
use url;
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
/// async/concurrent contexts.
#[derive(Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct CookieStoreMutex(Mutex<CookieStore>);
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
/// async/concurrent contexts.
#[derive(Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct CookieStoreRwLock(RwLock<CookieStore>);
impl Default for CookieStoreRwLock {