File tree 5 files changed +53
-1
lines changed
5 files changed +53
-1
lines changed Original file line number Diff line number Diff line change
1
+ Disabled TLS in TLS warning (when using HTTPS proxies) for uvloop and newer Python versions -- by :user: `lezgomatt `.
Original file line number Diff line number Diff line change @@ -250,6 +250,7 @@ Martin Sucha
250
250
Mathias Fröjdman
251
251
Mathieu Dugré
252
252
Matt VanEseltine
253
+ Matthew Go
253
254
Matthias Marquardt
254
255
Matthieu Hauglustaine
255
256
Matthieu Rigal
Original file line number Diff line number Diff line change @@ -1150,7 +1150,13 @@ def _warn_about_tls_in_tls(
1150
1150
if req .request_info .url .scheme != "https" :
1151
1151
return
1152
1152
1153
- asyncio_supports_tls_in_tls = getattr (
1153
+ # Check if uvloop is being used, which supports TLS in TLS,
1154
+ # otherwise assume that asyncio's native transport is being used.
1155
+ if type (underlying_transport ).__module__ .startswith ("uvloop" ):
1156
+ return
1157
+
1158
+ # Support in asyncio was added in Python 3.11 (bpo-44011)
1159
+ asyncio_supports_tls_in_tls = sys .version_info >= (3 , 11 ) or getattr (
1154
1160
underlying_transport ,
1155
1161
"_start_tls_compatible" ,
1156
1162
False ,
Original file line number Diff line number Diff line change 32
32
except ImportError :
33
33
TRUSTME = False
34
34
35
+
36
+ try :
37
+ import uvloop
38
+ except ImportError :
39
+ uvloop = None # type: ignore[assignment]
40
+
41
+
35
42
pytest_plugins = ("aiohttp.pytest_plugin" , "pytester" )
36
43
37
44
IS_HPUX = sys .platform .startswith ("hp-ux" )
@@ -234,6 +241,16 @@ def selector_loop() -> Iterator[asyncio.AbstractEventLoop]:
234
241
yield _loop
235
242
236
243
244
+ @pytest .fixture
245
+ def uvloop_loop () -> Iterator [asyncio .AbstractEventLoop ]:
246
+ policy = uvloop .EventLoopPolicy ()
247
+ asyncio .set_event_loop_policy (policy )
248
+
249
+ with loop_context (policy .new_event_loop ) as _loop :
250
+ asyncio .set_event_loop (_loop )
251
+ yield _loop
252
+
253
+
237
254
@pytest .fixture
238
255
def netrc_contents (
239
256
tmp_path : Path ,
Original file line number Diff line number Diff line change 1
1
import asyncio
2
2
import os
3
3
import pathlib
4
+ import platform
4
5
import ssl
5
6
import sys
6
7
from re import match as match_regex
@@ -240,6 +241,32 @@ async def test_https_proxy_unsupported_tls_in_tls(
240
241
await asyncio .sleep (0.1 )
241
242
242
243
244
+ @pytest .mark .usefixtures ("uvloop_loop" )
245
+ @pytest .mark .skipif (
246
+ platform .system () == "Windows" or sys .implementation .name != "cpython" ,
247
+ reason = "uvloop is not supported on Windows and non-CPython implementations" ,
248
+ )
249
+ @pytest .mark .filterwarnings (r"ignore:.*ssl.OP_NO_SSL*" )
250
+ # Filter out the warning from
251
+ # https://github.com/abhinavsingh/proxy.py/blob/30574fd0414005dfa8792a6e797023e862bdcf43/proxy/common/utils.py#L226
252
+ # otherwise this test will fail because the proxy will die with an error.
253
+ async def test_uvloop_secure_https_proxy (
254
+ client_ssl_ctx : ssl .SSLContext ,
255
+ secure_proxy_url : URL ,
256
+ ) -> None :
257
+ """Ensure HTTPS sites are accessible through a secure proxy without warning when using uvloop."""
258
+ conn = aiohttp .TCPConnector ()
259
+ sess = aiohttp .ClientSession (connector = conn )
260
+ url = URL ("https://example.com" )
261
+
262
+ async with sess .get (url , proxy = secure_proxy_url , ssl = client_ssl_ctx ) as response :
263
+ assert response .status == 200
264
+
265
+ await sess .close ()
266
+ await conn .close ()
267
+ await asyncio .sleep (0.1 )
268
+
269
+
243
270
@pytest .fixture
244
271
def proxy_test_server (
245
272
aiohttp_raw_server : AiohttpRawServer ,
You can’t perform that action at this time.
0 commit comments