Use mime! macro in fetch methods

This commit is contained in:
Keith Yeung 2016-04-07 21:12:32 -04:00
parent 13e21968e6
commit 32f309c02e
6 changed files with 18 additions and 14 deletions

View file

@ -38,6 +38,7 @@ flate2 = "0.2.0"
hyper = { version = "0.8", features = [ "serde-serialization" ] }
immeta = "0.3.1"
log = "0.3.5"
mime = "0.2.0"
mime_guess = "1.6.0"
openssl = "0.7.6"
rustc-serialize = "0.3"

View file

@ -59,28 +59,28 @@ pub fn fetch(request: Rc<Request>) -> Response {
// Substep 2
_ if request.is_navigation_request() =>
vec![qitem(Mime(TopLevel::Text, SubLevel::Html, vec![])),
vec![qitem(mime!(Text / Html)),
// FIXME: This should properly generate a MimeType that has a
// SubLevel of xhtml+xml (https://github.com/hyperium/mime.rs/issues/22)
qitem(Mime(TopLevel::Application, SubLevel::Ext("xhtml+xml".to_owned()), vec![])),
QualityItem::new(Mime(TopLevel::Application, SubLevel::Xml, vec![]), q(0.9)),
QualityItem::new(Mime(TopLevel::Star, SubLevel::Star, vec![]), q(0.8))],
qitem(mime!(Application / ("xhtml+xml") )),
QualityItem::new(mime!(Application / Xml), q(0.9)),
QualityItem::new(mime!(_ / _), q(0.8))],
// Substep 3
Type::Image =>
vec![qitem(Mime(TopLevel::Image, SubLevel::Png, vec![])),
vec![qitem(mime!(Image / Png)),
// FIXME: This should properly generate a MimeType that has a
// SubLevel of svg+xml (https://github.com/hyperium/mime.rs/issues/22)
qitem(Mime(TopLevel::Image, SubLevel::Ext("svg+xml".to_owned()), vec![])),
QualityItem::new(Mime(TopLevel::Image, SubLevel::Star, vec![]), q(0.8)),
QualityItem::new(Mime(TopLevel::Star, SubLevel::Star, vec![]), q(0.5))],
qitem(mime!(Image / ("svg+xml") )),
QualityItem::new(mime!(Image / _), q(0.8)),
QualityItem::new(mime!(_ / _), q(0.5))],
// Substep 3
Type::Style =>
vec![qitem(Mime(TopLevel::Text, SubLevel::Css, vec![])),
QualityItem::new(Mime(TopLevel::Star, SubLevel::Star, vec![]), q(0.1))],
vec![qitem(mime!(Text / Css)),
QualityItem::new(mime!(_ / _), q(0.1))],
// Substep 1
_ => vec![qitem(Mime(TopLevel::Star, SubLevel::Star, vec![]))]
_ => vec![qitem(mime!(_ / _))]
};
// Substep 4
@ -292,9 +292,7 @@ fn basic_fetch(request: Rc<Request>) -> Response {
match url.non_relative_scheme_data() {
Some(s) if &*s == "blank" => {
let mut response = Response::new();
response.headers.set(ContentType(Mime(
TopLevel::Text, SubLevel::Html,
vec![(Attr::Charset, Value::Utf8)])));
response.headers.set(ContentType(mime!(Text / Html; Charset = Utf8)));
*response.body.lock().unwrap() = ResponseBody::Done(vec![]);
response
},

View file

@ -20,6 +20,8 @@ extern crate immeta;
extern crate ipc_channel;
#[macro_use]
extern crate log;
#[macro_use]
extern crate mime;
extern crate mime_guess;
extern crate msg;
extern crate net_traits;

View file

@ -1286,6 +1286,7 @@ dependencies = [
"immeta 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"ipc-channel 0.2.1 (git+https://github.com/servo/ipc-channel)",
"log 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
"mime 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"mime_guess 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"msg 0.0.1",
"net_traits 0.0.1",

1
ports/cef/Cargo.lock generated
View file

@ -1198,6 +1198,7 @@ dependencies = [
"immeta 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"ipc-channel 0.2.1 (git+https://github.com/servo/ipc-channel)",
"log 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
"mime 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"mime_guess 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"msg 0.0.1",
"net_traits 0.0.1",

1
ports/gonk/Cargo.lock generated
View file

@ -1180,6 +1180,7 @@ dependencies = [
"immeta 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"ipc-channel 0.2.1 (git+https://github.com/servo/ipc-channel)",
"log 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
"mime 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"mime_guess 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"msg 0.0.1",
"net_traits 0.0.1",