bump httpx dependency version to 0.11.1 (#1794)

This commit is contained in:
Subham Roy
2020-03-02 01:12:11 +05:30
committed by GitHub
parent 7833d70d9e
commit ce71514d71
6 changed files with 47 additions and 32 deletions

View File

@@ -18,6 +18,22 @@ old_conn = None
class ReusableSanicConnectionPool(
httpx.dispatch.connection_pool.ConnectionPool
):
@property
def cert(self):
return self.ssl.cert
@property
def verify(self):
return self.ssl.verify
@property
def trust_env(self):
return self.ssl.trust_env
@property
def http2(self):
return self.ssl.http2
async def acquire_connection(self, origin, timeout):
global old_conn
connection = self.pop_connection(origin)
@@ -26,14 +42,17 @@ class ReusableSanicConnectionPool(
pool_timeout = None if timeout is None else timeout.pool_timeout
await self.max_connections.acquire(timeout=pool_timeout)
ssl_config = httpx.config.SSLConfig(
cert=self.cert,
verify=self.verify,
trust_env=self.trust_env,
http2=self.http2
)
connection = httpx.dispatch.connection.HTTPConnection(
origin,
verify=self.verify,
cert=self.cert,
http2=self.http2,
ssl=ssl_config,
backend=self.backend,
release_func=self.release_connection,
trust_env=self.trust_env,
uds=self.uds,
)
@@ -49,7 +68,7 @@ class ReusableSanicConnectionPool(
return connection
class ResusableSanicSession(httpx.Client):
class ResusableSanicSession(httpx.AsyncClient):
def __init__(self, *args, **kwargs) -> None:
dispatch = ReusableSanicConnectionPool()
super().__init__(dispatch=dispatch, *args, **kwargs)
@@ -159,7 +178,7 @@ class ReuseableSanicTestClient(SanicTestClient):
self._server = None
if self._session:
self._loop.run_until_complete(self._session.close())
self._loop.run_until_complete(self._session.aclose())
self._session = None
except Exception as e3:
@@ -178,7 +197,7 @@ class ReuseableSanicTestClient(SanicTestClient):
self._session = self.get_new_session()
try:
response = await getattr(self._session, method.lower())(
url, verify=False, timeout=request_keepalive, *args, **kwargs
url, timeout=request_keepalive, *args, **kwargs
)
except NameError:
raise Exception(response.status_code)
@@ -188,7 +207,7 @@ class ReuseableSanicTestClient(SanicTestClient):
except (JSONDecodeError, UnicodeDecodeError):
response.json = None
response.body = await response.read()
response.body = await response.aread()
response.status = response.status_code
response.content_type = response.headers.get("content-type")

View File

@@ -14,18 +14,15 @@ class DelayableHTTPConnection(httpx.dispatch.connection.HTTPConnection):
self._request_delay = kwargs.pop("request_delay")
super().__init__(*args, **kwargs)
async def send(self, request, verify=None, cert=None, timeout=None):
if self.h11_connection is None and self.h2_connection is None:
await self.connect(verify=verify, cert=cert, timeout=timeout)
async def send(self, request, timeout=None):
if self.connection is None:
self.connection = (await self.connect(timeout=timeout))
if self._request_delay:
await asyncio.sleep(self._request_delay)
if self.h2_connection is not None:
response = await self.h2_connection.send(request, timeout=timeout)
else:
assert self.h11_connection is not None
response = await self.h11_connection.send(request, timeout=timeout)
response = await self.connection.send(request, timeout=timeout)
return response
@@ -46,12 +43,9 @@ class DelayableSanicConnectionPool(
await self.max_connections.acquire(timeout=pool_timeout)
connection = DelayableHTTPConnection(
origin,
verify=self.verify,
cert=self.cert,
http2=self.http2,
ssl=self.ssl,
backend=self.backend,
release_func=self.release_connection,
trust_env=self.trust_env,
uds=self.uds,
request_delay=self._request_delay,
)
@@ -61,7 +55,7 @@ class DelayableSanicConnectionPool(
return connection
class DelayableSanicSession(httpx.Client):
class DelayableSanicSession(httpx.AsyncClient):
def __init__(self, request_delay=None, *args, **kwargs) -> None:
dispatch = DelayableSanicConnectionPool(request_delay=request_delay)
super().__init__(dispatch=dispatch, *args, **kwargs)