Skip to content

Commit

Permalink
ENH: Expose the ssl argument for disabling the ssl certification (hyr…
Browse files Browse the repository at this point in the history
  • Loading branch information
cheginit committed Dec 2, 2021
1 parent 0da58df commit f7132cb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion async_retriever/async_retriever.py
Expand Up @@ -2,6 +2,7 @@
import asyncio
import inspect
import socket
import ssl
from pathlib import Path
from typing import Any, Awaitable, Callable, Dict, List, Optional, Tuple, Union

Expand Down Expand Up @@ -72,6 +73,7 @@ async def async_session(
family: int,
timeout: float = 5.0,
expire_after: float = _EXPIRE,
ssl: Union[ssl.SSLContext, bool, None] = None,
) -> Callable[[int], Union[str, Awaitable[Union[str, bytes, Dict[str, Any]]]]]:
"""Create an async session for sending requests.
Expand All @@ -95,6 +97,8 @@ async def async_session(
Timeout for the request, defaults to 5.0.
expire_after : int, optional
Expiration time for the cache in seconds, defaults to 24 hours.
ssl : bool or SSLContext, optional
SSLContext to use for the connection, defaults to None. Set to False to disable.
Returns
-------
Expand All @@ -108,7 +112,7 @@ async def async_session(
timeout=timeout,
)

connector = TCPConnector(family=family)
connector = TCPConnector(family=family, ssl=ssl)

async with CachedSession(
json_serialize=json.dumps,
Expand Down Expand Up @@ -145,6 +149,7 @@ def retrieve(
family: str = "both",
timeout: float = 5.0,
expire_after: float = _EXPIRE,
ssl: Union[ssl.SSLContext, bool, None] = None,
) -> List[Union[str, Dict[str, Any], bytes]]:
r"""Send async requests.
Expand All @@ -170,6 +175,8 @@ def retrieve(
Timeout for the request, defaults to 5.0.
expire_after : int, optional
Expiration time for the cache in seconds, defaults to 24 hours.
ssl : bool or SSLContext, optional
SSLContext to use for the connection, defaults to None. Set to False to disable.
Returns
-------
Expand Down Expand Up @@ -209,6 +216,7 @@ def retrieve(
inp.family,
timeout,
expire_after,
ssl,
),
)
for c in chunked_reqs
Expand Down
2 changes: 1 addition & 1 deletion tests/test_async_retriever.py
Expand Up @@ -37,7 +37,7 @@ def test_binary():
)

cache_name = "cache_tmp/aiohttp_cache.sqlite"
r_b = ar.retrieve(urls, "binary", request_kwds=kwds, cache_name=cache_name)
r_b = ar.retrieve(urls, "binary", request_kwds=kwds, cache_name=cache_name, ssl=False)
ar.clean_cache(cache_name)
shutil.rmtree("cache_tmp")
assert sys.getsizeof(r_b[0]) == 986161
Expand Down

0 comments on commit f7132cb

Please sign in to comment.