http_connection.py 752 B

123456789101112131415161718192021222324252627
  1. # SPDX-License-Identifier: AGPL-3.0-or-later
  2. # lint: pylint
  3. """
  4. Method ``http_connection``
  5. --------------------------
  6. The ``http_connection`` method evaluates a request as the request of a bot if
  7. the Connection_ header is set to ``close``.
  8. .. _Connection:
  9. https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Connection
  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('Connection', '').strip() == 'close':
  19. return too_many_requests(request, "HTTP header 'Connection=close")
  20. return None