diff --git a/components/net/Cargo.toml b/components/net/Cargo.toml index 9aa13502744..9d3e91631a6 100644 --- a/components/net/Cargo.toml +++ b/components/net/Cargo.toml @@ -44,6 +44,7 @@ rustc-serialize = "0.3" cookie = "0.1" regex = "0.1.14" regex_macros = "0.1.8" +mime_guess = "1.1.1" flate2 = "0.2.0" uuid = "0.1.16" euclid = {version = "0.3", features = ["plugins"]} diff --git a/components/net/file_loader.rs b/components/net/file_loader.rs index a4348049d78..1519ec31b2d 100644 --- a/components/net/file_loader.rs +++ b/components/net/file_loader.rs @@ -3,6 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use mime_classifier::MIMEClassifier; +use mime_guess::guess_mime_type; use net_traits::ProgressMsg::{Done, Payload}; use net_traits::{LoadConsumer, LoadData, Metadata}; use resource_task::{CancellationListener, ProgressSender}; @@ -70,7 +71,9 @@ pub fn factory(load_data: LoadData, } match read_block(reader) { Ok(ReadStatus::Partial(buf)) => { - let metadata = Metadata::default(url); + let mut metadata = Metadata::default(url); + let mime_type = guess_mime_type(file_path.as_path()); + metadata.set_content_type(Some(&mime_type)); let progress_chan = start_sending_sniffed(senders, metadata, classifier, &buf); progress_chan.send(Payload(buf)).unwrap(); @@ -83,7 +86,9 @@ pub fn factory(load_data: LoadData, } } Ok(ReadStatus::EOF) => { - let metadata = Metadata::default(url); + let mut metadata = Metadata::default(url); + let mime_type = guess_mime_type(file_path.as_path()); + metadata.set_content_type(Some(&mime_type)); if let Ok(chan) = start_sending_sniffed_opt(senders, metadata, classifier, diff --git a/components/net/lib.rs b/components/net/lib.rs index 514be731f77..3fe4fba3d2c 100644 --- a/components/net/lib.rs +++ b/components/net/lib.rs @@ -20,6 +20,7 @@ extern crate flate2; extern crate brotli; extern crate hyper; extern crate ipc_channel; +extern crate mime_guess; extern crate msg; extern crate net_traits; extern crate openssl; diff --git a/components/servo/Cargo.lock b/components/servo/Cargo.lock index f0d37d70faa..2b16bd24fe6 100644 --- a/components/servo/Cargo.lock +++ b/components/servo/Cargo.lock @@ -1119,6 +1119,14 @@ dependencies = [ "log 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "mime_guess" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "mime 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "miniz-sys" version = "0.1.6" @@ -1182,6 +1190,7 @@ dependencies = [ "hyper 0.6.15 (registry+https://github.com/rust-lang/crates.io-index)", "ipc-channel 0.1.0 (git+https://github.com/pcwalton/ipc-channel)", "log 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "mime_guess 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "msg 0.0.1", "net_traits 0.0.1", "openssl 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/ports/cef/Cargo.lock b/ports/cef/Cargo.lock index 0fb84a80b8c..04a08181998 100644 --- a/ports/cef/Cargo.lock +++ b/ports/cef/Cargo.lock @@ -1071,6 +1071,14 @@ dependencies = [ "log 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "mime_guess" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "mime 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "miniz-sys" version = "0.1.6" @@ -1134,6 +1142,7 @@ dependencies = [ "hyper 0.6.15 (registry+https://github.com/rust-lang/crates.io-index)", "ipc-channel 0.1.0 (git+https://github.com/pcwalton/ipc-channel)", "log 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "mime_guess 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "msg 0.0.1", "net_traits 0.0.1", "openssl 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/ports/gonk/Cargo.lock b/ports/gonk/Cargo.lock index 531f2b92268..5074bc6ae33 100644 --- a/ports/gonk/Cargo.lock +++ b/ports/gonk/Cargo.lock @@ -1051,6 +1051,14 @@ dependencies = [ "log 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "mime_guess" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "mime 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "miniz-sys" version = "0.1.6" @@ -1114,6 +1122,7 @@ dependencies = [ "hyper 0.6.15 (registry+https://github.com/rust-lang/crates.io-index)", "ipc-channel 0.1.0 (git+https://github.com/pcwalton/ipc-channel)", "log 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "mime_guess 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "msg 0.0.1", "net_traits 0.0.1", "openssl 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)",