aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/script_module.rs
diff options
context:
space:
mode:
authorCYBAI <cyb.ai.815@gmail.com>2020-03-02 11:05:10 +0900
committerCYBAI <cyb.ai.815@gmail.com>2020-03-02 11:05:10 +0900
commit5245921c5c5c97422825a0f44ba75147dbdf723d (patch)
tree6ade0d8ba08f01fff56da792837730ab752dc941 /components/script/script_module.rs
parent1c910da749d785178632ba17697e86c61b34f877 (diff)
downloadservo-5245921c5c5c97422825a0f44ba75147dbdf723d.tar.gz
servo-5245921c5c5c97422825a0f44ba75147dbdf723d.zip
Use `essence` algorithm from mime crate
Diffstat (limited to 'components/script/script_module.rs')
-rw-r--r--components/script/script_module.rs21
1 files changed, 14 insertions, 7 deletions
diff --git a/components/script/script_module.rs b/components/script/script_module.rs
index bf2eafd5b42..b9eda4c2ee6 100644
--- a/components/script/script_module.rs
+++ b/components/script/script_module.rs
@@ -56,6 +56,7 @@ use js::rust::wrappers::JS_SetPendingException;
use js::rust::CompileOptionsWrapper;
use js::rust::IntoHandle;
use js::rust::{Handle, HandleValue};
+use mime::Mime;
use net_traits::request::{CredentialsMode, Destination, ParserMetadata};
use net_traits::request::{Referrer, RequestBuilder, RequestMode};
use net_traits::{FetchMetadata, Metadata};
@@ -68,6 +69,7 @@ use std::ffi;
use std::marker::PhantomData;
use std::ptr;
use std::rc::Rc;
+use std::str::FromStr;
use std::sync::{Arc, Mutex};
use url::ParseError as UrlParseError;
@@ -934,15 +936,20 @@ impl FetchResponseListener for ModuleContext {
let meta = self.metadata.take().unwrap();
if let Some(content_type) = meta.content_type.map(Serde::into_inner) {
- let c = content_type.to_string();
- // The MIME crate includes params (e.g. charset=utf8) in the to_string
- // https://github.com/hyperium/mime/issues/120
- if let Some(ty) = c.split(';').next() {
- if !SCRIPT_JS_MIMES.contains(&ty) {
- return Err(NetworkError::Internal(format!("Invalid MIME type: {}", ty)));
+ if let Ok(content_type) = Mime::from_str(&content_type.to_string()) {
+ let essence_mime = content_type.essence_str();
+
+ if !SCRIPT_JS_MIMES.contains(&essence_mime) {
+ return Err(NetworkError::Internal(format!(
+ "Invalid MIME type: {}",
+ essence_mime
+ )));
}
} else {
- return Err(NetworkError::Internal("Empty MIME type".into()));
+ return Err(NetworkError::Internal(format!(
+ "Failed to parse MIME type: {}",
+ content_type.to_string()
+ )));
}
} else {
return Err(NetworkError::Internal("No MIME type".into()));