FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[3.10] bpo-40321: Support HTTP response status code 308 in urllib.request (GH-19588) by miss-islington · Pull Request #28750 · python/cpython · GitHub

Repository navigation

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) .rst  (2) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
6 changes: 6 additions & 0 deletions Doc/library/urllib.request.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,12 @@ HTTPRedirectHandler Objects
response.


.. method:: HTTPRedirectHandler.http_error_308(req, fp, code, msg, hdrs)

The same as :meth:`http_error_301`, but called for the 'permanent redirect'
response.


.. _http-cookie-processor:

HTTPCookieProcessor Objects
Expand Down
15 changes: 11 additions & 4 deletions Lib/urllib/request.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
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
Expand Down Expand Up @@ -661,7 +661,7 @@ def redirect_request(self, req, fp, code, msg, headers, newurl):
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)

Expand Down Expand Up @@ -748,7 +748,7 @@ def http_error_302(self, req, fp, code, msg, headers):

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" \
Expand Down Expand Up @@ -2211,6 +2211,13 @@ def http_error_307(self, url, fp, errcode, errmsg, headers, data=None):
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.
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Adds support for HTTP 308 redirects to :mod:`urllib`. Patch by Jochem
Schulenklopper.

Back | FazBrowse Home | New Git URL