summaryrefslogtreecommitdiff
path: root/qutebrowser/api/interceptor.py
blob: c5bfc807d6f19fe787707dd33e0733761baace39 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Copyright 2018-2021 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
#
# SPDX-License-Identifier: GPL-3.0-or-later

"""APIs related to intercepting/blocking requests."""

from qutebrowser.extensions import interceptors
# pylint: disable=unused-import
from qutebrowser.extensions.interceptors import Request


#: Type annotation for an interceptor function.
InterceptorType = interceptors.InterceptorType

#: Possible resource types for requests sent to interceptor.
ResourceType = interceptors.ResourceType


def register(interceptor: InterceptorType) -> None:
    """Register a request interceptor.

    Whenever a request happens, the interceptor gets called with a
    :class:`Request` object.

    Example::

        def intercept(request: interceptor.Request) -> None:
            if request.request_url.host() == 'badhost.example.com':
                request.block()
    """
    interceptors.register(interceptor)