Skip to content

[feature required] does we can add the timeout or proxy parameters directly #711

@a358003542

Description

@a358003542

Like this, we will directly have the proxy and timeout parameters for the ClientSession, this will be very convenient in some situation.

class Client(aiohttp.ClientSession):
    '''
based on aiohttp's ClientSession,and add:
- proxy proxy_auth (user,pass)
- timeout

    '''
    def __init__(self,timeout=None,proxy=None,proxy_auth=None,*args,**kwargs):
        self.timeout = timeout

        conn = None
        if proxy:### handle proxy
            if proxy_auth:
                conn = aiohttp.ProxyConnector(proxy=proxy,proxy_auth=aiohttp.BasicAuth(proxy_auth[0], proxy_auth[1]))
            else:
                conn = aiohttp.ProxyConnector(proxy=proxy)

        super().__init__(connector=conn,*args,**kwargs)


    def _request(self,*args,**kwargs):
        return asyncio.wait_for(super()._request(*args,**kwargs), self.timeout)

    def _ws_connect(self,*args,**kwargs):
        return asyncio.wait_for(super()._ws_connect(*args,**kwargs), self.timeout)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions