http_accept_language.py 897 B

123456789101112131415161718192021222324252627282930313233343536
  1. # SPDX-License-Identifier: AGPL-3.0-or-later
  2. """
  3. Method ``http_accept_language``
  4. -------------------------------
  5. The ``http_accept_language`` method evaluates a request as the request of a bot
  6. if the Accept-Language_ header is unset.
  7. .. _Accept-Language:
  8. https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent
  9. """
  10. from __future__ import annotations
  11. from ipaddress import (
  12. IPv4Network,
  13. IPv6Network,
  14. )
  15. import werkzeug
  16. from searx.extended_types import SXNG_Request
  17. from . import config
  18. from ._helpers import too_many_requests
  19. def filter_request(
  20. network: IPv4Network | IPv6Network,
  21. request: SXNG_Request,
  22. cfg: config.Config, # pylint: disable=unused-argument
  23. ) -> werkzeug.Response | None:
  24. if request.headers.get('Accept-Language', '').strip() == '':
  25. return too_many_requests(network, "missing HTTP header Accept-Language")
  26. return None