servo: Merge #10725 - A few minor `net` component cleanups (from frewsxcv:net-cleanup); r=KiChjang

Source-Repo: https://github.com/servo/servo
Source-Revision: bebc1dc859192d7fdcfc53e550cbf51343f4375a
This commit is contained in:
Corey Farwell 2016-04-20 05:01:59 +05:01
Родитель 4781925f69
Коммит 939c774f41
3 изменённых файлов: 15 добавлений и 20 удалений

Просмотреть файл

@ -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 "/";
}

Просмотреть файл

@ -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,

Просмотреть файл

@ -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()
}
}
}