add option for custom network request timeout

pull/114/head
Sunshine 4 years ago
parent 1e8348543a
commit 727a5a410c
No known key found for this signature in database
GPG Key ID: B80CA68703CD8AB1

@ -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 - `-k`: Accept invalid X.509 (TLS) certificates
- `-o`: Write output to file - `-o`: Write output to file
- `-s`: Silent mode - `-s`: Silent mode
- `-t`: Set custom network request timeout (in seconds)
- `-u`: Specify custom User-Agent - `-u`: Specify custom User-Agent
## HTTPS and HTTP proxies ## 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 ## Contributing
Please open an issue if something is wrong, that helps make this project better. Please open an issue if something is wrong, that helps make this project better.

@ -11,9 +11,11 @@ pub struct AppArgs {
pub isolate: bool, pub isolate: bool,
pub output: String, pub output: String,
pub silent: bool, pub silent: bool,
pub timeout: u64,
pub user_agent: String, pub user_agent: String,
} }
const DEFAULT_NETWORK_TIMEOUT: u64 = 120;
const DEFAULT_USER_AGENT: &str = const DEFAULT_USER_AGENT: &str =
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:66.0) Gecko/20100101 Firefox/66.0"; "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("-k, --insecure 'Accept invalid X.509 (TLS) certificates'")
.args_from_usage("-o, --output=[document.html] 'Write output to <file>'") .args_from_usage("-o, --output=[document.html] 'Write output to <file>'")
.args_from_usage("-s, --silent 'Suppress verbosity'") .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("-u, --user-agent=[Iceweasel] 'Custom User-Agent string'")
// .args_from_usage("-v, --include-video 'Embed video sources'") // .args_from_usage("-v, --include-video 'Embed video sources'")
.get_matches(); .get_matches();
@ -55,6 +58,11 @@ impl AppArgs {
app_args.insecure = app.is_present("insecure"); app_args.insecure = app.is_present("insecure");
app_args.isolate = app.is_present("isolate"); app_args.isolate = app.is_present("isolate");
app_args.silent = app.is_present("silent"); 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.output = app.value_of("output").unwrap_or("").to_string();
app_args.user_agent = app app_args.user_agent = app
.value_of("user-agent") .value_of("user-agent")

@ -22,8 +22,7 @@ const ICON_VALUES: &[&str] = &[
"fluid-icon", "fluid-icon",
]; ];
const TRANSPARENT_PIXEL: &str = const TRANSPARENT_PIXEL: &str = "data:image/png;base64,\
"data:image/png;base64,\
iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII="; iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=";
pub fn get_parent_node(node: &Handle) -> Handle { pub fn get_parent_node(node: &Handle) -> Handle {

@ -65,8 +65,13 @@ fn main() {
HeaderValue::from_str(&app_args.user_agent).expect("Invalid User-Agent header specified"), 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() let client = Client::builder()
.timeout(Duration::from_secs(10)) .timeout(Duration::from_secs(timeout))
.danger_accept_invalid_certs(app_args.insecure) .danger_accept_invalid_certs(app_args.insecure)
.default_headers(header_map) .default_headers(header_map)
.build() .build()

Loading…
Cancel
Save