http_accept_language.py 712 B

12345678910111213141516171819202122232425
  1. # SPDX-License-Identifier: AGPL-3.0-or-later
  2. # lint: pylint
  3. """
  4. Method ``http_accept_language``
  5. -------------------------------
  6. The ``http_accept_language`` method evaluates a request as the request of a bot
  7. if the Accept-Language_ header is unset.
  8. .. _Accept-Language:
  9. https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent
  10. """
  11. # pylint: disable=unused-argument
  12. from typing import Optional, Tuple
  13. import flask
  14. from searx.tools import config
  15. def filter_request(request: flask.Request, cfg: config.Config) -> Optional[Tuple[int, str]]:
  16. if request.headers.get('Accept-Language', '').strip() == '':
  17. return 429, "bot detected, missing HTTP header Accept-Language"
  18. return None