Import and update the file service application and orizentic #72

Merged
savanni merged 36 commits from file-service into main 2023-10-03 23:50:54 +00:00
1 changed files with 0 additions and 61 deletions
Showing only changes of commit f7403b43a3 - Show all commits

View File

@ -1,61 +0,0 @@
use iron::headers;
use std::collections::HashMap;
#[derive(Clone, Debug)]
pub struct Cookie {
pub name: String,
pub value: String,
}
impl From<&str> for Cookie {
fn from(s: &str) -> Cookie {
let parts: Vec<&str> = s.split("=").collect();
Cookie {
name: String::from(parts[0]),
value: String::from(parts[1]),
}
}
}
impl From<&String> for Cookie {
fn from(s: &String) -> Cookie {
Cookie::from(s.as_str())
}
}
impl From<String> for Cookie {
fn from(s: String) -> Cookie {
Cookie::from(s.as_str())
}
}
#[derive(Debug)]
pub struct CookieJar(HashMap<String, Cookie>);
impl CookieJar {
pub fn new() -> CookieJar {
CookieJar(HashMap::new())
}
pub fn add_cookie(&mut self, name: String, value: Cookie) {
self.0.insert(name, value);
}
pub fn lookup(&self, name: &str) -> Option<&Cookie> {
self.0.get(name)
}
}
// Some(Cookie(["auth=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJqdGkiOiJhYzNhNDZjNi0zZmExLTRkMGEtYWYxMi1lN2QzZmVmZGM4NzgiLCJhdWQiOiJzYXZhbm5pIiwiZXhwIjoxNjIxMzUxNDM2LCJpc3MiOiJzYXZhbm5pIiwiaWF0IjoxNTg5NzI5MDM2LCJzdWIiOiJodHRwczovL3NhdmFubmkubHVtaW5lc2NlbnQtZHJlYW1zLmNvbS9maWxlLXNlcnZpY2UvIiwicGVybXMiOlsiYWRtaW4iXX0.8zjAbZ7Ut0d6EcDeyik39GKhXvH4qkMDdaiQVNKWiuM"]))
impl From<&headers::Cookie> for CookieJar {
fn from(c: &headers::Cookie) -> CookieJar {
let jar = CookieJar::new();
let headers::Cookie(cs) = c;
cs.iter().fold(jar, |mut jar, c_| {
let cookie = Cookie::from(c_);
jar.add_cookie(cookie.name.clone(), cookie);
jar
})
}
}