mirror of
https://github.com/YGGverse/ggemini.git
synced 2026-03-31 17:15:31 +00:00
30 lines
790 B
Rust
30 lines
790 B
Rust
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 Default for Session {
|
|
fn default() -> Self {
|
|
Self::new()
|
|
}
|
|
}
|
|
|
|
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)
|
|
}
|
|
}
|