diff options
| author | Markus Heiser <markus.heiser@darmarit.de> | 2024-08-19 17:47:54 +0200 |
|---|---|---|
| committer | Markus Heiser <markus.heiser@darmarIT.de> | 2024-10-05 08:18:28 +0200 |
| commit | 7ab577a1fba43578b77f56b76275d0e65d03b318 (patch) | |
| tree | 0179516d6d89aab77b542494b4e90b22d22cc9cf /searx/favicon_resolver.py | |
| parent | c49a2707c1ba7122c250ba963a83d095441f4d59 (diff) | |
[mod] Revision of the favicon solution
All favicons implementations have been documented and moved to the Python
package:
searx.favicons
There is a configuration (based on Pydantic) for the favicons and all its
components:
searx.favicons.config
A solution for caching favicons has been implemented:
searx.favicon.cache
If the favicon is already in the cache, the returned URL is a data URL [1]
(something like `data:image/png;base64,...`). By generating a data url from
the FaviconCache, additional HTTP roundtripps via the favicon_proxy are saved:
favicons.proxy.favicon_url
The favicon proxy service now sets a HTTP header "Cache-Control: max-age=...":
favicons.proxy.favicon_proxy
The resolvers now also provide the mime type (data, mime):
searx.favicon.resolvers
[1] https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLs
Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
Diffstat (limited to 'searx/favicon_resolver.py')
| -rw-r--r-- | searx/favicon_resolver.py | 105 |
1 files changed, 0 insertions, 105 deletions
diff --git a/searx/favicon_resolver.py b/searx/favicon_resolver.py deleted file mode 100644 index d292d4ce7..000000000 --- a/searx/favicon_resolver.py +++ /dev/null @@ -1,105 +0,0 @@ -# SPDX-License-Identifier: AGPL-3.0-or-later -"""This module implements functions needed for the favicon resolver. - -""" -# pylint: disable=use-dict-literal - -from httpx import HTTPError - -from searx import settings - -from searx.network import get as http_get, post as http_post -from searx.exceptions import SearxEngineResponseException - - -def update_kwargs(**kwargs): - if 'timeout' not in kwargs: - kwargs['timeout'] = settings['outgoing']['request_timeout'] - kwargs['raise_for_httperror'] = False - - -def get(*args, **kwargs): - update_kwargs(**kwargs) - return http_get(*args, **kwargs) - - -def post(*args, **kwargs): - update_kwargs(**kwargs) - return http_post(*args, **kwargs) - - -def allesedv(domain): - """Favicon Resolver from allesedv.com""" - - url = 'https://f1.allesedv.com/32/{domain}' - - # will just return a 200 regardless of the favicon existing or not - # sometimes will be correct size, sometimes not - response = get(url.format(domain=domain)) - - # returns image/gif if the favicon does not exist - if response.headers['Content-Type'] == 'image/gif': - return [] - - return response.content - - -def duckduckgo(domain): - """Favicon Resolver from duckduckgo.com""" - - url = 'https://icons.duckduckgo.com/ip2/{domain}.ico' - - # will return a 404 if the favicon does not exist and a 200 if it does, - response = get(url.format(domain=domain)) - - # api will respond with a 32x32 png image - if response.status_code == 200: - return response.content - return [] - - -def google(domain): - """Favicon Resolver from google.com""" - - url = 'https://www.google.com/s2/favicons?sz=32&domain={domain}' - - # will return a 404 if the favicon does not exist and a 200 if it does, - response = get(url.format(domain=domain)) - - # api will respond with a 32x32 png image - if response.status_code == 200: - return response.content - return [] - - -def yandex(domain): - """Favicon Resolver from yandex.com""" - - url = 'https://favicon.yandex.net/favicon/{domain}' - - # will always return 200 - response = get(url.format(domain=domain)) - - # api will respond with a 16x16 png image, if it doesn't exist, it will be a 1x1 png image (70 bytes) - if response.status_code == 200: - if len(response.content) > 70: - return response.content - return [] - - -backends = { - 'allesedv': allesedv, - 'duckduckgo': duckduckgo, - 'google': google, - 'yandex': yandex, -} - - -def search_favicon(backend_name, domain): - backend = backends.get(backend_name) - if backend is None: - return [] - try: - return backend(domain) - except (HTTPError, SearxEngineResponseException): - return [] |