Verified Commit f4d0c51d authored by Jordan Petridis's avatar Jordan Petridis 🌱

podcasts-downloader: Upgrade reqwests to 0.9

parent ba60db99
This diff is collapsed.
......@@ -8,7 +8,7 @@ workspace = "../"
error-chain = "0.12.0"
log = "0.4.4"
mime_guess = "1.8.6"
reqwest = "0.8.8"
reqwest = "0.9.2"
tempdir = "0.3.7"
glob = "0.2.11"
failure = "0.1.2"
......
......@@ -76,12 +76,19 @@ fn download_into(
}
let headers = resp.headers().clone();
let ct_len = headers.get::<ContentLength>().map(|ct_len| **ct_len);
let ct_type = headers.get::<ContentType>();
let ct_len = headers
.get(CONTENT_LENGTH)
.and_then(|h| h.to_str().ok())
.and_then(|len| len.parse().ok());
let ct_type = headers
.get(CONTENT_TYPE)
.and_then(|h| h.to_str().ok())
.map(From::from);
ct_len.map(|x| info!("File Lenght: {}", x));
ct_type.map(|x| info!("Content Type: {}", x));
let ext = get_ext(ct_type.cloned()).unwrap_or_else(|| String::from("unknown"));
let ext = get_ext(ct_type).unwrap_or_else(|| String::from("unknown"));
info!("Extension: {}", ext);
// Construct a temp file to save desired content.
......@@ -110,17 +117,17 @@ fn download_into(
}
/// Determine the file extension from the http content-type header.
fn get_ext(content: Option<ContentType>) -> Option<String> {
let cont = content.clone()?;
content
.and_then(|c| mime_guess::get_extensions(c.type_().as_ref(), c.subtype().as_ref()))
.and_then(|c| {
if c.contains(&cont.subtype().as_ref()) {
Some(cont.subtype().as_ref().to_string())
} else {
Some(c.first().unwrap().to_string())
}
})
fn get_ext(content: Option<&str>) -> Option<String> {
let mut iter = content?.split("/");
let type_ = iter.next()?;
let subtype = iter.next()?;
mime_guess::get_extensions(type_, subtype).and_then(|c| {
if c.contains(&&subtype) {
Some(subtype.to_string())
} else {
Some(c.first()?.to_string())
}
})
}
// TODO: Write unit-tests.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment