From 51cd08ef578421ae2f360053af01c59bad4f25e2 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Wed, 8 Nov 2017 21:01:56 -0800 Subject: [PATCH] store cookies load state --- src/httprequest.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/httprequest.rs b/src/httprequest.rs index d9ca2c65..5fdf6f04 100644 --- a/src/httprequest.rs +++ b/src/httprequest.rs @@ -23,6 +23,7 @@ pub struct HttpRequest { headers: HeaderMap, params: Params, cookies: Vec>, + 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, 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)