zerodeckvc / httplib2

Automatically exported from code.google.com/p/httplib2
0 stars 0 forks source link

303 See Other after a POST doesn't clear the message body #47

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. POST to a URL that will return a 303 redirect.

>>> (r, c) = httplib2.Http().request("...someurl...", method="POST", 
body="arg1=foo")
>>> r['status']
'400'
>>> r.previous['status']
'303'
>>> r.previous['location']
'http://localhost/'

2. When the 303 comes back, a new request, with method="GET" is generated.
3. The new GET request goes to the server, which dies with: 400 Bad Request

Because: GET requests cannot have content-length > 0.

The fix (in version 2.0.4.0-py2.5), is at httplib2/__init__.py:898

redirect_method = ((response.status == 303) and (method not in ["GET", 
"HEAD"])) and "GET" or method

should be:

if response.status == 303 and method not in ("GET","HEAD"):
  redirect_method = "GET"
  body = None
else:
  redirect_method = method

An edited __init__.py is attached.

Original issue reported on code.google.com by jesse.dailey@gmail.com on 7 Jan 2009 at 7:23

Attachments:

GoogleCodeExporter commented 9 years ago
just checked svn and this bug is still there, line 907 of __init__.py

Original comment by jesse.dailey@gmail.com on 7 Jan 2009 at 7:35

GoogleCodeExporter commented 9 years ago

Original comment by joe.gregorio@gmail.com on 13 Jun 2011 at 5:50