Skip to content

Commit

Permalink
Update ureq dep and add native_certs feature
Browse files Browse the repository at this point in the history
  • Loading branch information
jeff-hughes committed Feb 3, 2022
1 parent 66a92cd commit be2c7f6
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 52 deletions.
92 changes: 71 additions & 21 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 15 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ readme = "README.md"
crossterm = "0.19.0"
rss = "1.10.0"
rusqlite = "0.21.0"
ureq = "2.4.0"
native-tls = { version = "0.2.8", optional = true }
clap = "2.33.1"
toml = "0.5.8"
anyhow = "1.0.43"
Expand All @@ -38,26 +40,27 @@ escaper = "0.1.0"
rfc822_sanitizer = "0.3.6"
semver = "0.10.0"

[dependencies.ureq]
version = "1.5.5"
default-features = false


[features]
default = ["native-tls"]
default = ["native_certs"]

# bundle sqlite library with app; recommended for Windows. This is
# turned on by default, but if you are building this for a package
# manager, consider building with `--no-default-features` specified, and
# adding libsqlite3-dev or sqlite3 as a dependency on the package
sqlite_bundled = ["rusqlite/bundled"]

# by default, shellcaster uses `native-tls` crate to enable TLS support;
# if this is causing issues for some websites, you can try building it
# to use `rustls` crate instead; build with `--no-default-features` and
# then specify `--features "rustls"`
native-tls = ["ureq/native-tls"]
rustls = ["ureq/tls"]
# by default, shellcaster uses the `rustls` crate to enable TLS support;
# if this is causing issues for some URLs (e.g., those using TLS 1.0 or
# 1.1), you can try building it to use the `native-tls` crate instead by
# specifying `--features "native_tls"`
native_tls = ["native-tls", "ureq/native-tls"]

# the `native_certs` feature (enabled by default) extracts the trusted
# certificate roots from your OS's trust store; you can instead use a
# bundled copy of the Mozilla Root program (which will thus not update
# if the program is not updated). To do so, build shellcaster with
# `--no-default-features` to turn off use of the native certificates
native_certs = ["ureq/native-certs"]

[profile.release]
debug = 1
27 changes: 18 additions & 9 deletions src/downloads.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::fs::File;
use std::path::{Path, PathBuf};
use std::sync::mpsc::Sender;
use std::time::Duration;

use chrono::{DateTime, Utc};
use sanitize_filename::{sanitize_with_options, Options};
Expand Down Expand Up @@ -57,18 +58,26 @@ pub fn download_list(
/// Downloads a file to a local filepath, returning DownloadMsg variant
/// indicating success or failure.
fn download_file(mut ep_data: EpData, dest: PathBuf, mut max_retries: usize) -> DownloadMsg {
let agent_builder = ureq::builder();
#[cfg(feature = "native_tls")]
let tls_connector = std::sync::Arc::new(native_tls::TlsConnector::new().unwrap());
#[cfg(feature = "native_tls")]
let agent_builder = agent_builder.tls_connector(tls_connector);
let agent = agent_builder.build();

let request: Result<ureq::Response, ()> = loop {
let response = ureq::get(&ep_data.url)
.timeout_connect(5000)
.timeout_read(30000)
let response = agent
.get(&ep_data.url)
.timeout(Duration::from_secs(30))
.call();
if response.error() {
max_retries -= 1;
if max_retries == 0 {
break Err(());
match response {
Ok(resp) => break Ok(resp),
Err(_) => {
max_retries -= 1;
if max_retries == 0 {
break Err(());
}
}
} else {
break Ok(response);
}
};

Expand Down
26 changes: 16 additions & 10 deletions src/feeds.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use anyhow::{anyhow, Result};
use std::io::Read;
use std::sync::mpsc;
use std::time::Duration;

use chrono::{DateTime, Utc};
use lazy_static::lazy_static;
Expand Down Expand Up @@ -72,18 +73,23 @@ pub fn check_feed(
/// Given a URL, this attempts to pull the data about a podcast and its
/// episodes from an RSS feed.
fn get_feed_data(url: String, mut max_retries: usize) -> Result<PodcastNoId> {
let agent_builder = ureq::builder();
#[cfg(feature = "native_tls")]
let tls_connector = std::sync::Arc::new(native_tls::TlsConnector::new().unwrap());
#[cfg(feature = "native_tls")]
let agent_builder = agent_builder.tls_connector(tls_connector);
let agent = agent_builder.build();

let request: Result<ureq::Response> = loop {
let response = ureq::get(&url)
.timeout_connect(5000)
.timeout_read(15000)
.call();
if response.error() {
max_retries -= 1;
if max_retries == 0 {
break Err(anyhow!("No response from feed"));
let response = agent.get(&url).timeout(Duration::from_secs(20)).call();
match response {
Ok(resp) => break Ok(resp),
Err(_) => {
max_retries -= 1;
if max_retries == 0 {
break Err(anyhow!("No response from feed"));
}
}
} else {
break Ok(response);
}
};

Expand Down

0 comments on commit be2c7f6

Please sign in to comment.