File tree 3 files changed +37
-1
lines changed
3 files changed +37
-1
lines changed Original file line number Diff line number Diff line change
1
+ Fixed proxy headers being used in the ``ConnectionKey `` hash when a proxy was not being used -- by :user: `bdraco `.
2
+
3
+ If default headers are used, they are also used for proxy headers. This could have led to creating connections that were not needed when one was already available.
Original file line number Diff line number Diff line change @@ -626,10 +626,16 @@ def update_proxy(
626
626
proxy_auth : Optional [BasicAuth ],
627
627
proxy_headers : Optional [LooseHeaders ],
628
628
) -> None :
629
+ self .proxy = proxy
630
+ if proxy is None :
631
+ self .proxy_auth = None
632
+ self .proxy_headers = None
633
+ return
634
+
629
635
if proxy_auth and not isinstance (proxy_auth , helpers .BasicAuth ):
630
636
raise ValueError ("proxy_auth must be None or BasicAuth() tuple" )
631
- self .proxy = proxy
632
637
self .proxy_auth = proxy_auth
638
+
633
639
if proxy_headers is not None and not isinstance (
634
640
proxy_headers , (MultiDict , MultiDictProxy )
635
641
):
Original file line number Diff line number Diff line change @@ -1467,3 +1467,30 @@ def test_basicauth_from_empty_netrc(
1467
1467
"""Test that no Authorization header is sent when netrc is empty"""
1468
1468
req = make_request ("get" , "http://example.com" , trust_env = True )
1469
1469
assert hdrs .AUTHORIZATION not in req .headers
1470
+
1471
+
1472
+ async def test_connection_key_with_proxy () -> None :
1473
+ """Verify the proxy headers are included in the ConnectionKey when a proxy is used."""
1474
+ proxy = URL ("http://proxy.example.com" )
1475
+ req = ClientRequest (
1476
+ "GET" ,
1477
+ URL ("http://example.com" ),
1478
+ proxy = proxy ,
1479
+ proxy_headers = {"X-Proxy" : "true" },
1480
+ loop = asyncio .get_running_loop (),
1481
+ )
1482
+ assert req .connection_key .proxy_headers_hash is not None
1483
+ await req .close ()
1484
+
1485
+
1486
+ async def test_connection_key_without_proxy () -> None :
1487
+ """Verify the proxy headers are not included in the ConnectionKey when a proxy is used."""
1488
+ # If proxy is unspecified, proxy_headers should be ignored
1489
+ req = ClientRequest (
1490
+ "GET" ,
1491
+ URL ("http://example.com" ),
1492
+ proxy_headers = {"X-Proxy" : "true" },
1493
+ loop = asyncio .get_running_loop (),
1494
+ )
1495
+ assert req .connection_key .proxy_headers_hash is None
1496
+ await req .close ()
You can’t perform that action at this time.
0 commit comments