Update read blob url in chunk changes to use new hyper

This commit is contained in:
Fernando Jiménez Moreno 2018-11-05 18:22:04 +01:00
parent 2f3affcfc8
commit 67722d1943

View file

@ -5,11 +5,13 @@
use embedder_traits::{EmbedderMsg, EmbedderProxy, FilterPattern};
use ipc_channel::ipc::{self, IpcSender};
use fetch::methods::Data;
use hyper::header::{Charset, ContentLength, ContentType, Headers};
use hyper::header::{ContentDisposition, DispositionParam, DispositionType};
use mime::{Attr, Mime};
use headers_core::HeaderMapExt;
use headers_ext::{ContentLength, ContentType};
use http::HeaderMap;
use http::header::{self, HeaderValue};
use mime::{self, Mime};
use mime_guess::guess_mime_type_opt;
use net_traits::NetworkError;
use net_traits::{http_percent_encode, NetworkError};
use net_traits::blob_url_store::{BlobBuf, BlobURLStoreError};
use net_traits::filemanager_thread::{FileManagerResult, FileManagerThreadMsg, FileOrigin};
use net_traits::filemanager_thread::{
@ -524,23 +526,29 @@ impl FileManagerStore {
bytes: buf.bytes.index(range).to_vec(),
};
let content_type: Mime = blob_buf.type_string.parse().unwrap_or(mime!(Text / Plain));
let charset = content_type.get_param(Attr::Charset);
let mut headers = Headers::new();
let content_type: Mime = blob_buf.type_string.parse().unwrap_or(mime::TEXT_PLAIN);
let charset = content_type.get_param(mime::CHARSET);
let mut headers = HeaderMap::new();
if let Some(name) = blob_buf.filename {
let charset = charset.and_then(|c| c.as_str().parse().ok());
headers.set(ContentDisposition {
disposition: DispositionType::Inline,
parameters: vec![
DispositionParam::Filename(charset.unwrap_or(Charset::Us_Ascii),
None, name.as_bytes().to_vec())
]
});
let charset = charset.map(|c| c.as_ref().into()).unwrap_or("us-ascii".to_owned());
// TODO(eijebong): Replace this once the typed header is there
headers.insert(
header::CONTENT_DISPOSITION,
HeaderValue::from_bytes(
format!("inline; {}",
if charset.to_lowercase() == "utf-8" {
format!("filename=\"{}\"", String::from_utf8(name.as_bytes().into()).unwrap())
} else {
format!("filename*=\"{}\"''{}", charset, http_percent_encode(name.as_bytes()))
}
).as_bytes()
).unwrap()
);
}
headers.set(ContentLength(blob_buf.size as u64));
headers.set(ContentType(content_type.clone()));
headers.typed_insert(ContentLength(blob_buf.size as u64));
headers.typed_insert(ContentType::from(content_type.clone()));
bytes.extend_from_slice(&blob_buf.bytes);