.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
http_accept_encoding.py
Go to the documentation of this file.
1# SPDX-License-Identifier: AGPL-3.0-or-later
2"""
3Method ``http_accept_encoding``
4-------------------------------
5
6The ``http_accept_encoding`` method evaluates a request as the request of a
7bot if the Accept-Encoding_ header ..
8
9- did not contain ``gzip`` AND ``deflate`` (if both values are missed)
10- did not contain ``text/html``
11
12.. _Accept-Encoding:
13 https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Encoding
14
15"""
16
17from __future__ import annotations
18from ipaddress import (
19 IPv4Network,
20 IPv6Network,
21)
22
23import werkzeug
24import flask
25
26from . import config
27from ._helpers import too_many_requests
28
29
31 network: IPv4Network | IPv6Network,
32 request: flask.Request,
33 cfg: config.Config, # pylint: disable=unused-argument
34) -> werkzeug.Response | None:
35
36 accept_list = [l.strip() for l in request.headers.get('Accept-Encoding', '').split(',')]
37 if not ('gzip' in accept_list or 'deflate' in accept_list):
38 return too_many_requests(network, "HTTP header Accept-Encoding did not contain gzip nor deflate")
39 return None
werkzeug.Response|None filter_request(IPv4Network|IPv6Network network, flask.Request request, config.Config cfg)