diff options
-rw-r--r-- | components/net/cookie.rs | 4 | ||||
-rw-r--r-- | components/net/file_loader.rs | 9 | ||||
-rw-r--r-- | components/net/resource_thread.rs | 22 |
3 files changed, 15 insertions, 20 deletions
diff --git a/components/net/cookie.rs b/components/net/cookie.rs index 2f555767b11..0f77a8d6f2c 100644 --- a/components/net/cookie.rs +++ b/components/net/cookie.rs @@ -66,7 +66,7 @@ impl Cookie { // Step 7 let mut path = cookie.path.unwrap_or("".to_owned()); - if path.is_empty() || path.as_bytes()[0] != b'/' { + if path.chars().next() != Some('/') { let url_path = request.serialize_path(); let url_path = url_path.as_ref().map(|path| &**path); path = Cookie::default_path(url_path.unwrap_or("")).to_owned(); @@ -96,7 +96,7 @@ impl Cookie { // http://tools.ietf.org/html/rfc6265#section-5.1.4 pub fn default_path(request_path: &str) -> &str { // Step 2 - if request_path.is_empty() || !request_path.starts_with("/") { + if request_path.chars().next() != Some('/') { return "/"; } diff --git a/components/net/file_loader.rs b/components/net/file_loader.rs index db87cb33375..b3b905c7dcb 100644 --- a/components/net/file_loader.rs +++ b/components/net/file_loader.rs @@ -44,17 +44,14 @@ fn read_block(reader: &mut File) -> Result<ReadStatus, String> { fn read_all(reader: &mut File, progress_chan: &ProgressSender, cancel_listener: &CancellationListener) -> Result<LoadResult, String> { - loop { - if cancel_listener.is_cancelled() { - let _ = progress_chan.send(Done(Err("load cancelled".to_owned()))); - return Ok(LoadResult::Cancelled); - } - + while !cancel_listener.is_cancelled() { match try!(read_block(reader)) { ReadStatus::Partial(buf) => progress_chan.send(Payload(buf)).unwrap(), ReadStatus::EOF => return Ok(LoadResult::Finished), } } + let _ = progress_chan.send(Done(Err("load cancelled".to_owned()))); + Ok(LoadResult::Cancelled) } fn get_progress_chan(load_data: LoadData, file_path: PathBuf, diff --git a/components/net/resource_thread.rs b/components/net/resource_thread.rs index bb839176b14..0bc6f19e053 100644 --- a/components/net/resource_thread.rs +++ b/components/net/resource_thread.rs @@ -133,7 +133,7 @@ fn start_sending_opt(start_chan: LoadConsumer, metadata: Metadata) -> Result<Pro /// Create a ResourceThread pub fn new_resource_thread(user_agent: String, - devtools_chan: Option<Sender<DevtoolsControlMsg>>) -> ResourceThread { + devtools_chan: Option<Sender<DevtoolsControlMsg>>) -> ResourceThread { let hsts_preload = HstsList::from_servo_preload(); let (setup_chan, setup_port) = ipc::channel().unwrap(); let setup_chan_clone = setup_chan.clone(); @@ -227,17 +227,15 @@ impl CancellationListener { } pub fn is_cancelled(&self) -> bool { - match self.cancel_resource { - Some(ref resource) => { - match resource.cancel_receiver.try_recv() { - Ok(_) => { - self.cancel_status.set(true); - true - }, - Err(_) => self.cancel_status.get(), - } - }, - None => false, // channel doesn't exist! + let resource = match self.cancel_resource { + Some(ref resource) => resource, + None => return false, // channel doesn't exist! + }; + if resource.cancel_receiver.try_recv().is_ok() { + self.cancel_status.set(true); + true + } else { + self.cancel_status.get() } } } |