From 13429e32d3e011ea1b7220c7e52c9a6ace5e3a4a Mon Sep 17 00:00:00 2001 From: Vincent Flyson Date: Fri, 23 Aug 2019 16:00:05 -0400 Subject: [PATCH] Allow HTTP redirects and preserve email links --- Cargo.toml | 2 +- src/html.rs | 4 ++-- src/http.rs | 3 ++- src/main.rs | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ca1b409..c0ae12f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "monolith" -version = "2.0.5" +version = "2.0.6" authors = ["Sunshine "] description = "CLI tool to save webpages as a single HTML file" diff --git a/src/html.rs b/src/html.rs index 63c1d7d..0da1aaf 100644 --- a/src/html.rs +++ b/src/html.rs @@ -146,8 +146,8 @@ pub fn walk_and_embed_assets( NodeMatch::Anchor => { for attr in attrs_mut.iter_mut() { if &attr.name.local == "href" { - // Do not touch hrefs which begin with a hash sign - if attr.value.to_string().chars().nth(0) == Some('#') { + // Don't touch email links or hrefs which begin with a hash sign + if attr.value.starts_with('#') || attr.value.starts_with("mailto:") { continue; } diff --git a/src/http.rs b/src/http.rs index 19e064d..b18da0c 100644 --- a/src/http.rs +++ b/src/http.rs @@ -1,6 +1,6 @@ use regex::Regex; use reqwest::header::{CONTENT_TYPE, USER_AGENT}; -use reqwest::Client; +use reqwest::{Client, RedirectPolicy}; use std::time::Duration; use url::{ParseError, Url}; use utils::data_to_dataurl; @@ -75,6 +75,7 @@ pub fn retrieve_asset( Ok(url.to_string()) } else { let client = Client::builder() + .redirect(RedirectPolicy::limited(3)) .timeout(Duration::from_secs(10)) .build() .unwrap(); diff --git a/src/main.rs b/src/main.rs index cfb4872..7988f2f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -22,7 +22,7 @@ fn main() { ) .args_from_usage("-j, --no-js 'Excludes JavaScript'") .args_from_usage("-i, --no-images 'Removes images'") - .args_from_usage("-u, --user-agent= 'Custom User-Agent string'") + .args_from_usage("-u, --user-agent=[Iceweasel] 'Custom User-Agent string'") .get_matches(); // Process the command