aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbors-servo <metajack+bors@gmail.com>2015-04-14 15:11:20 -0500
committerbors-servo <metajack+bors@gmail.com>2015-04-14 15:11:20 -0500
commit7f422e2076e7ebc9949e9fb2ffc3f09c653130c0 (patch)
treef5901d29981d491204439e4fbf6786d6be6acf10
parentfe81ce942a36b08ece8ef6d58de72624a961eeaa (diff)
parent3dd48d214baa952bc5809a91d0a4d4b2bf9beda4 (diff)
downloadservo-7f422e2076e7ebc9949e9fb2ffc3f09c653130c0.tar.gz
servo-7f422e2076e7ebc9949e9fb2ffc3f09c653130c0.zip
Auto merge of #5544 - boghison:master, r=jdm
Fixes #5538 <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/5544) <!-- Reviewable:end -->
-rw-r--r--components/net/about_loader.rs4
-rw-r--r--components/net/resource_task.rs15
-rw-r--r--components/net_traits/lib.rs9
-rw-r--r--components/script/parse/html.rs9
-rw-r--r--components/script/script_task.rs9
-rw-r--r--tests/unit/Cargo.toml1
-rw-r--r--tests/unit/net/data_loader.rs15
7 files changed, 39 insertions, 23 deletions
diff --git a/components/net/about_loader.rs b/components/net/about_loader.rs
index 3fd1a09c315..cd7d40671fd 100644
--- a/components/net/about_loader.rs
+++ b/components/net/about_loader.rs
@@ -9,7 +9,9 @@ use resource_task::start_sending;
use file_loader;
use url::Url;
+use hyper::header::ContentType;
use hyper::http::RawStatus;
+use hyper::mime::{Mime, TopLevel, SubLevel};
use util::resource_files::resources_dir_path;
use std::borrow::IntoCow;
@@ -22,7 +24,7 @@ pub fn factory(mut load_data: LoadData, classifier: Arc<MIMEClassifier>) {
let start_chan = load_data.consumer;
let chan = start_sending(start_chan, Metadata {
final_url: load_data.url,
- content_type: Some(("text".to_string(), "html".to_string())),
+ content_type: Some(ContentType(Mime(TopLevel::Text, SubLevel::Html, vec![]))),
charset: Some("utf-8".to_string()),
headers: None,
status: Some(RawStatus(200, "OK".into_cow())),
diff --git a/components/net/resource_task.rs b/components/net/resource_task.rs
index 4d29526a989..9952190c23b 100644
--- a/components/net/resource_task.rs
+++ b/components/net/resource_task.rs
@@ -18,8 +18,8 @@ use net_traits::ProgressMsg::Done;
use util::opts;
use util::task::spawn_named;
-use hyper::header::UserAgent;
-use hyper::header::{Header, SetCookie};
+use hyper::header::{ContentType, Header, SetCookie, UserAgent};
+use hyper::mime::{Mime, TopLevel, SubLevel};
use std::borrow::ToOwned;
use std::boxed;
@@ -27,6 +27,7 @@ use std::collections::HashMap;
use std::env;
use std::fs::File;
use std::io::{BufReader, Read};
+use std::str::FromStr;
use std::sync::Arc;
use std::sync::mpsc::{channel, Receiver, Sender};
use std::thunk::Invoke;
@@ -78,8 +79,14 @@ pub fn start_sending_sniffed_opt(start_chan: Sender<LoadResponse>, mut metadata:
let nosniff = false;
let check_for_apache_bug = false;
- metadata.content_type = classifier.classify(nosniff, check_for_apache_bug,
- &metadata.content_type, &partial_body);
+ let supplied_type = metadata.content_type.map(|ContentType(Mime(toplevel, sublevel, _))| {
+ (format!("{}", toplevel), format!("{}", sublevel))
+ });
+ metadata.content_type = classifier.classify(nosniff, check_for_apache_bug, &supplied_type, &partial_body).map(|(toplevel, sublevel)| {
+ let mime_tp: TopLevel = FromStr::from_str(&toplevel).unwrap();
+ let mime_sb: SubLevel = FromStr::from_str(&sublevel).unwrap();
+ ContentType(Mime(mime_tp, mime_sb, vec!()))
+ });
}
diff --git a/components/net_traits/lib.rs b/components/net_traits/lib.rs
index 0e80fa2eda9..8a35fc87762 100644
--- a/components/net_traits/lib.rs
+++ b/components/net_traits/lib.rs
@@ -18,7 +18,7 @@ extern crate stb_image;
extern crate url;
extern crate util;
-use hyper::header::Headers;
+use hyper::header::{ContentType, Headers};
use hyper::http::RawStatus;
use hyper::method::Method;
use hyper::mime::{Mime, Attr};
@@ -108,7 +108,7 @@ pub struct Metadata {
pub final_url: Url,
/// MIME type / subtype.
- pub content_type: Option<(String, String)>,
+ pub content_type: Option<(ContentType)>,
/// Character set.
pub charset: Option<String>,
@@ -137,8 +137,9 @@ impl Metadata {
pub fn set_content_type(&mut self, content_type: Option<&Mime>) {
match content_type {
None => (),
- Some(&Mime(ref type_, ref subtype, ref parameters)) => {
- self.content_type = Some((type_.to_string(), subtype.to_string()));
+ Some(mime) => {
+ self.content_type = Some(ContentType(mime.clone()));
+ let &Mime(_, _, ref parameters) = mime;
for &(ref k, ref v) in parameters.iter() {
if &Attr::Charset == k {
self.charset = Some(v.to_string());
diff --git a/components/script/parse/html.rs b/components/script/parse/html.rs
index 9995d06593d..5fb99174591 100644
--- a/components/script/parse/html.rs
+++ b/components/script/parse/html.rs
@@ -38,7 +38,6 @@ use net_traits::{ProgressMsg, LoadResponse};
use util::str::DOMString;
use util::task_state;
use util::task_state::IN_HTML_PARSER;
-use std::ascii::AsciiExt;
use std::borrow::Cow;
use std::old_io::{Writer, IoResult};
use url::Url;
@@ -49,6 +48,9 @@ use html5ever::serialize::TraversalScope::{IncludeNode, ChildrenOnly};
use html5ever::tree_builder::{TreeSink, QuirksMode, NodeOrText, AppendNode, AppendText};
use string_cache::QualName;
+use hyper::header::ContentType;
+use hyper::mime::{Mime, TopLevel, SubLevel};
+
pub enum HTMLInput {
InputString(String),
InputUrl(LoadResponse),
@@ -297,12 +299,11 @@ pub fn parse_html(document: JSRef<Document>,
}
HTMLInput::InputUrl(load_response) => {
match load_response.metadata.content_type {
- Some((ref t, _)) if t.as_slice().eq_ignore_ascii_case("image") => {
+ Some(ContentType(Mime(TopLevel::Image, _, _))) => {
let page = format!("<html><body><img src='{}' /></body></html>", url.serialize());
parser.parse_chunk(page);
},
- Some((ref t, ref st)) if t.as_slice().eq_ignore_ascii_case("text") &&
- st.as_slice().eq_ignore_ascii_case("plain") => {
+ Some(ContentType(Mime(TopLevel::Text, SubLevel::Plain, _))) => {
// FIXME: When servo/html5ever#109 is fixed remove <plaintext> usage and
// replace with fix from that issue.
diff --git a/components/script/script_task.rs b/components/script/script_task.rs
index ec4b40bfc75..877289a27fd 100644
--- a/components/script/script_task.rs
+++ b/components/script/script_task.rs
@@ -83,7 +83,6 @@ use js;
use url::Url;
use libc;
-use std::ascii::AsciiExt;
use std::any::Any;
use std::borrow::ToOwned;
use std::cell::{Cell, RefCell};
@@ -96,6 +95,9 @@ use std::result::Result;
use std::sync::mpsc::{channel, Sender, Receiver, Select};
use time::Tm;
+use hyper::header::ContentType;
+use hyper::mime::{Mime, TopLevel, SubLevel};
+
thread_local!(pub static STACK_ROOTS: Cell<Option<RootCollectionPtr>> = Cell::new(None));
thread_local!(static SCRIPT_TASK_ROOT: RefCell<Option<*const ScriptTask>> = RefCell::new(None));
@@ -1052,10 +1054,7 @@ impl ScriptTask {
});
let content_type = match response.metadata.content_type {
- Some((ref t, ref st)) if t.as_slice().eq_ignore_ascii_case("text") &&
- st.as_slice().eq_ignore_ascii_case("plain") => {
- Some("text/plain".to_owned())
- }
+ Some(ContentType(Mime(TopLevel::Text, SubLevel::Plain, _))) => Some("text/plain".to_owned()),
_ => None
};
diff --git a/tests/unit/Cargo.toml b/tests/unit/Cargo.toml
index 5f0d1125796..3c3c80a3e4b 100644
--- a/tests/unit/Cargo.toml
+++ b/tests/unit/Cargo.toml
@@ -47,3 +47,4 @@ git = "https://github.com/servo/string-cache"
[dependencies]
cookie = "*"
url = "*"
+hyper = "0.3"
diff --git a/tests/unit/net/data_loader.rs b/tests/unit/net/data_loader.rs
index 370fa1bd28e..482a7462bea 100644
--- a/tests/unit/net/data_loader.rs
+++ b/tests/unit/net/data_loader.rs
@@ -2,12 +2,16 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+extern crate hyper;
+
use net_traits::LoadData;
use net_traits::ProgressMsg::{Payload, Done};
+use self::hyper::header::ContentType;
+use self::hyper::mime::{Mime, TopLevel, SubLevel, Attr, Value};
#[cfg(test)]
fn assert_parse(url: &'static str,
- content_type: Option<(String, String)>,
+ content_type: Option<ContentType>,
charset: Option<String>,
data: Option<Vec<u8>>) {
use std::sync::mpsc::channel;
@@ -47,13 +51,14 @@ fn plain() {
#[test]
fn plain_ct() {
assert_parse("data:text/plain,hello",
- Some(("text".to_string(), "plain".to_string())), None, Some(b"hello".iter().map(|&x| x).collect()));
+ Some(ContentType(Mime(TopLevel::Text, SubLevel::Plain, vec!()))), None, Some(b"hello".iter().map(|&x| x).collect()));
}
#[test]
fn plain_charset() {
assert_parse("data:text/plain;charset=latin1,hello",
- Some(("text".to_string(), "plain".to_string())), Some("latin1".to_string()), Some(b"hello".iter().map(|&x| x).collect()));
+ Some(ContentType(Mime(TopLevel::Text, SubLevel::Plain, vec!((Attr::Charset, Value::Ext("latin1".to_string())))))),
+ Some("latin1".to_string()), Some(b"hello".iter().map(|&x| x).collect()));
}
#[test]
@@ -64,12 +69,12 @@ fn base64() {
#[test]
fn base64_ct() {
assert_parse("data:application/octet-stream;base64,C62+7w==",
- Some(("application".to_string(), "octet-stream".to_string())), None, Some(vec!(0x0B, 0xAD, 0xBE, 0xEF)));
+ Some(ContentType(Mime(TopLevel::Application, SubLevel::Ext("octet-stream".to_string()), vec!()))), None, Some(vec!(0x0B, 0xAD, 0xBE, 0xEF)));
}
#[test]
fn base64_charset() {
assert_parse("data:text/plain;charset=koi8-r;base64,8PLl9+XkIO3l5Pfl5A==",
- Some(("text".to_string(), "plain".to_string())), Some("koi8-r".to_string()),
+ Some(ContentType(Mime(TopLevel::Text, SubLevel::Plain, vec!((Attr::Charset, Value::Ext("koi8-r".to_string())))))), Some("koi8-r".to_string()),
Some(vec!(0xF0, 0xF2, 0xE5, 0xF7, 0xE5, 0xE4, 0x20, 0xED, 0xE5, 0xE4, 0xF7, 0xE5, 0xE4)));
}