summaryrefslogtreecommitdiffstats
path: root/bitbake/lib
diff options
context:
space:
mode:
authorRoss Burton <ross.burton@arm.com>2024-12-03 20:05:06 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2024-12-20 16:25:28 +0000
commite8ab6bc411dc44cae69beebdbdf9ce4af9e47be0 (patch)
treeecadc65bf75f4e9012070f5a65da74f3408cbc32 /bitbake/lib
parent59c725f411fd6b123a91c02fb5bcda164022831a (diff)
downloadpoky-e8ab6bc411dc44cae69beebdbdf9ce4af9e47be0.tar.gz
bitbake: fetch2/wget: handle HTTP 308 Permanent Redirect
urllib2.HTTPRedirectHandler.redirect_request doesn't handle HTTP reponse code 308 (Permanent Redirect). This was fixed in c379bc5 but can't be worked around without copying the entire redirect_request() method. When we can depend on Python 3.13, FixedHTTPRedirectHandler can be removed. (Bitbake rev: 365829a2803b954ee6cb0364749551a91d806075) Signed-off-by: Ross Burton <ross.burton@arm.com> Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib')
-rw-r--r--bitbake/lib/bb/fetch2/wget.py42
1 files changed, 37 insertions, 5 deletions
diff --git a/bitbake/lib/bb/fetch2/wget.py b/bitbake/lib/bb/fetch2/wget.py
index 773d41ca81..fcb71246d9 100644
--- a/bitbake/lib/bb/fetch2/wget.py
+++ b/bitbake/lib/bb/fetch2/wget.py
@@ -305,13 +305,45 @@ class Wget(FetchMethod):
305 305
306 class FixedHTTPRedirectHandler(urllib.request.HTTPRedirectHandler): 306 class FixedHTTPRedirectHandler(urllib.request.HTTPRedirectHandler):
307 """ 307 """
308 urllib2.HTTPRedirectHandler resets the method to GET on redirect, 308 urllib2.HTTPRedirectHandler before 3.13 has two flaws:
309 when we want to follow redirects using the original method. 309
310 It resets the method to GET on redirect when we want to follow
311 redirects using the original method (typically HEAD). This was fixed
312 in 759e8e7.
313
314 It also doesn't handle 308 (Permanent Redirect). This was fixed in
315 c379bc5.
316
317 Until we depend on Python 3.13 onwards, copy the redirect_request
318 method to fix these issues.
310 """ 319 """
311 def redirect_request(self, req, fp, code, msg, headers, newurl): 320 def redirect_request(self, req, fp, code, msg, headers, newurl):
312 newreq = urllib.request.HTTPRedirectHandler.redirect_request(self, req, fp, code, msg, headers, newurl) 321 m = req.get_method()
313 newreq.get_method = req.get_method 322 if (not (code in (301, 302, 303, 307, 308) and m in ("GET", "HEAD")
314 return newreq 323 or code in (301, 302, 303) and m == "POST")):
324 raise urllib.HTTPError(req.full_url, code, msg, headers, fp)
325
326 # Strictly (according to RFC 2616), 301 or 302 in response to
327 # a POST MUST NOT cause a redirection without confirmation
328 # from the user (of urllib.request, in this case). In practice,
329 # essentially all clients do redirect in this case, so we do
330 # the same.
331
332 # Be conciliant with URIs containing a space. This is mainly
333 # redundant with the more complete encoding done in http_error_302(),
334 # but it is kept for compatibility with other callers.
335 newurl = newurl.replace(' ', '%20')
336
337 CONTENT_HEADERS = ("content-length", "content-type")
338 newheaders = {k: v for k, v in req.headers.items()
339 if k.lower() not in CONTENT_HEADERS}
340 return urllib.request.Request(newurl,
341 method="HEAD" if m == "HEAD" else "GET",
342 headers=newheaders,
343 origin_req_host=req.origin_req_host,
344 unverifiable=True)
345
346 http_error_308 = urllib.request.HTTPRedirectHandler.http_error_302
315 347
316 # We need to update the environment here as both the proxy and HTTPS 348 # We need to update the environment here as both the proxy and HTTPS
317 # handlers need variables set. The proxy needs http_proxy and friends to 349 # handlers need variables set. The proxy needs http_proxy and friends to