]> git.proxmox.com Git - proxmox-backup.git/commitdiff
rest: add cookie_from_header helper
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Mon, 31 Jan 2022 14:50:23 +0000 (15:50 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 3 Feb 2022 12:12:02 +0000 (13:12 +0100)
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
proxmox-rest-server/src/lib.rs

index 474827a3ca0770f9d43ab8d44f45fc3d7de3972c..3f7afae668fa266692f63b0c28fa219ef448f455 100644 (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"