diff options
-rw-r--r-- | bitbake/lib/bb/fetch2/wget.py | 42 |
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 |