Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
e61a7da2
Commit
e61a7da2
authored
Jul 12, 2003
by
Martin v. Löwis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Patch 549151, rev4: redirect posts for 301 also. Will backport to 2.2.
parent
fb23cafe
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
14 deletions
+22
-14
Doc/lib/liburllib.tex
Doc/lib/liburllib.tex
+6
-6
Doc/lib/liburllib2.tex
Doc/lib/liburllib2.tex
+11
-3
Lib/urllib2.py
Lib/urllib2.py
+5
-5
No files found.
Doc/lib/liburllib.tex
View file @
e61a7da2
...
@@ -257,12 +257,12 @@ actually retrieve a resource at an \file{https:} URL.
...
@@ -257,12 +257,12 @@ actually retrieve a resource at an \file{https:} URL.
\begin{classdesc}
{
FancyURLopener
}{
...
}
\begin{classdesc}
{
FancyURLopener
}{
...
}
\class
{
FancyURLopener
}
subclasses
\class
{
URLopener
}
providing default
\class
{
FancyURLopener
}
subclasses
\class
{
URLopener
}
providing default
handling for the following HTTP response codes: 301, 302, 303
and 401.
handling for the following HTTP response codes: 301, 302, 303
, 307 and
For 301, 302 and 303 response codes, the
\mailheader
{
Location
}
header
401. For the 30x response codes listed above, the
is used to fetch the actual URL. For 401 response codes
\mailheader
{
Location
}
header is used to fetch the actual URL. For 401
(authentication required), basic HTTP authentication is performed.
response codes (authentication required), basic HTTP authentication is
For 301, 302 and 303 response codes, recursion is bounded by the valu
e
performed. For the 30x response codes, recursion is bounded by th
e
of the
\var
{
maxtries
}
attribute, which defaults
10.
value of the
\var
{
maxtries
}
attribute, which defaults to
10.
\note
{
According to the letter of
\rfc
{
2616
}
, 301 and 302 responses to
\note
{
According to the letter of
\rfc
{
2616
}
, 301 and 302 responses to
POST requests must not be automatically redirected without
POST requests must not be automatically redirected without
...
...
Doc/lib/liburllib2.tex
View file @
e61a7da2
...
@@ -424,8 +424,11 @@ redirect. Otherwise, raise \exception{HTTPError} if no other
...
@@ -424,8 +424,11 @@ redirect. Otherwise, raise \exception{HTTPError} if no other
if you can't but another
\class
{
Handler
}
might.
if you can't but another
\class
{
Handler
}
might.
\note
{
The default implementation of this method does not strictly
\note
{
The default implementation of this method does not strictly
follow
\rfc
{
2616
}
: it allows automatic 302 redirection of POST
follow
\rfc
{
2616
}
, which says that 301 and 302 responses to POST
requests, because essentially all HTTP clients do this.
}
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}
\end{methoddesc}
...
@@ -446,9 +449,14 @@ The same as \method{http_error_301()}, but called for the
...
@@ -446,9 +449,14 @@ The same as \method{http_error_301()}, but called for the
\begin{methoddesc}
[HTTPRedirectHandler]
{
http
_
error
_
303
}{
req,
\begin{methoddesc}
[HTTPRedirectHandler]
{
http
_
error
_
303
}{
req,
fp, code, msg, hdrs
}
fp, code, msg, hdrs
}
The same as
\method
{
http
_
error
_
301()
}
, but called for the
The same as
\method
{
http
_
error
_
301()
}
, but called for the
`see other' re
direct re
sponse.
`see other' response.
\end{methoddesc}
\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
}}
\subsection
{
ProxyHandler Objects
\label
{
proxy-handler
}}
\begin{methoddescni}
[ProxyHandler]
{
\var
{
protocol
}_
open
}{
request
}
\begin{methoddescni}
[ProxyHandler]
{
\var
{
protocol
}_
open
}{
request
}
...
...
Lib/urllib2.py
View file @
e61a7da2
...
@@ -431,9 +431,9 @@ class HTTPRedirectHandler(BaseHandler):
...
@@ -431,9 +431,9 @@ class HTTPRedirectHandler(BaseHandler):
"""
"""
m
=
req
.
get_method
()
m
=
req
.
get_method
()
if
(
code
in
(
301
,
302
,
303
,
307
)
and
m
in
(
"GET"
,
"HEAD"
)
if
(
code
in
(
301
,
302
,
303
,
307
)
and
m
in
(
"GET"
,
"HEAD"
)
or
code
in
(
302
,
303
)
and
m
==
"POST"
):
or
code
in
(
30
1
,
30
2
,
303
)
and
m
==
"POST"
):
# Strictly (according to RFC 2616), 30
2 in response to a
# Strictly (according to RFC 2616), 30
1 or 302 in response
# POST MUST NOT cause a redirection without confirmation
#
to a
POST MUST NOT cause a redirection without confirmation
# from the user (of urllib2, in this case). In practice,
# from the user (of urllib2, in this case). In practice,
# essentially all clients do redirect in this case, so we
# essentially all clients do redirect in this case, so we
# do the same.
# do the same.
...
@@ -480,9 +480,9 @@ class HTTPRedirectHandler(BaseHandler):
...
@@ -480,9 +480,9 @@ class HTTPRedirectHandler(BaseHandler):
http_error_301
=
http_error_303
=
http_error_307
=
http_error_302
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
"
\
"lead to an infinite loop.
\
n
"
\
"The last 30
2
error message was:
\
n
"
"The last 30
x
error message was:
\
n
"
class
ProxyHandler
(
BaseHandler
):
class
ProxyHandler
(
BaseHandler
):
# Proxies must be in front
# Proxies must be in front
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment