简体   繁体   中英

aiohtttp connection pooling with ProxyConnector

I was wondering if anyone knows how to do connection pooling with aiohttp using the ProxyConnector as the connector?

The docs mention how to do this with the TcpConnector or using the Session class, but I can not seem to figure it out.

Thanks.

The ClientSession object , which handles connection pooling, takes a connector keyword argument:

class aiohttp.client.ClientSession(*, connector=None, loop=None, request_class=None, response_class=None, cookies=None, headers=None, auth=None)

if no connector is given, a TCPConnector will be used by default, but you can just specify a ProxyConnector instance, and that will be used instead. You can see this logic in the source:

class ClientSession:

    def __init__(self, *, connector=None, loop=None, request_class=None,
                 response_class=None, cookies=None, headers=None, auth=None):
        if loop is None:
            loop = asyncio.get_event_loop()
        self._loop = loop
        self.cookies = http.cookies.SimpleCookie()
        if connector is None:
            connector = aiohttp.TCPConnector(force_close=True, loop=loop)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM