make blocking subdomains configurable
This commit is contained in:
parent
5b0365ddee
commit
38ec7f61c8
|
|
@ -142,6 +142,7 @@
|
|||
|<<content.autoplay,content.autoplay>>|Automatically start playing `<video>` elements.
|
||||
|<<content.blocking.adblock.lists,content.blocking.adblock.lists>>|List of URLs to ABP-style adblocking rulesets.
|
||||
|<<content.blocking.enabled,content.blocking.enabled>>|Enable the ad/host blocker
|
||||
|<<content.blocking.hosts.block_subdomains,content.blocking.hosts.block_subdomains>>|Block subdomains of blocked hosts.
|
||||
|<<content.blocking.hosts.lists,content.blocking.hosts.lists>>|List of URLs to host blocklists for the host blocker.
|
||||
|<<content.blocking.method,content.blocking.method>>|Which method of blocking ads should be used.
|
||||
|<<content.blocking.whitelist,content.blocking.whitelist>>|A list of patterns that should always be loaded, despite being blocked by the ad-/host-blocker.
|
||||
|
|
@ -1994,6 +1995,14 @@ Type: <<types,Bool>>
|
|||
|
||||
Default: +pass:[true]+
|
||||
|
||||
[[content.blocking.hosts.block_subdomains]]
|
||||
=== content.blocking.hosts.block_subdomains
|
||||
Block subdomains of blocked hosts.
|
||||
|
||||
Type: <<types,Bool>>
|
||||
|
||||
Default: +pass:[true]+
|
||||
|
||||
[[content.blocking.hosts.lists]]
|
||||
=== content.blocking.hosts.lists
|
||||
List of URLs to host blocklists for the host blocker.
|
||||
|
|
|
|||
|
|
@ -132,10 +132,15 @@ class HostBlocker:
|
|||
|
||||
host = request_url.host()
|
||||
|
||||
return any(
|
||||
hostname in self._blocked_hosts or hostname in self._config_blocked_hosts
|
||||
for hostname in urlutils.widened_hostnames(host)
|
||||
)
|
||||
if config.get("content.blocking.hosts.block_subdomains"):
|
||||
return any(
|
||||
hostname in self._blocked_hosts or hostname in self._config_blocked_hosts
|
||||
for hostname in urlutils.widened_hostnames(host)
|
||||
)
|
||||
else:
|
||||
return (
|
||||
host in self._blocked_hosts or host in self._config_blocked_hosts
|
||||
)
|
||||
|
||||
def filter_request(self, info: interceptor.Request) -> None:
|
||||
"""Block the given request if necessary."""
|
||||
|
|
|
|||
|
|
@ -747,6 +747,11 @@ content.blocking.hosts.lists:
|
|||
|
||||
The file `~/.config/qutebrowser/blocked-hosts` is always read if it exists.
|
||||
|
||||
content.blocking.hosts.block_subdomains:
|
||||
default: true
|
||||
type: Bool
|
||||
desc: Block subdomains of blocked hosts.
|
||||
|
||||
content.blocking.method:
|
||||
default: auto
|
||||
type:
|
||||
|
|
|
|||
|
|
@ -570,4 +570,7 @@ def test_subdomain_blocking(config_stub, host_blocker_factory):
|
|||
config_stub.val.content.blocking.hosts.lists = None
|
||||
host_blocker = host_blocker_factory()
|
||||
host_blocker._blocked_hosts.add("example.com")
|
||||
config_stub.val.content.blocking.hosts.block_subdomains = True
|
||||
assert host_blocker._is_blocked(QUrl("https://subdomain.example.com"))
|
||||
config_stub.val.content.blocking.hosts.block_subdomains = False
|
||||
assert not host_blocker._is_blocked(QUrl("https://subdomain.example.com"))
|
||||
|
|
|
|||
Loading…
Reference in New Issue