.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
http_connection.py
Go to the documentation of this file.
1# SPDX-License-Identifier: AGPL-3.0-or-later
2"""
3Method ``http_connection``
4--------------------------
5
6The ``http_connection`` method evaluates a request as the request of a bot if
7the Connection_ header is set to ``close``.
8
9.. _Connection:
10 https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Connection
11
12"""
13
14from __future__ import annotations
15from ipaddress import (
16 IPv4Network,
17 IPv6Network,
18)
19
20import werkzeug
21
22from searx.extended_types import SXNG_Request
23
24from . import config
25from ._helpers import too_many_requests
26
27
29 network: IPv4Network | IPv6Network,
30 request: SXNG_Request,
31 cfg: config.Config, # pylint: disable=unused-argument
32) -> werkzeug.Response | None:
33
34 if request.headers.get('Connection', '').strip() == 'close':
35 return too_many_requests(network, "HTTP header 'Connection=close")
36 return None
werkzeug.Response|None filter_request(IPv4Network|IPv6Network network, SXNG_Request request, config.Config cfg)