rest: add cookie_from_header helper

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht 2022-01-31 15:50:23 +01:00
parent 5d74f79643
commit e5e48b01ad

View File

@ -201,6 +201,16 @@ pub fn extract_cookie(cookie: &str, cookie_name: &str) -> Option<String> {
None
}
/// Extract a specific cookie from a HeaderMap's "COOKIE" entry.
/// We assume cookie_name is already url encoded.
pub fn cookie_from_header(headers: &http::HeaderMap, cookie_name: &str) -> Option<String> {
if let Some(Ok(cookie)) = headers.get("COOKIE").map(|v| v.to_str()) {
extract_cookie(&cookie, cookie_name)
} else {
None
}
}
/// normalize uri path
///
/// Do not allow ".", "..", or hidden files ".XXXX"