http_accept.py 685 B

123456789101112131415161718192021222324252627
  1. # SPDX-License-Identifier: AGPL-3.0-or-later
  2. # lint: pylint
  3. """
  4. Method ``http_accept``
  5. ----------------------
  6. The ``http_accept`` method evaluates a request as the request of a bot if the
  7. Accept_ header ..
  8. - did not contain ``text/html``
  9. .. _Accept:
  10. https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept
  11. """
  12. # pylint: disable=unused-argument
  13. from typing import Optional, Tuple
  14. import flask
  15. from searx.tools import config
  16. def filter_request(request: flask.Request, cfg: config.Config) -> Optional[Tuple[int, str]]:
  17. if 'text/html' not in request.accept_mimetypes:
  18. return 429, "bot detected, HTTP header Accept did not contain text/html"
  19. return None