add option for custom network request timeout

This commit is contained in:
Sunshine 2020-02-03 00:38:21 -05:00
parent 1e8348543a
commit 727a5a410c
No known key found for this signature in database
GPG key ID: B80CA68703CD8AB1
4 changed files with 17 additions and 4 deletions

View file

@ -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.

View file

@ -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 <file>'")
.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::<u64>()
.unwrap();
app_args.output = app.value_of("output").unwrap_or("").to_string();
app_args.user_agent = app
.value_of("user-agent")

View file

@ -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 {

View file

@ -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()