diff --git a/README.md b/README.md index 82f9eba..7170d65 100644 --- a/README.md +++ b/README.md @@ -42,10 +42,11 @@ If compared to saving websites with `wget -mpk`, this tool embeds all assets as - `-k`: Accept invalid X.509 (TLS) certificates - `-o`: Write output to file - `-s`: Silent mode + - `-t`: Set custom network request timeout (in seconds) - `-u`: Specify custom User-Agent ## HTTPS and HTTP proxies -Please set `https_proxy`, `http_proxy` and `no_proxy` environment variables. +Please set `https_proxy`, `http_proxy`, and `no_proxy` environment variables. ## Contributing Please open an issue if something is wrong, that helps make this project better. diff --git a/src/args.rs b/src/args.rs index 9448d5f..02d1e8c 100644 --- a/src/args.rs +++ b/src/args.rs @@ -11,9 +11,11 @@ pub struct AppArgs { pub isolate: bool, pub output: String, pub silent: bool, + pub timeout: u64, pub user_agent: String, } +const DEFAULT_NETWORK_TIMEOUT: u64 = 120; const DEFAULT_USER_AGENT: &str = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:66.0) Gecko/20100101 Firefox/66.0"; @@ -39,6 +41,7 @@ impl AppArgs { .args_from_usage("-k, --insecure 'Accept invalid X.509 (TLS) certificates'") .args_from_usage("-o, --output=[document.html] 'Write output to '") .args_from_usage("-s, --silent 'Suppress verbosity'") + .args_from_usage("-t, --timeout=[60] 'Specify custom timeout for network requests'") .args_from_usage("-u, --user-agent=[Iceweasel] 'Custom User-Agent string'") // .args_from_usage("-v, --include-video 'Embed video sources'") .get_matches(); @@ -55,6 +58,11 @@ impl AppArgs { app_args.insecure = app.is_present("insecure"); app_args.isolate = app.is_present("isolate"); app_args.silent = app.is_present("silent"); + app_args.timeout = app + .value_of("timeout") + .unwrap_or(&DEFAULT_NETWORK_TIMEOUT.to_string()) + .parse::() + .unwrap(); app_args.output = app.value_of("output").unwrap_or("").to_string(); app_args.user_agent = app .value_of("user-agent") diff --git a/src/html.rs b/src/html.rs index 4d34e99..8d6486a 100644 --- a/src/html.rs +++ b/src/html.rs @@ -22,8 +22,7 @@ const ICON_VALUES: &[&str] = &[ "fluid-icon", ]; -const TRANSPARENT_PIXEL: &str = - "data:image/png;base64,\ +const TRANSPARENT_PIXEL: &str = "data:image/png;base64,\ iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII="; pub fn get_parent_node(node: &Handle) -> Handle { diff --git a/src/main.rs b/src/main.rs index a805133..183545f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -65,8 +65,13 @@ fn main() { HeaderValue::from_str(&app_args.user_agent).expect("Invalid User-Agent header specified"), ); + let timeout: u64 = if app_args.timeout > 0 { + app_args.timeout + } else { + std::u64::MAX / 4 + }; let client = Client::builder() - .timeout(Duration::from_secs(10)) + .timeout(Duration::from_secs(timeout)) .danger_accept_invalid_certs(app_args.insecure) .default_headers(header_map) .build()