Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fa19f7c

Browse files
committed
More fixes according to SF 549151:
- When redirecting, always use GET. This is common practice and more-or-less sanctioned by the HTTP standard. - Add a handler for 307 redirection, which becomes an error for POST, but a regular redirect for GET and HEAD.
1 parent 8f512a2 commit fa19f7c

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

Lib/urllib.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -577,10 +577,7 @@ def redirect_internal(self, url, fp, errcode, errmsg, headers, data):
577577
fp.close()
578578
# In case the server sent a relative URL, join with original:
579579
newurl = basejoin(self.type + ":" + url, newurl)
580-
if data is None:
581-
return self.open(newurl)
582-
else:
583-
return self.open(newurl, data)
580+
return self.open(newurl)
584581

585582
def http_error_301(self, url, fp, errcode, errmsg, headers, data=None):
586583
"""Error 301 -- also relocated (permanently)."""
@@ -590,6 +587,13 @@ def http_error_303(self, url, fp, errcode, errmsg, headers, data=None):
590587
"""Error 303 -- also relocated (essentially identical to 302)."""
591588
return self.http_error_302(url, fp, errcode, errmsg, headers, data)
592589

590+
def http_error_307(self, url, fp, errcode, errmsg, headers, data=None):
591+
"""Error 307 -- relocated, but turn POST into error."""
592+
if data is None:
593+
return self.http_error_302(url, fp, errcode, errmsg, headers, data)
594+
else:
595+
return self.http_error_default(url, fp, errcode, errmsg, headers)
596+
593597
def http_error_401(self, url, fp, errcode, errmsg, headers, data=None):
594598
"""Error 401 -- authentication required.
595599
See this URL for a description of the basic authentication scheme:

Misc/NEWS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ Extension modules
3838
Library
3939
-------
4040

41+
- More fixes to urllib (SF 549151): (a) When redirecting, always use
42+
GET. This is common practice and more-or-less sanctioned by the
43+
HTTP standard. (b) Add a handler for 307 redirection, which becomes
44+
an error for POST, but a regular redirect for GET and HEAD
45+
4146
- Added optional 'onerror' argument to os.walk(), to control error
4247
handling.
4348

0 commit comments

Comments
 (0)