From: Thomas Lamprecht Date: Mon, 31 Jan 2022 14:50:23 +0000 (+0100) Subject: rest: add cookie_from_header helper X-Git-Tag: v2.2.1~433 X-Git-Url: https://git.proxmox.com/?a=commitdiff_plain;h=e5e48b01ade24fd854f6f81427b73243ba1344d7;p=proxmox-backup.git rest: add cookie_from_header helper Signed-off-by: Thomas Lamprecht --- diff --git a/proxmox-rest-server/src/lib.rs b/proxmox-rest-server/src/lib.rs index 474827a3..3f7afae6 100644 --- a/proxmox-rest-server/src/lib.rs +++ b/proxmox-rest-server/src/lib.rs @@ -201,6 +201,16 @@ pub fn extract_cookie(cookie: &str, cookie_name: &str) -> Option { 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 { + 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"