.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# pylint: disable=unused-argument
14
15from __future__ import annotations
16from ipaddress import (
17 IPv4Network,
18 IPv6Network,
19)
20
21import flask
22import werkzeug
23
24from . import config
25from ._helpers import too_many_requests
26
27
29 network: IPv4Network | IPv6Network,
30 request: flask.Request,
31 cfg: config.Config,
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, flask.Request request, config.Config cfg)