Skip to content

Commit

Permalink
Merge pull request #204 from myyrakle/feat/#200
Browse files Browse the repository at this point in the history
[#200] cookies 필드 추가 및 파싱 구현
  • Loading branch information
myyrakle authored Dec 23, 2024
2 parents e1518f2 + 660fd5e commit 24d602b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions rupring/src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions rupring/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ impl rupring::ParamStringDeserializer<SomeCustomType> for rupring::ParamString {
*/
use std::{collections::HashMap, panic::UnwindSafe, sync::Arc};

use hyper::header;

use crate::Method;

#[derive(Debug, Clone)]
Expand All @@ -95,11 +97,27 @@ pub struct Request {
pub path: String,
pub body: String,
pub headers: HashMap<String, String>,
pub cookies: HashMap<String, String>,
pub query_parameters: HashMap<String, Vec<String>>,
pub path_parameters: HashMap<String, String>,
pub(crate) di_context: Arc<crate::DIContext>,
}

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<T: BindFromRequest + Default>(&self) -> anyhow::Result<T> {
BindFromRequest::bind(self.clone())
Expand Down

0 comments on commit 24d602b

Please sign in to comment.