http_accept_language.py 772 B

123456789101112131415161718192021222324252627
  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
  13. import flask
  14. import werkzeug
  15. from searx.tools import config
  16. from ._helpers import too_many_requests
  17. def filter_request(request: flask.Request, cfg: config.Config) -> Optional[werkzeug.Response]:
  18. if request.headers.get('Accept-Language', '').strip() == '':
  19. return too_many_requests(request, "missing HTTP header Accept-Language")
  20. return None