Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep sessions around between each ConanRequester #17455

Open
wants to merge 10 commits into
base: develop2
Choose a base branch
from
31 changes: 17 additions & 14 deletions conans/client/rest/conan_requester.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,20 +97,11 @@ def add_auth(self, url, kwargs):


class ConanRequester:
_http_requester_imp = None
AbrilRBS marked this conversation as resolved.
Show resolved Hide resolved

def __init__(self, config, cache_folder=None):
# TODO: Make all this lazy, to avoid fully configuring Requester, for every api call
# even if it doesn't use it
# FIXME: Trick for testing when requests is mocked
if hasattr(requests, "Session"):
self._http_requester = requests.Session()
adapter = HTTPAdapter(max_retries=self._get_retries(config))
self._http_requester.mount("http://", adapter)
self._http_requester.mount("https://", adapter)
else:
self._http_requester = requests

self._url_creds = _SourceURLCredentials(cache_folder)
self._max_retries = config.get("core.net.http:max_retries", default=2, check_type=int)
AbrilRBS marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The _max_retries is now legacy?

self._timeout = config.get("core.net.http:timeout", default=DEFAULT_TIMEOUT)
self._no_proxy_match = config.get("core.net.http:no_proxy_match", check_type=list)
self._proxies = config.get("core.net.http:proxies")
Expand All @@ -123,9 +114,21 @@ def __init__(self, config, cache_folder=None):
platform.machine()])
self._user_agent = "Conan/%s (%s)" % (__version__, platform_info)

@staticmethod
def _get_retries(config):
retry = config.get("core.net.http:max_retries", default=2, check_type=int)
@property
def _http_requester(self):
if ConanRequester._http_requester_imp is None:
# FIXME: Trick for testing when requests is mocked
if hasattr(requests, "Session"):
ConanRequester._http_requester_imp = requests.Session()
adapter = HTTPAdapter(max_retries=self._get_retries())
AbrilRBS marked this conversation as resolved.
Show resolved Hide resolved
ConanRequester._http_requester_imp.mount("http://", adapter)
ConanRequester._http_requester_imp.mount("https://", adapter)
else:
ConanRequester._http_requester_imp = requests
return ConanRequester._http_requester_imp

def _get_retries(self):
retry = self._max_retries
if retry == 0:
return 0
retry_status_code_set = {
Expand Down
Loading