Update some code that's feature-gated under core.

This commit is contained in:
Ms2ger 2015-03-21 18:44:39 +01:00
parent 29a36adbe7
commit ba87666cdb
33 changed files with 104 additions and 107 deletions

View file

@ -54,7 +54,7 @@ impl Cookie {
// Step 6
let host_only = if !domain.is_empty() {
if !Cookie::domain_match(url_host.as_slice(), domain.as_slice()) {
if !Cookie::domain_match(&url_host, &domain) {
return None;
} else {
cookie.domain = Some(domain);
@ -69,7 +69,7 @@ impl Cookie {
let mut path = cookie.path.unwrap_or("".to_owned());
if path.is_empty() || path.char_at(0) != '/' {
let url_path = request.serialize_path();
let url_path = url_path.as_ref().map(|path| path.as_slice());
let url_path = url_path.as_ref().map(|path| &**path);
path = Cookie::default_path(url_path.unwrap_or(""));
}
cookie.path = Some(path);
@ -136,14 +136,14 @@ impl Cookie {
}
} else {
if let (Some(ref domain), &Some(ref cookie_domain)) = (domain, &self.cookie.domain) {
if !Cookie::domain_match(domain.as_slice(), cookie_domain.as_slice()) {
if !Cookie::domain_match(domain, cookie_domain) {
return false;
}
}
}
if let (Some(ref path), &Some(ref cookie_path)) = (url.serialize_path(), &self.cookie.path) {
if !Cookie::path_match(path.as_slice(), cookie_path.as_slice()) {
if !Cookie::path_match(path, cookie_path) {
return false;
}
}
@ -177,12 +177,12 @@ fn test_domain_match() {
#[test]
fn test_default_path() {
assert!(Cookie::default_path("/foo/bar/baz/").as_slice() == "/foo/bar/baz");
assert!(Cookie::default_path("/foo/").as_slice() == "/foo");
assert!(Cookie::default_path("/foo").as_slice() == "/");
assert!(Cookie::default_path("/").as_slice() == "/");
assert!(Cookie::default_path("").as_slice() == "/");
assert!(Cookie::default_path("foo").as_slice() == "/");
assert!(&*Cookie::default_path("/foo/bar/baz/") == "/foo/bar/baz");
assert!(&*Cookie::default_path("/foo/") == "/foo");
assert!(&*Cookie::default_path("/foo") == "/");
assert!(&*Cookie::default_path("/") == "/");
assert!(&*Cookie::default_path("") == "/");
assert!(&*Cookie::default_path("foo") == "/");
}
#[test]
@ -201,7 +201,7 @@ fn fn_cookie_constructor() {
let cookie = cookie_rs::Cookie::parse(" baz = bar; Domain = ").unwrap();
assert!(Cookie::new_wrapped(cookie.clone(), url, CookieSource::HTTP).is_some());
let cookie = Cookie::new_wrapped(cookie, url, CookieSource::HTTP).unwrap();
assert!(cookie.cookie.domain.as_ref().unwrap().as_slice() == "example.com");
assert!(&**cookie.cookie.domain.as_ref().unwrap() == "example.com");
// cookie public domains test
let cookie = cookie_rs::Cookie::parse(" baz = bar; Domain = gov.ac").unwrap();

View file

@ -112,7 +112,7 @@ impl CookieStorage {
(match acc.len() {
0 => acc,
_ => acc + ";"
}) + c.cookie.name.as_slice() + "=" + c.cookie.value.as_slice()
}) + &c.cookie.name + "=" + &c.cookie.value
};
let result = url_cookies.iter_mut().fold("".to_string(), reducer);

View file

@ -22,7 +22,7 @@ pub fn factory(load_data: LoadData, start_chan: Sender<TargetedLoadResponse>) {
fn load(load_data: LoadData, start_chan: Sender<TargetedLoadResponse>) {
let url = load_data.url;
assert!("data" == url.scheme.as_slice());
assert!(&*url.scheme == "data");
let mut metadata = Metadata::default(url.clone());
@ -39,11 +39,11 @@ fn load(load_data: LoadData, start_chan: Sender<TargetedLoadResponse>) {
match url.query {
Some(query) => {
scheme_data.push_str("?");
scheme_data.push_str(query.as_slice());
scheme_data.push_str(&query);
},
None => ()
}
let parts: Vec<&str> = scheme_data.as_slice().splitn(1, ',').collect();
let parts: Vec<&str> = scheme_data.splitn(1, ',').collect();
if parts.len() != 2 {
start_sending(senders, metadata).send(Done(Err("invalid data uri".to_string()))).unwrap();
return;
@ -70,7 +70,7 @@ fn load(load_data: LoadData, start_chan: Sender<TargetedLoadResponse>) {
// FIXME(#2909): Its unclear what to do with non-alphabet characters,
// but Acid 3 apparently depends on spaces being ignored.
let bytes = bytes.into_iter().filter(|&b| b != ' ' as u8).collect::<Vec<u8>>();
match bytes.as_slice().from_base64() {
match bytes.from_base64() {
Err(..) => {
progress_chan.send(Done(Err("non-base64 data uri".to_string()))).unwrap();
}

View file

@ -28,7 +28,7 @@ pub enum HeaderOrMethod {
impl HeaderOrMethod {
fn match_header(&self, header_name: &str) -> bool {
match *self {
HeaderOrMethod::HeaderData(ref s) => s.as_slice().eq_ignore_ascii_case(header_name),
HeaderOrMethod::HeaderData(ref s) => s.eq_ignore_ascii_case(header_name),
_ => false
}
}
@ -294,10 +294,10 @@ impl CORSCacheTask {
tx.send(());
},
CORSCacheTaskMsg::MatchHeader(request, header, tx) => {
tx.send(self.cache.match_header(request, header.as_slice()));
tx.send(self.cache.match_header(request, &header));
},
CORSCacheTaskMsg::MatchHeaderUpdate(request, header, new_max_age, tx) => {
tx.send(self.cache.match_header_and_update(request, header.as_slice(), new_max_age));
tx.send(self.cache.match_header_and_update(request, &header, new_max_age));
},
CORSCacheTaskMsg::MatchMethod(request, method, tx) => {
tx.send(self.cache.match_method(request, method));

View file

@ -119,9 +119,9 @@ impl Request {
/// [Basic fetch](http://fetch.spec.whatwg.org#basic-fetch)
pub fn basic_fetch(&mut self) -> Response {
match self.url.scheme.as_slice() {
match &*self.url.scheme {
"about" => match self.url.non_relative_scheme_data() {
Some(s) if s.as_slice() == "blank" => {
Some(s) if &*s == "blank" => {
let mut response = Response::new();
response.headers.set(ContentType(Mime(
TopLevel::Text, SubLevel::Html,

View file

@ -110,7 +110,7 @@ impl Response {
ResponseType::Default | ResponseType::Error => unreachable!(),
ResponseType::Basic => {
let headers = old_headers.iter().filter(|header| {
match header.name().to_ascii_lowercase().as_slice() {
match &*header.name().to_ascii_lowercase() {
"set-cookie" | "set-cookie2" => false,
_ => true
}
@ -120,7 +120,7 @@ impl Response {
},
ResponseType::CORS => {
let headers = old_headers.iter().filter(|header| {
match header.name().to_ascii_lowercase().as_slice() {
match &*header.name().to_ascii_lowercase() {
"cache-control" | "content-language" |
"content-type" | "expires" | "last-modified" | "Pragma" => false,
// XXXManishearth handle Access-Control-Expose-Headers

View file

@ -34,7 +34,7 @@ fn read_all(reader: &mut io::Stream, progress_chan: &Sender<ProgressMsg>)
pub fn factory(load_data: LoadData, start_chan: Sender<TargetedLoadResponse>) {
let url = load_data.url;
assert!("file" == url.scheme.as_slice());
assert!(&*url.scheme == "file");
let senders = ResponseSenders {
immediate_consumer: start_chan,
eventual_consumer: load_data.consumer,

View file

@ -64,20 +64,20 @@ fn load(mut load_data: LoadData, start_chan: Sender<TargetedLoadResponse>, cooki
// real URL that should be used for which the source is to be viewed.
// Change our existing URL to that and keep note that we are viewing
// the source rather than rendering the contents of the URL.
let viewing_source = if url.scheme == "view-source" {
let inner_url = load_data.url.non_relative_scheme_data().unwrap();
url = Url::parse(inner_url).unwrap();
match url.scheme.as_slice() {
"http" | "https" => {}
_ => {
let s = format!("The {} scheme with view-source is not supported", url.scheme);
send_error(url, s, senders);
return;
}
};
true
let viewing_source = if &*url.scheme == "view-source" {
let inner_url = load_data.url.non_relative_scheme_data().unwrap();
url = Url::parse(inner_url).unwrap();
match &*url.scheme {
"http" | "https" => {}
_ => {
let s = format!("The {} scheme with view-source is not supported", url.scheme);
send_error(url, s, senders);
return;
}
};
true
} else {
false
false
};
// Loop to handle redirects.
@ -89,7 +89,7 @@ fn load(mut load_data: LoadData, start_chan: Sender<TargetedLoadResponse>, cooki
return;
}
match url.scheme.as_slice() {
match &*url.scheme {
"http" | "https" => {}
_ => {
let s = format!("{} request, but we don't support that scheme", url.scheme);
@ -252,7 +252,7 @@ reason: \"certificate verify failed\" }]";
}
_ => {}
}
let new_url = match UrlParser::new().base_url(&url).parse(new_url.as_slice()) {
let new_url = match UrlParser::new().base_url(&url).parse(&new_url) {
Ok(u) => u,
Err(e) => {
send_error(url, e.to_string(), senders);

View file

@ -316,7 +316,7 @@ impl ImageCache {
debug!("image_cache_task: started image decode for {}", url.serialize());
let image = profile(time::TimeProfilerCategory::ImageDecoding,
None, time_profiler_chan, || {
load_from_memory(data.as_slice())
load_from_memory(&data)
});
let image = image.map(|image| Arc::new(box image));
@ -456,7 +456,7 @@ fn load_image_data(url: Url, resource_task: ResourceTask) -> Result<Vec<u8>, ()>
loop {
match progress_port.recv().unwrap() {
Payload(data) => {
image_data.push_all(data.as_slice());
image_data.push_all(&data);
}
Done(Ok(..)) => {
return Ok(image_data);

View file

@ -57,7 +57,7 @@ pub fn global_init() {
};
unsafe {
let host_table = boxed::into_raw(parse_hostsfile(lines.as_slice()));
let host_table = boxed::into_raw(parse_hostsfile(&lines));
HOST_TABLE = Some(host_table);
}
}
@ -218,7 +218,7 @@ pub fn load_whole_resource(resource_task: &ResourceTask, url: Url)
let mut buf = vec!();
loop {
match response.progress_port.recv().unwrap() {
ProgressMsg::Payload(data) => buf.push_all(data.as_slice()),
ProgressMsg::Payload(data) => buf.push_all(&data),
ProgressMsg::Done(Ok(())) => return Ok((response.metadata, buf)),
ProgressMsg::Done(Err(e)) => return Err(e)
}
@ -303,7 +303,7 @@ impl ResourceManager {
self.load(load_data)
}
ControlMsg::SetCookiesForUrl(request, cookie_list, source) => {
let header = Header::parse_header([cookie_list.into_bytes()].as_slice());
let header = Header::parse_header(&[cookie_list.into_bytes()]);
if let Some(SetCookie(cookies)) = header {
for bare_cookie in cookies.into_iter() {
if let Some(cookie) = cookie::Cookie::new_wrapped(bare_cookie, &request, source) {
@ -342,7 +342,7 @@ impl ResourceManager {
}
}
let loader = match load_data.url.scheme.as_slice() {
let loader = match &*load_data.url.scheme {
"file" => from_factory(file_loader::factory),
"http" | "https" | "view-source" => http_loader::factory(self.resource_task.clone()),
"data" => from_factory(data_loader::factory),
@ -549,9 +549,7 @@ fn test_replace_hosts() {
//Start the resource task and make a request to our TCP server
let resource_task = new_resource_task(None);
let (start_chan, _) = channel();
let mut raw_url: String = "http://foo.bar.com:".to_string();
raw_url = raw_url + port.to_string().as_slice();
let url = Url::parse(raw_url.as_slice()).unwrap();
let url = Url::parse(&format!("http://foo.bar.com:{}", port)).unwrap();
resource_task.send(ControlMsg::Load(replace_hosts(LoadData::new(url, start_chan), host_table)));
match acceptor.accept() {

View file

@ -141,7 +141,7 @@ impl StorageManager {
}
let updated = data.get_mut(&origin).map(|entry| {
if entry.get(&origin).map_or(true, |item| item.as_slice() != value.as_slice()) {
if entry.get(&origin).map_or(true, |item| *item != value) {
entry.insert(name.clone(), value.clone());
true
} else {
@ -182,12 +182,12 @@ impl StorageManager {
fn get_origin_as_string(&self, url: Url) -> String {
let mut origin = "".to_string();
origin.push_str(url.scheme.as_slice());
origin.push_str(&url.scheme);
origin.push_str("://");
url.domain().map(|domain| origin.push_str(domain.as_slice()));
url.domain().map(|domain| origin.push_str(&domain));
url.port().map(|port| {
origin.push_str(":");
origin.push_str(port.to_string().as_slice());
origin.push_str(&port.to_string());
});
origin.push_str("/");
origin