Fix: Should assign a new cookie vector if it doesn't exist

This commit is contained in:
winkidney 2019-01-02 11:41:50 +08:00
parent 5eb4ee27e8
commit 2d2917b61f
1 changed files with 12 additions and 12 deletions

View File

@ -549,9 +549,9 @@ impl<S: 'static> TestRequest<S> {
/// set cookie of this request /// set cookie of this request
pub fn cookie(mut self, cookie: Cookie<'static>) -> Self { pub fn cookie(mut self, cookie: Cookie<'static>) -> Self {
if self.cookies.is_none() {
let mut should_insert = true; let mut should_insert = true;
match &mut self.cookies { let old_cookies = self.cookies.as_mut().unwrap();
Some(old_cookies) => {
for old_cookie in old_cookies.iter() { for old_cookie in old_cookies.iter() {
if old_cookie == &cookie { if old_cookie == &cookie {
should_insert = false should_insert = false
@ -560,8 +560,8 @@ impl<S: 'static> TestRequest<S> {
if should_insert { if should_insert {
old_cookies.push(cookie); old_cookies.push(cookie);
}; };
} } else {
None => {} self.cookies = Some(vec![cookie]);
}; };
self self
} }