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