1
0
mirror of https://github.com/actix/actix-extras.git synced 2025-06-25 09:59:21 +02:00

Session should write percent encoded cookies and add cookie middleware test (#393)

* Should write percent encoded cookies to HTTP response

* Add cookie middleware test
This commit is contained in:
Douman
2018-07-17 08:38:18 +03:00
committed by GitHub
parent 1af5aa3a3e
commit 29a275b0f5
3 changed files with 79 additions and 3 deletions

View File

@ -161,7 +161,7 @@ impl HttpResponse {
let mut count: usize = 0;
for v in vals {
if let Ok(s) = v.to_str() {
if let Ok(c) = Cookie::parse(s) {
if let Ok(c) = Cookie::parse_encoded(s) {
if c.name() == name {
count += 1;
continue;
@ -327,7 +327,7 @@ impl<'a> Iterator for CookieIter<'a> {
#[inline]
fn next(&mut self) -> Option<Cookie<'a>> {
for v in self.iter.by_ref() {
if let Ok(c) = Cookie::parse(v.to_str().ok()?) {
if let Ok(c) = Cookie::parse_encoded(v.to_str().ok()?) {
return Some(c);
}
}

View File

@ -410,7 +410,7 @@ impl CookieSessionInner {
}
for cookie in jar.delta() {
let val = HeaderValue::from_str(&cookie.to_string())?;
let val = HeaderValue::from_str(&cookie.encoded().to_string())?;
resp.headers_mut().append(header::SET_COOKIE, val);
}
@ -464,6 +464,9 @@ impl CookieSessionInner {
/// all session data is lost. The constructors will panic if the key is less
/// than 32 bytes in length.
///
/// The backend relies on `cookie` crate to create and read cookies.
/// By default all cookies are percent encoded, but certain symbols may
/// cause troubles when reading cookie, if they are not properly percent encoded.
///
/// # Example
///