Skip to content

Commit f528045

Browse files
authored
bpo-40321: Add missing test, slightly expand documentation (GH-28760)
1 parent 61892c0 commit f528045

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

Doc/library/urllib.request.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -876,13 +876,17 @@ HTTPRedirectHandler Objects
876876
.. method:: HTTPRedirectHandler.http_error_307(req, fp, code, msg, hdrs)
877877

878878
The same as :meth:`http_error_301`, but called for the 'temporary redirect'
879-
response.
879+
response. It does not allow changing the request method from ``POST``
880+
to ``GET``.
880881

881882

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

884885
The same as :meth:`http_error_301`, but called for the 'permanent redirect'
885-
response.
886+
response. It does not allow changing the request method from ``POST``
887+
to ``GET``.
888+
889+
.. versionadded:: 3.11
886890

887891

888892
.. _http-cookie-processor:

Lib/test/test_urllib2.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,7 +1163,7 @@ def test_redirect(self):
11631163
o = h.parent = MockOpener()
11641164

11651165
# ordinary redirect behaviour
1166-
for code in 301, 302, 303, 307:
1166+
for code in 301, 302, 303, 307, 308:
11671167
for data in None, "blah\nblah\n":
11681168
method = getattr(h, "http_error_%s" % code)
11691169
req = Request(from_url, data)
@@ -1176,8 +1176,8 @@ def test_redirect(self):
11761176
method(req, MockFile(), code, "Blah",
11771177
MockHeaders({"location": to_url}))
11781178
except urllib.error.HTTPError:
1179-
# 307 in response to POST requires user OK
1180-
self.assertEqual(code, 307)
1179+
# 307 and 308 in response to POST require user OK
1180+
self.assertIn(code, (307, 308))
11811181
self.assertIsNotNone(data)
11821182
self.assertEqual(o.req.get_full_url(), to_url)
11831183
try:

Lib/urllib/request.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
Handlers needed to open the requested URL. For example, the
1212
HTTPHandler performs HTTP GET and POST requests and deals with
1313
non-error returns. The HTTPRedirectHandler automatically deals with
14-
HTTP 301, 302, 303, 307 and 308 redirect errors, and the
14+
HTTP 301, 302, 303, 307, and 308 redirect errors, and the
1515
HTTPDigestAuthHandler deals with digest authentication.
1616
1717
urlopen(url, data=None) -- Basic usage is the same as original
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Adds support for HTTP 308 redirects to :mod:`urllib`. Patch by Jochem
2-
Schulenklopper.
1+
Adds support for HTTP 308 redirects to :mod:`urllib`. See :rfc:`7538` for
2+
details. Patch by Jochem Schulenklopper.

0 commit comments

Comments
 (0)