Skip to content

Commit

Permalink
Added support for http_proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Nilsson committed Nov 7, 2024
1 parent cbdced9 commit b9825c4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion PILOTVERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.9.2.22
3.9.2.23b
2 changes: 1 addition & 1 deletion pilot/util/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
RELEASE = '3' # released number should be fixed at 3 for Pilot 3
VERSION = '9' # version number is '1' for first release, '0' until then, increased for bigger updates
REVISION = '2' # revision number should be reset to '0' for every new version release, increased for small updates
BUILD = '22' # build number should be reset to '1' for every new development cycle
BUILD = '23' # build number should be reset to '1' for every new development cycle

SUCCESS = 0
FAILURE = 1
Expand Down
25 changes: 21 additions & 4 deletions pilot/util/https.py
Original file line number Diff line number Diff line change
Expand Up @@ -859,8 +859,7 @@ def request2(url: str = "",

if ipv == 'IPv4':
logger.info("will use IPv4 in server communication")
opener = urllib.request.build_opener(IPv4HTTPHandler())
urllib.request.install_opener(opener)
install_ipv4_opener()
else:
logger.info("will use IPv6 in server communication")

Expand All @@ -870,10 +869,10 @@ def request2(url: str = "",
logger.debug('sending data to server')
with urllib.request.urlopen(req, context=ssl_context, timeout=config.Pilot.http_maxtime) as response:
# Handle the response here
logger.debug(f"response.status={response.status}, response.reason={response.reason}")
logger.info(f"response.status={response.status}, response.reason={response.reason}")
ret = response.read().decode('utf-8')
if 'getProxy' not in url:
logger.debug(f"response={ret}")
logger.info(f"response={ret}")
logger.debug('sent request to server')
except (urllib.error.URLError, urllib.error.HTTPError, TimeoutError) as exc:
logger.warning(f'failed to send request: {exc}')
Expand All @@ -897,6 +896,24 @@ def request2(url: str = "",
return ret


def install_ipv4_opener():
"""Install the IPv4 opener."""
http_proxy = os.environ.get("http_proxy")
all_proxy = os.environ.get("all_proxy")
if http_proxy and all_proxy:
logger.info(f"using http_proxy={http_proxy}, all_proxy={all_proxy}")
proxy_handler = urllib.request.ProxyHandler({
'http': http_proxy,
'https': http_proxy,
'all': all_proxy
})
opener = urllib.request.build_opener(proxy_handler, IPv4HTTPHandler())
else:
logger.info("no http_proxy found, will use IPv4 without proxy")
opener = urllib.request.build_opener(IPv4HTTPHandler())
urllib.request.install_opener(opener)


def request2_old(url: str = "",
data: dict = None,
secure: bool = True,
Expand Down

0 comments on commit b9825c4

Please sign in to comment.