mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-27 09:42:57 +01:00
store cookies load state
This commit is contained in:
parent
2a319d733f
commit
51cd08ef57
@ -23,6 +23,7 @@ pub struct HttpRequest {
|
||||
headers: HeaderMap,
|
||||
params: Params,
|
||||
cookies: Vec<Cookie<'static>>,
|
||||
cookies_loaded: bool,
|
||||
extensions: Extensions,
|
||||
}
|
||||
|
||||
@ -40,6 +41,7 @@ impl HttpRequest {
|
||||
headers: headers,
|
||||
params: Params::empty(),
|
||||
cookies: Vec::new(),
|
||||
cookies_loaded: false,
|
||||
extensions: Extensions::new(),
|
||||
}
|
||||
}
|
||||
@ -53,6 +55,7 @@ impl HttpRequest {
|
||||
headers: HeaderMap::new(),
|
||||
params: Params::empty(),
|
||||
cookies: Vec::new(),
|
||||
cookies_loaded: false,
|
||||
extensions: Extensions::new(),
|
||||
}
|
||||
}
|
||||
@ -119,11 +122,14 @@ impl HttpRequest {
|
||||
/// Load cookies
|
||||
pub fn load_cookies(&mut self) -> Result<&Vec<Cookie>, CookieParseError>
|
||||
{
|
||||
if let Some(val) = self.headers.get(header::COOKIE) {
|
||||
let s = str::from_utf8(val.as_bytes())
|
||||
.map_err(CookieParseError::from)?;
|
||||
for cookie in s.split("; ") {
|
||||
self.cookies.push(Cookie::parse_encoded(cookie)?.into_owned());
|
||||
if !self.cookies_loaded {
|
||||
self.cookies_loaded = true;
|
||||
if let Some(val) = self.headers.get(header::COOKIE) {
|
||||
let s = str::from_utf8(val.as_bytes())
|
||||
.map_err(CookieParseError::from)?;
|
||||
for cookie in s.split("; ") {
|
||||
self.cookies.push(Cookie::parse_encoded(cookie)?.into_owned());
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(&self.cookies)
|
||||
|
Loading…
Reference in New Issue
Block a user