summaryrefslogtreecommitdiffstats
path: root/bitbake/lib
diff options
context:
space:
mode:
authorEnrico Scholz <enrico.scholz@sigma-chemnitz.de>2021-08-18 19:16:22 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2021-08-23 08:30:54 +0100
commite8182a794da04212e8815c1cb6d01f4f7744424f (patch)
tree3745f556537c8c6f77cdf5b0d29503075acc54e6 /bitbake/lib
parentf113446f417711e652a01907ba14fc513861131e (diff)
downloadpoky-e8182a794da04212e8815c1cb6d01f4f7744424f.tar.gz
bitbake: fetch2/wget: fix 'no_proxy' handling
The urllib.request.ProxyHandler constructor only reads the $http_proxy + $https_proxy environment variables. $no_proxy is evaluated later when the url is opened. It is therefore not sufficient to just construct the proxy handler in the | with bb.utils.environment(**newenv): context, but the 'opener.open(r)' call must also be made there. (Bitbake rev: 076baf4fbd328d247508fd399866a397eb34f67e) Signed-off-by: Enrico Scholz <enrico.scholz@sigma-chemnitz.de> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib')
-rw-r--r--bitbake/lib/bb/fetch2/wget.py87
1 files changed, 44 insertions, 43 deletions
diff --git a/bitbake/lib/bb/fetch2/wget.py b/bitbake/lib/bb/fetch2/wget.py
index 29fcfbb3d1..9a49e64a00 100644
--- a/bitbake/lib/bb/fetch2/wget.py
+++ b/bitbake/lib/bb/fetch2/wget.py
@@ -330,50 +330,51 @@ class Wget(FetchMethod):
330 urllib.request.HTTPSHandler(context=context)] 330 urllib.request.HTTPSHandler(context=context)]
331 opener = urllib.request.build_opener(*handlers) 331 opener = urllib.request.build_opener(*handlers)
332 332
333 try:
334 uri = ud.url.split(";")[0]
335 r = urllib.request.Request(uri)
336 r.get_method = lambda: "HEAD"
337 # Some servers (FusionForge, as used on Alioth) require that the
338 # optional Accept header is set.
339 r.add_header("Accept", "*/*")
340 r.add_header("User-Agent", self.user_agent)
341 def add_basic_auth(login_str, request):
342 '''Adds Basic auth to http request, pass in login:password as string'''
343 import base64
344 encodeuser = base64.b64encode(login_str.encode('utf-8')).decode("utf-8")
345 authheader = "Basic %s" % encodeuser
346 r.add_header("Authorization", authheader)
347
348 if ud.user and ud.pswd:
349 add_basic_auth(ud.user + ':' + ud.pswd, r)
350
351 try: 333 try:
352 import netrc 334 uri = ud.url.split(";")[0]
353 n = netrc.netrc() 335 r = urllib.request.Request(uri)
354 login, unused, password = n.authenticators(urllib.parse.urlparse(uri).hostname) 336 r.get_method = lambda: "HEAD"
355 add_basic_auth("%s:%s" % (login, password), r) 337 # Some servers (FusionForge, as used on Alioth) require that the
356 except (TypeError, ImportError, IOError, netrc.NetrcParseError): 338 # optional Accept header is set.
357 pass 339 r.add_header("Accept", "*/*")
358 340 r.add_header("User-Agent", self.user_agent)
359 with opener.open(r) as response: 341 def add_basic_auth(login_str, request):
360 pass 342 '''Adds Basic auth to http request, pass in login:password as string'''
361 except urllib.error.URLError as e: 343 import base64
362 if try_again: 344 encodeuser = base64.b64encode(login_str.encode('utf-8')).decode("utf-8")
363 logger.debug2("checkstatus: trying again") 345 authheader = "Basic %s" % encodeuser
364 return self.checkstatus(fetch, ud, d, False) 346 r.add_header("Authorization", authheader)
365 else: 347
366 # debug for now to avoid spamming the logs in e.g. remote sstate searches 348 if ud.user and ud.pswd:
367 logger.debug2("checkstatus() urlopen failed: %s" % e) 349 add_basic_auth(ud.user + ':' + ud.pswd, r)
368 return False 350
369 except ConnectionResetError as e: 351 try:
370 if try_again: 352 import netrc
371 logger.debug2("checkstatus: trying again") 353 n = netrc.netrc()
372 return self.checkstatus(fetch, ud, d, False) 354 login, unused, password = n.authenticators(urllib.parse.urlparse(uri).hostname)
373 else: 355 add_basic_auth("%s:%s" % (login, password), r)
374 # debug for now to avoid spamming the logs in e.g. remote sstate searches 356 except (TypeError, ImportError, IOError, netrc.NetrcParseError):
375 logger.debug2("checkstatus() urlopen failed: %s" % e) 357 pass
376 return False 358
359 with opener.open(r) as response:
360 pass
361 except urllib.error.URLError as e:
362 if try_again:
363 logger.debug2("checkstatus: trying again")
364 return self.checkstatus(fetch, ud, d, False)
365 else:
366 # debug for now to avoid spamming the logs in e.g. remote sstate searches
367 logger.debug2("checkstatus() urlopen failed: %s" % e)
368 return False
369 except ConnectionResetError as e:
370 if try_again:
371 logger.debug2("checkstatus: trying again")
372 return self.checkstatus(fetch, ud, d, False)
373 else:
374 # debug for now to avoid spamming the logs in e.g. remote sstate searches
375 logger.debug2("checkstatus() urlopen failed: %s" % e)
376 return False
377
377 return True 378 return True
378 379
379 def _parse_path(self, regex, s): 380 def _parse_path(self, regex, s):