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" ] } hyper = { version = "0.8", features = [ "serde-serialization" ] }
immeta = "0.3.1" immeta = "0.3.1"
log = "0.3.5" log = "0.3.5"
mime = "0.2.0"
mime_guess = "1.6.0" mime_guess = "1.6.0"
openssl = "0.7.6" openssl = "0.7.6"
rustc-serialize = "0.3" rustc-serialize = "0.3"

View file

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

View file

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

View file

@ -1286,6 +1286,7 @@ dependencies = [
"immeta 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "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)", "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)", "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)", "mime_guess 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"msg 0.0.1", "msg 0.0.1",
"net_traits 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)", "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)", "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)", "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)", "mime_guess 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"msg 0.0.1", "msg 0.0.1",
"net_traits 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)", "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)", "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)", "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)", "mime_guess 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"msg 0.0.1", "msg 0.0.1",
"net_traits 0.0.1", "net_traits 0.0.1",