diff --git a/rupring/src/core/mod.rs b/rupring/src/core/mod.rs index d754af9..e5a39ea 100644 --- a/rupring/src/core/mod.rs +++ b/rupring/src/core/mod.rs @@ -525,9 +525,12 @@ where query_parameters, headers, path_parameters, + cookies: HashMap::new(), di_context: Arc::clone(&di_context), }; + request.parse_cookies_from_headers(); + let mut response = crate::Response::new(); // 3.5. middleware chain processing diff --git a/rupring/src/request.rs b/rupring/src/request.rs index fc1ef04..cbe4960 100644 --- a/rupring/src/request.rs +++ b/rupring/src/request.rs @@ -87,6 +87,8 @@ impl rupring::ParamStringDeserializer for rupring::ParamString { */ use std::{collections::HashMap, panic::UnwindSafe, sync::Arc}; +use hyper::header; + use crate::Method; #[derive(Debug, Clone)] @@ -95,11 +97,27 @@ pub struct Request { pub path: String, pub body: String, pub headers: HashMap, + pub cookies: HashMap, pub query_parameters: HashMap>, pub path_parameters: HashMap, pub(crate) di_context: Arc, } +impl Request { + pub fn parse_cookies_from_headers(&mut self) { + if let Some(cookie_header) = self.headers.get(header::COOKIE.as_str()) { + for cookie in cookie_header.split("; ") { + let mut parts = cookie.splitn(2, '='); + if let Some(key) = parts.next() { + if let Some(value) = parts.next() { + self.cookies.insert(key.to_string(), value.to_string()); + } + } + } + } + } +} + impl Request { pub fn bind(&self) -> anyhow::Result { BindFromRequest::bind(self.clone())