http_accept.py 745 B

1234567891011121314151617181920212223242526272829
  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
  14. import flask
  15. import werkzeug
  16. from searx.tools import config
  17. from ._helpers import too_many_requests
  18. def filter_request(request: flask.Request, cfg: config.Config) -> Optional[werkzeug.Response]:
  19. if 'text/html' not in request.accept_mimetypes:
  20. return too_many_requests(request, "HTTP header Accept did not contain text/html")
  21. return None