|
3 | 3 | import io
|
4 | 4 | import json
|
5 | 5 | import logging
|
| 6 | +import warnings |
6 | 7 | from ssl import SSLContext
|
7 |
| -from typing import Any, AsyncGenerator, Callable, Dict, Optional, Tuple, Type, Union |
| 8 | +from typing import ( |
| 9 | + Any, |
| 10 | + AsyncGenerator, |
| 11 | + Callable, |
| 12 | + Dict, |
| 13 | + Optional, |
| 14 | + Tuple, |
| 15 | + Type, |
| 16 | + Union, |
| 17 | + cast, |
| 18 | +) |
8 | 19 |
|
9 | 20 | import aiohttp
|
10 | 21 | from aiohttp.client_exceptions import ClientResponseError
|
@@ -46,7 +57,7 @@ def __init__(
|
46 | 57 | headers: Optional[LooseHeaders] = None,
|
47 | 58 | cookies: Optional[LooseCookies] = None,
|
48 | 59 | auth: Optional[Union[BasicAuth, "AppSyncAuthentication"]] = None,
|
49 |
| - ssl: Union[SSLContext, bool, Fingerprint] = False, |
| 60 | + ssl: Union[SSLContext, bool, Fingerprint, str] = "ssl_warning", |
50 | 61 | timeout: Optional[int] = None,
|
51 | 62 | ssl_close_timeout: Optional[Union[int, float]] = 10,
|
52 | 63 | json_serialize: Callable = json.dumps,
|
@@ -74,7 +85,20 @@ def __init__(
|
74 | 85 | self.headers: Optional[LooseHeaders] = headers
|
75 | 86 | self.cookies: Optional[LooseCookies] = cookies
|
76 | 87 | self.auth: Optional[Union[BasicAuth, "AppSyncAuthentication"]] = auth
|
77 |
| - self.ssl: Union[SSLContext, bool, Fingerprint] = ssl |
| 88 | + |
| 89 | + if ssl == "ssl_warning": |
| 90 | + ssl = False |
| 91 | + if str(url).startswith("https"): |
| 92 | + warnings.warn( |
| 93 | + "WARNING: By default, AIOHTTPTransport does not verify" |
| 94 | + " ssl certificates. This will be fixed in the next major version." |
| 95 | + " You can set ssl=True to force the ssl certificate verification" |
| 96 | + " or ssl=False to disable this warning" |
| 97 | + ) |
| 98 | + |
| 99 | + self.ssl: Union[SSLContext, bool, Fingerprint] = cast( |
| 100 | + Union[SSLContext, bool, Fingerprint], ssl |
| 101 | + ) |
78 | 102 | self.timeout: Optional[int] = timeout
|
79 | 103 | self.ssl_close_timeout: Optional[Union[int, float]] = ssl_close_timeout
|
80 | 104 | self.client_session_args = client_session_args
|
|
0 commit comments