add support for inverting whitelist
This commit is contained in:
parent
e89b79492b
commit
116c556e09
2 changed files with 18 additions and 7 deletions
|
@ -53,7 +53,7 @@ impl Options {
|
|||
.args_from_usage("-c, --no-css 'Removes CSS'")
|
||||
.args_from_usage("-C, --charset=[UTF-8] 'Enforces custom encoding'")
|
||||
.args_from_usage(
|
||||
"-D, --domains=[bad.org,ads.site,0.0.0.0,127.0.0.0:8080] 'Whitelist of domains'",
|
||||
"-D, --domains=[bad.org,ads.site,127.0.0.0:8080] 'Whitelist of domains'",
|
||||
)
|
||||
.args_from_usage("-e, --ignore-errors 'Ignore network errors'")
|
||||
.args_from_usage("-E, --exclude-domains 'Treat list of specified domains as blacklist'")
|
||||
|
|
11
src/utils.rs
11
src/utils.rs
|
@ -266,6 +266,7 @@ pub fn retrieve_asset(
|
|||
"".to_string(),
|
||||
))
|
||||
} else {
|
||||
if options.exclude_domains {
|
||||
if let Some(domains) = &options.domains {
|
||||
if domains
|
||||
.iter()
|
||||
|
@ -274,6 +275,16 @@ pub fn retrieve_asset(
|
|||
return Err(client.get("").send().unwrap_err());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if let Some(domains) = &options.domains {
|
||||
if domains
|
||||
.iter()
|
||||
.any(|d| !domain_is_within_domain(url.host_str().unwrap(), &d.trim()))
|
||||
{
|
||||
return Err(client.get("").send().unwrap_err());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// URL not in cache, we retrieve the file
|
||||
match client.get(url.as_str()).send() {
|
||||
|
|
Loading…
Reference in a new issue