servo: Merge #10471 - Use mime! macro in fetch methods (from KiChjang:mime-macro); r=emilio
authorKeith Yeung <kungfukeith11@gmail.com>
Fri, 08 Apr 2016 21:30:45 +0500
changeset 476626 09fd6b17e5e5460e0dba95580233329197a39379
parent 476625 a0c9c9dc3b04834a265c2fd1b1bcdef56db5b786
child 476627 3e830a437726c75bff889a5210a1c49bd20aa38a
push id44079
push userbmo:gps@mozilla.com
push dateSat, 04 Feb 2017 00:14:49 +0000
reviewersemilio
servo: Merge #10471 - Use mime! macro in fetch methods (from KiChjang:mime-macro); r=emilio Source-Repo: https://github.com/servo/servo Source-Revision: 217e45006bc04a932650cbfda52388ce1d2a5698
servo/components/net/Cargo.toml
servo/components/net/fetch/methods.rs
servo/components/net/lib.rs
servo/components/servo/Cargo.lock
servo/ports/cef/Cargo.lock
servo/ports/gonk/Cargo.lock
--- a/servo/components/net/Cargo.toml
+++ b/servo/components/net/Cargo.toml
@@ -33,16 +33,17 @@ git = "https://github.com/servo/ipc-chan
 git = "https://github.com/servo/webrender_traits"
 
 [dependencies]
 cookie = "0.2"
 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"
 threadpool = "1.0"
 time = "0.1.17"
 url = {version = "0.5.7", features = ["heap_size"]}
 uuid = { version = "0.2", features = ["v4"] }
 websocket = "0.16.1"
--- a/servo/components/net/fetch/methods.rs
+++ b/servo/components/net/fetch/methods.rs
@@ -54,38 +54,38 @@ pub fn fetch(request: Rc<Request>) -> Re
 
     // Step 3
     if !request.headers.borrow().has::<Accept>() {
 
         let value = match request.type_ {
 
             // 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
         request.headers.borrow_mut().set(Accept(value));
     }
 
     // Step 4
     if !request.headers.borrow().has::<AcceptLanguage>() {
@@ -287,19 +287,17 @@ fn basic_fetch(request: Rc<Request>) -> 
     let scheme = url.scheme.clone();
 
     match &*scheme {
 
         "about" => {
             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
                 },
                 _ => Response::network_error()
             }
         },
 
         "http" | "https" => {
--- a/servo/components/net/lib.rs
+++ b/servo/components/net/lib.rs
@@ -15,16 +15,18 @@ extern crate brotli;
 extern crate cookie as cookie_rs;
 extern crate devtools_traits;
 extern crate flate2;
 extern crate hyper;
 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;
 extern crate openssl;
 extern crate rustc_serialize;
 extern crate threadpool;
 extern crate time;
 extern crate url;
--- a/servo/components/servo/Cargo.lock
+++ b/servo/components/servo/Cargo.lock
@@ -1281,16 +1281,17 @@ dependencies = [
  "brotli 0.3.20 (git+https://github.com/ende76/brotli-rs)",
  "cookie 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "devtools_traits 0.0.1",
  "flate2 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
  "hyper 0.8.0 (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)",
  "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",
  "openssl 0.7.8 (registry+https://github.com/rust-lang/crates.io-index)",
  "plugins 0.0.1",
  "rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)",
  "threadpool 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "time 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)",
--- a/servo/ports/cef/Cargo.lock
+++ b/servo/ports/cef/Cargo.lock
@@ -1193,16 +1193,17 @@ dependencies = [
  "brotli 0.3.20 (git+https://github.com/ende76/brotli-rs)",
  "cookie 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "devtools_traits 0.0.1",
  "flate2 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
  "hyper 0.8.0 (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)",
  "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",
  "openssl 0.7.8 (registry+https://github.com/rust-lang/crates.io-index)",
  "plugins 0.0.1",
  "rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)",
  "threadpool 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "time 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)",
--- a/servo/ports/gonk/Cargo.lock
+++ b/servo/ports/gonk/Cargo.lock
@@ -1175,16 +1175,17 @@ dependencies = [
  "brotli 0.3.20 (git+https://github.com/ende76/brotli-rs)",
  "cookie 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "devtools_traits 0.0.1",
  "flate2 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
  "hyper 0.8.0 (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)",
  "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",
  "openssl 0.7.8 (registry+https://github.com/rust-lang/crates.io-index)",
  "plugins 0.0.1",
  "rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)",
  "threadpool 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "time 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)",