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

funilrys / PyFunceble / 9637396124

23 Jun 2024 08:22PM CUT coverage: 94.723%. Remained the same
9637396124

push

github

funilrys
Bump version to v4.2.24.dev

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

11326 of 11957 relevant lines covered (94.72%)

14.17 hits per line

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

25.93
/PyFunceble/query/requests/adapter/https.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 HTTPS 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://pyfunceble.readthedocs.io/en/dev/
30

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

34
License:
35
::
36

37

38
    Copyright 2017, 2018, 2019, 2020, 2022, 2023, 2024 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
import PyFunceble.storage
15✔
59
from PyFunceble.query.requests.adapter.base import RequestAdapterBase
15✔
60

61

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

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

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

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

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

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

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

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

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

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

115
            if parsed_url.scheme == "https":
×
116
                self.poolmanager.connection_pool_kw["server_hostname"] = (
×
117
                    parsed_url.hostname
118
                )
119
                self.poolmanager.connection_pool_kw["assert_hostname"] = (
×
120
                    parsed_url.hostname
121
                )
122

123
            # Ensure that the Hosts header is present. Otherwise, connection might
124
            # not work.
125
            request.headers["Host"] = parsed_url.hostname
×
126
        else:
127
            self.poolmanager.connection_pool_kw.pop(
×
128
                "server_hostname", PyFunceble.storage.NOT_RESOLVED_STD_HOSTNAME
129
            )
130
            self.poolmanager.connection_pool_kw.pop(
×
131
                "assert_hostname", PyFunceble.storage.NOT_RESOLVED_STD_HOSTNAME
132
            )
133

134
            self.poolmanager.connection_pool_kw.pop(
×
135
                "server_hostname", parsed_url.hostname
136
            )
137
            self.poolmanager.connection_pool_kw.pop(
×
138
                "assert_hostname", parsed_url.hostname
139
            )
140

141
            return self.fake_response()
×
142

143
        response = super().send(request, **kwargs)
×
144

145
        if hostname_ip:
×
146
            response.url = response.url.replace(hostname_ip, parsed_url.hostname)
×
147

148
        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

© 2025 Coveralls, Inc