diff options
author | Guido van Rossum <guido@python.org> | 2003-05-16 01:46:51 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2003-05-16 01:46:51 (GMT) |
commit | fa19f7c20d14d34dfa58bfb9b4055555e46fd437 (patch) | |
tree | 934e7102bb160321b36d0356382d52ef52ba2688 /Lib/urllib.py | |
parent | 8f512a22cd9fe90c2bf52537f703818cc0d7f1b8 (diff) | |
download | cpython-fa19f7c20d14d34dfa58bfb9b4055555e46fd437.zip cpython-fa19f7c20d14d34dfa58bfb9b4055555e46fd437.tar.gz cpython-fa19f7c20d14d34dfa58bfb9b4055555e46fd437.tar.bz2 |
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.
Diffstat (limited to 'Lib/urllib.py')
-rw-r--r-- | Lib/urllib.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/Lib/urllib.py b/Lib/urllib.py index 42851ee..494f578 100644 --- a/Lib/urllib.py +++ b/Lib/urllib.py @@ -577,10 +577,7 @@ class FancyURLopener(URLopener): fp.close() # In case the server sent a relative URL, join with original: newurl = basejoin(self.type + ":" + url, newurl) - if data is None: - return self.open(newurl) - else: - return self.open(newurl, data) + return self.open(newurl) def http_error_301(self, url, fp, errcode, errmsg, headers, data=None): """Error 301 -- also relocated (permanently).""" @@ -590,6 +587,13 @@ class FancyURLopener(URLopener): """Error 303 -- also relocated (essentially identical to 302).""" return self.http_error_302(url, fp, errcode, errmsg, headers, data) + def http_error_307(self, url, fp, errcode, errmsg, headers, data=None): + """Error 307 -- relocated, but turn POST into error.""" + if data is None: + return self.http_error_302(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): """Error 401 -- authentication required. See this URL for a description of the basic authentication scheme: |