Skip to content

Commit

Permalink
fix: fix expired cookie for cookie store
Browse files Browse the repository at this point in the history
  • Loading branch information
vicanso committed Oct 10, 2023
1 parent 38c0918 commit c9fd5fb
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
13 changes: 12 additions & 1 deletion src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ tauri-build = { version = "1.5.0", features = [] }
base64 = "0.21.4"
brotli-decompressor = "2.5.0"
chrono = "0.4.31"
cookie = "0.18.0"
cookie_store = "0.20.0"
hyper = { version = "0.14.27", features = ["client", "http1"] }
hyper-rustls = "0.24.1"
Expand Down
18 changes: 17 additions & 1 deletion src-tauri/src/cookies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,24 @@ pub fn clear_cookie_from_store() -> Result<(), CyberAPIError> {

pub fn save_cookie_store(set_cookies: Vec<String>, current_url: &Url) -> Result<(), CyberAPIError> {
let mut store = get_cookie_store();
let now = chrono::Local::now().timestamp();
for ele in set_cookies {
store.parse(ele.as_str(), current_url)?;
let c = cookie::Cookie::parse(&ele)?;
let mut expired = false;
if let Some(expires) = c.expires() {
if let Some(expired_time) = expires.datetime() {
expired = expired_time.unix_timestamp() < now;
}
}
if expired {
store.remove(
c.domain().unwrap_or_default(),
c.path().unwrap_or_default(),
c.name(),
);
} else {
store.parse(ele.as_str(), current_url)?;
}
}

save_store(store)?;
Expand Down
8 changes: 8 additions & 0 deletions src-tauri/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,11 @@ impl From<ZipError> for CyberAPIError {
}
}
}
impl From<cookie::ParseError> for CyberAPIError {
fn from(error: cookie::ParseError) -> Self {
CyberAPIError {
message: error.to_string(),
category: "cookie".to_string(),
}
}
}

0 comments on commit c9fd5fb

Please sign in to comment.