diff --git a/core/lib/src/local/client.rs b/core/lib/src/local/client.rs index 1d0f7be7..4a6a8320 100644 --- a/core/lib/src/local/client.rs +++ b/core/lib/src/local/client.rs @@ -1,4 +1,4 @@ -use std::cell::RefCell; +use std::sync::RwLock; use std::borrow::Cow; use Rocket; @@ -53,7 +53,7 @@ use error::LaunchError; /// [`post`]: #method.post pub struct Client { rocket: Rocket, - crate cookies: Option>, + crate cookies: Option>, } impl Client { @@ -62,7 +62,7 @@ impl Client { /// set to `None`. fn _new(rocket: Rocket, tracked: bool) -> Result { let cookies = match tracked { - true => Some(RefCell::new(CookieJar::new())), + true => Some(RwLock::new(CookieJar::new())), false => None }; @@ -321,3 +321,15 @@ impl Client { LocalRequest::new(self, method, uri.into()) } } + +#[cfg(test)] +mod test { + use super::Client; + + fn assert_sync() {} + + #[test] + fn test_local_client_impl_sync() { + assert_sync::(); + } +} diff --git a/core/lib/src/local/request.rs b/core/lib/src/local/request.rs index 0471755b..e6e3fea8 100644 --- a/core/lib/src/local/request.rs +++ b/core/lib/src/local/request.rs @@ -111,7 +111,8 @@ impl<'c> LocalRequest<'c> { // Set up any cookies we know about. if let Some(ref jar) = client.cookies { - for cookie in jar.borrow().iter() { + let cookies = jar.read().expect("LocalRequest::new() read lock"); + for cookie in cookies.iter() { request.cookies().add_original(cookie.clone().into_owned()); } } @@ -408,7 +409,7 @@ impl<'c> LocalRequest<'c> { // If the client is tracking cookies, updates the internal cookie jar // with the changes reflected by `response`. if let Some(ref jar) = client.cookies { - let mut jar = jar.borrow_mut(); + let mut jar = jar.write().expect("LocalRequest::_dispatch() write lock"); let current_time = ::time::now(); for cookie in response.cookies() { if let Some(expires) = cookie.expires() {