• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

funilrys / PyFunceble / 16098639223

06 Jul 2025 11:41AM UTC coverage: 96.648% (-0.01%) from 96.659%
16098639223

push

github

funilrys
Bump version to v4.3.0a24.dev

1 of 1 new or added line in 1 file covered. (100.0%)

14 existing lines in 4 files now uncovered.

11967 of 12382 relevant lines covered (96.65%)

14.23 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

28.57
/PyFunceble/query/requests/adapter/http.py
1
"""
2
The tool to check the availability or syntax of domain, IP or URL.
3

4
::
5

6

7
    ██████╗ ██╗   ██╗███████╗██╗   ██╗███╗   ██╗ ██████╗███████╗██████╗ ██╗     ███████╗
8
    ██╔══██╗╚██╗ ██╔╝██╔════╝██║   ██║████╗  ██║██╔════╝██╔════╝██╔══██╗██║     ██╔════╝
9
    ██████╔╝ ╚████╔╝ █████╗  ██║   ██║██╔██╗ ██║██║     █████╗  ██████╔╝██║     █████╗
10
    ██╔═══╝   ╚██╔╝  ██╔══╝  ██║   ██║██║╚██╗██║██║     ██╔══╝  ██╔══██╗██║     ██╔══╝
11
    ██║        ██║   ██║     ╚██████╔╝██║ ╚████║╚██████╗███████╗██████╔╝███████╗███████╗
12
    ╚═╝        ╚═╝   ╚═╝      ╚═════╝ ╚═╝  ╚═══╝ ╚═════╝╚══════╝╚═════╝ ╚══════╝╚══════╝
13

14
Provides the our HTTP adapter.
15

16
Author:
17
    Nissar Chababy, @funilrys, contactTATAfunilrysTODTODcom
18

19
Special thanks:
20
    https://pyfunceble.github.io/#/special-thanks
21

22
Contributors:
23
    https://pyfunceble.github.io/#/contributors
24

25
Project link:
26
    https://github.com/funilrys/PyFunceble
27

28
Project documentation:
29
    https://docs.pyfunceble.com
30

31
Project homepage:
32
    https://pyfunceble.github.io/
33

34
License:
35
::
36

37

38
    Copyright 2017, 2018, 2019, 2020, 2022, 2023, 2024, 2025 Nissar Chababy
39

40
    Licensed under the Apache License, Version 2.0 (the "License");
41
    you may not use this file except in compliance with the License.
42
    You may obtain a copy of the License at
43

44
        https://www.apache.org/licenses/LICENSE-2.0
45

46
    Unless required by applicable law or agreed to in writing, software
47
    distributed under the License is distributed on an "AS IS" BASIS,
48
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
49
    See the License for the specific language governing permissions and
50
    limitations under the License.
51
"""
52

53
import urllib.parse
15✔
54

55
import requests
15✔
56

57
import PyFunceble.facility
15✔
58
from PyFunceble.query.requests.adapter.base import RequestAdapterBase
15✔
59

60

61
class RequestHTTPAdapter(RequestAdapterBase):
15✔
62
    """
63
    Provides our HTTP adapter.
64
    """
65

66
    # pylint: disable=arguments-differ
67
    def send(self, request, **kwargs) -> requests.Response:
15✔
68
        """
69
        Overwrite the upstream :code:`send` method.
70

71
        We basically do the same. We only ensure that we request the IP from the chosen
72
        DNS record.
73

74
        :param request: The :class:`PreparedRequest <PreparedRequest>` being sent.
75
        :param stream: (optional) Whether to stream the request content.
76
        :param timeout: (optional) How long to wait for the server to send
77
            data before giving up, as a float, or
78
            a :ref:`(connect timeout, read timeout) <timeouts>` tuple.
79
        :type timeout: float or tuple or urllib3 Timeout object
80
        :param verify: (optional) Either a boolean, in which case it controls whether
81
            we verify the server's TLS certificate, or a string, in which case it
82
            must be a path to a CA bundle to use
83
        :param cert: (optional) Any user-provided SSL certificate to be trusted.
84
        :param proxies: (optional) The proxies dictionary to apply to the request.
85
        :rtype: requests.Response
86

87
        .. versionchanged:: 4.1.0b16
88
            When a proxy is given, it is acceptable to have an unresolvable
89
            subject. The proxy should handle the situation and give us back a
90
            proper status or error.
91
        """
92

93
        kwargs["timeout"] = self.timeout
×
94

95
        parsed_url = urllib.parse.urlparse(request.url)
×
96
        hostname_ip = self.resolve(parsed_url.hostname)
×
97

98
        kwargs["proxies"] = self.fetch_proxy_from_pattern(parsed_url.hostname)
×
99

100
        PyFunceble.facility.Logger.debug("Parsed URL: %r", parsed_url)
101
        PyFunceble.facility.Logger.debug("Resolved IP: %r", hostname_ip)
102
        PyFunceble.facility.Logger.debug("KWARGS: %r", kwargs)
103
        PyFunceble.facility.Logger.debug(
104
            "Pool Manager: %r", self.poolmanager.connection_pool_kw
105
        )
106

107
        if hostname_ip or kwargs["proxies"]:
×
108
            if hostname_ip:
×
109
                request.url = request.url.replace(
×
110
                    f"{parsed_url.scheme}://{parsed_url.hostname}",
111
                    f"{parsed_url.scheme}://{hostname_ip}",
112
                )
113

114
            # Ensure that the Hosts header is present. Otherwise, connection might
115
            # not work.
116
            request.headers["Host"] = parsed_url.hostname
×
117
        else:
118
            self.poolmanager.connection_pool_kw.pop(
×
119
                "server_hostname", self.NOT_RESOLVED_STD_HOSTNAME
120
            )
121
            self.poolmanager.connection_pool_kw.pop(
×
122
                "assert_hostname", self.NOT_RESOLVED_STD_HOSTNAME
123
            )
124

125
            return self.fake_response()
×
126

UNCOV
127
        response = super().send(request, **kwargs)
×
128

UNCOV
129
        if hostname_ip:
×
130
            response.url = response.url.replace(hostname_ip, parsed_url.hostname)
×
131

UNCOV
132
        return response
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc