Skip to content

Commit

Permalink
Manage proxies & auth just in case
Browse files Browse the repository at this point in the history
  • Loading branch information
mboudet committed Aug 23, 2024
1 parent 744f196 commit bf7f4f4
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion biomaj_download/download/curl.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,26 @@ def _estimate_size(self, rfile):

def _head_size_call(self, full_url):
# Now do a HEAD call on this url

auth = ()
proxies = {}

if self.credentials is not None:
auth = tuple(self.credentials.split(":"))

if self.proxy is not None:
proxy = self.proxy
if not self.proxy.startswith("http"):
proxy = 'http://' + self.proxy
if self.proxy_auth is not None:
# Don't really want to manage properly the various schemes
proxy.replace('http://', 'http://{}@'.format(self.proxy_auth))
proxy.replace('https://', 'https://{}@'.format(self.proxy_auth))
proxies['http'] = proxy
proxies['https'] = proxy

try:
size_response = requests.head(full_url, allow_redirects=True)
size_response = requests.head(full_url, allow_redirects=True, auth=auth, proxies=proxies)
size = int(size_response.headers.get('content-length', 0))
return size

Expand Down

0 comments on commit bf7f4f4

Please sign in to comment.