diff options
author | Jochem Schulenklopper <j.schulenklopper@gmail.com> | 2021-10-06 02:02:58 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-06 02:02:58 (GMT) |
commit | c379bc5ec9012cf66424ef3d80612cf13ec51006 (patch) | |
tree | ad2aac1c9b349e089e3d49a191a4a57b05dec2c0 /Lib/urllib | |
parent | 241bda785a092a272d7e0f6a4e20bd250c389cfe (diff) | |
download | cpython-c379bc5ec9012cf66424ef3d80612cf13ec51006.zip cpython-c379bc5ec9012cf66424ef3d80612cf13ec51006.tar.gz cpython-c379bc5ec9012cf66424ef3d80612cf13ec51006.tar.bz2 |
bpo-40321: Support HTTP response status code 308 in urllib.request (#19588)
* Support HTTP response status code 308 in urllib.
HTTP response status code 308 is defined in https://tools.ietf.org/html/rfc7538 to be the permanent redirect variant of 307 (temporary redirect).
* Update documentation to include http_error_308()
* Add blurb for bpo-40321 fix
Co-authored-by: Roland Crosby <roland@rolandcrosby.com>
Diffstat (limited to 'Lib/urllib')
-rw-r--r-- | Lib/urllib/request.py | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py index eca6cc3..3ba6d92 100644 --- a/Lib/urllib/request.py +++ b/Lib/urllib/request.py @@ -11,8 +11,8 @@ option. The OpenerDirector is a composite object that invokes the Handlers needed to open the requested URL. For example, the HTTPHandler performs HTTP GET and POST requests and deals with non-error returns. The HTTPRedirectHandler automatically deals with -HTTP 301, 302, 303 and 307 redirect errors, and the HTTPDigestAuthHandler -deals with digest authentication. +HTTP 301, 302, 303, 307 and 308 redirect errors, and the +HTTPDigestAuthHandler deals with digest authentication. urlopen(url, data=None) -- Basic usage is the same as original urllib. pass the url and optionally data to post to an HTTP URL, and @@ -661,7 +661,7 @@ class HTTPRedirectHandler(BaseHandler): but another Handler might. """ m = req.get_method() - if (not (code in (301, 302, 303, 307) and m in ("GET", "HEAD") + if (not (code in (301, 302, 303, 307, 308) and m in ("GET", "HEAD") or code in (301, 302, 303) and m == "POST")): raise HTTPError(req.full_url, code, msg, headers, fp) @@ -748,7 +748,7 @@ class HTTPRedirectHandler(BaseHandler): return self.parent.open(new, timeout=req.timeout) - http_error_301 = http_error_303 = http_error_307 = http_error_302 + http_error_301 = http_error_303 = http_error_307 = http_error_308 = http_error_302 inf_msg = "The HTTP server returned a redirect error that would " \ "lead to an infinite loop.\n" \ @@ -2211,6 +2211,13 @@ class FancyURLopener(URLopener): else: return self.http_error_default(url, fp, errcode, errmsg, headers) + def http_error_308(self, url, fp, errcode, errmsg, headers, data=None): + """Error 308 -- relocated, but turn POST into error.""" + if data is None: + return self.http_error_301(url, fp, errcode, errmsg, headers, data) + else: + return self.http_error_default(url, fp, errcode, errmsg, headers) + def http_error_401(self, url, fp, errcode, errmsg, headers, data=None, retry=False): """Error 401 -- authentication required. |