implement session update on certificate change in runtime

This commit is contained in:
yggverse 2024-11-29 17:54:37 +02:00
parent f4cb0c3bcc
commit c4c173f6cf
3 changed files with 113 additions and 36 deletions

24
src/client/session.rs Normal file
View file

@ -0,0 +1,24 @@
use super::Connection;
use std::{cell::RefCell, collections::HashMap, rc::Rc};
/// Request sessions holder for `Client` object
/// * useful to keep connections open and / or validate TLS certificate updates in runtime
pub struct Session {
index: RefCell<HashMap<String, Rc<Connection>>>,
}
impl Session {
pub fn new() -> Self {
Self {
index: RefCell::new(HashMap::new()),
}
}
pub fn get(&self, request: &str) -> Option<Rc<Connection>> {
self.index.borrow().get(request).cloned()
}
pub fn update(&self, request: String, connection: Rc<Connection>) -> Option<Rc<Connection>> {
self.index.borrow_mut().insert(request, connection)
}
}