summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2003-07-12 07:35:35 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2003-07-12 07:35:35 (GMT)
commit8a5ffac3c87cbdb7569715145937e13dea21d9c5 (patch)
tree8b09457cc599b41764beec39c8343748392206b3
parent68976378f7aed6be86a057211c5a7a5e7591aedb (diff)
downloadcpython-8a5ffac3c87cbdb7569715145937e13dea21d9c5.zip
cpython-8a5ffac3c87cbdb7569715145937e13dea21d9c5.tar.gz
cpython-8a5ffac3c87cbdb7569715145937e13dea21d9c5.tar.bz2
Patch #549151, rev4: redirect POST on 301 also.
-rw-r--r--Doc/lib/liburllib.tex12
-rw-r--r--Doc/lib/liburllib2.tex14
-rw-r--r--Lib/urllib2.py10
3 files changed, 22 insertions, 14 deletions
diff --git a/Doc/lib/liburllib.tex b/Doc/lib/liburllib.tex
index a30b03c..5c3b897 100644
--- a/Doc/lib/liburllib.tex
+++ b/Doc/lib/liburllib.tex
@@ -223,12 +223,12 @@ actually retrieve a resource at an \file{https:} URL.
\begin{classdesc}{FancyURLopener}{...}
\class{FancyURLopener} subclasses \class{URLopener} providing default
-handling for the following HTTP response codes: 301, 302, 303 and 401.
-For 301, 302 and 303 response codes, the \mailheader{Location} header
-is used to fetch the actual URL. For 401 response codes
-(authentication required), basic HTTP authentication is performed.
-For 301, 302 and 303 response codes, recursion is bounded by the value
-of the \var{maxtries} attribute, which defaults 10.
+handling for the following HTTP response codes: 301, 302, 303, 307 and
+401. For the 30x response codes listed above, the
+\mailheader{Location} header is used to fetch the actual URL. For 401
+response codes (authentication required), basic HTTP authentication is
+performed. For the 30x response codes, recursion is bounded by the
+value of the \var{maxtries} attribute, which defaults to 10.
\note{According to the letter of \rfc{2616}, 301 and 302 responses to
POST requests must not be automatically redirected without
diff --git a/Doc/lib/liburllib2.tex b/Doc/lib/liburllib2.tex
index 48afc9b..0674888 100644
--- a/Doc/lib/liburllib2.tex
+++ b/Doc/lib/liburllib2.tex
@@ -419,8 +419,11 @@ redirect. Otherwise, raise \exception{HTTPError} if no other
if you can't but another \class{Handler} might.
\note{The default implementation of this method does not strictly
- follow \rfc{2616}: it allows automatic 302 redirection of POST
- requests, because essentially all HTTP clients do this.}
+ follow \rfc{2616}, which says that 301 and 302 responses to POST
+ requests must not be automatically redirected without confirmation by
+ the user. In reality, browsers do allow automatic redirection of
+ these responses, changing the POST to a GET, and the default
+ implementation reproduces this behaviour.}
\end{methoddesc}
@@ -441,9 +444,14 @@ The same as \method{http_error_301()}, but called for the
\begin{methoddesc}[HTTPRedirectHandler]{http_error_303}{req,
fp, code, msg, hdrs}
The same as \method{http_error_301()}, but called for the
-`see other' redirect response.
+`see other' response.
\end{methoddesc}
+\begin{methoddesc}[HTTPRedirectHandler]{http_error_307}{req,
+ fp, code, msg, hdrs}
+The same as \method{http_error_301()}, but called for the
+`temporary redirect' response.
+
\subsection{ProxyHandler Objects \label{proxy-handler}}
\begin{methoddescni}[ProxyHandler]{\var{protocol}_open}{request}
diff --git a/Lib/urllib2.py b/Lib/urllib2.py
index 0ea7b6c..72d799a 100644
--- a/Lib/urllib2.py
+++ b/Lib/urllib2.py
@@ -418,9 +418,9 @@ class HTTPRedirectHandler(BaseHandler):
"""
m = req.get_method()
if (code in (301, 302, 303, 307) and m in ("GET", "HEAD")
- or code in (302, 303) and m == "POST"):
- # Strictly (according to RFC 2616), 302 in response to a
- # POST MUST NOT cause a redirection without confirmation
+ or code in (301, 302, 303) and m == "POST"):
+ # Strictly (according to RFC 2616), 301 or 302 in response
+ # to a POST MUST NOT cause a redirection without confirmation
# from the user (of urllib2, in this case). In practice,
# essentially all clients do redirect in this case, so we
# do the same.
@@ -467,9 +467,9 @@ class HTTPRedirectHandler(BaseHandler):
http_error_301 = http_error_303 = http_error_307 = http_error_302
- inf_msg = "The HTTP server returned a redirect error that would" \
+ inf_msg = "The HTTP server returned a redirect error that would " \
"lead to an infinite loop.\n" \
- "The last 302 error message was:\n"
+ "The last 30x error message was:\n"
class ProxyHandler(BaseHandler):
def __init__(self, proxies=None):