Skip to content

Commit 8b66863

Browse files
committed
Add 307 too and update release notes.
1 parent 24d96f0 commit 8b66863

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

tornado/simple_httpclient.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class SimpleAsyncHTTPClient(AsyncHTTPClient):
5353
5454
Some features found in the curl-based AsyncHTTPClient are not yet
5555
supported. In particular, proxies are not supported, connections
56-
are not reused, and callers cannot select the network interface to be
56+
are not reused, and callers cannot select the network interface to be
5757
used.
5858
5959
Python 2.6 or higher is required for HTTPS support. Users of Python 2.5
@@ -310,7 +310,7 @@ def cleanup(self):
310310
yield
311311
except Exception, e:
312312
logging.warning("uncaught exception", exc_info=True)
313-
self._run_callback(HTTPResponse(self.request, 599, error=e,
313+
self._run_callback(HTTPResponse(self.request, 599, error=e,
314314
request_time=time.time() - self.start_time,
315315
))
316316

@@ -335,7 +335,7 @@ def _on_headers(self, data):
335335
# use them but if they differ it's an error.
336336
pieces = re.split(r',\s*', self.headers["Content-Length"])
337337
if any(i != pieces[0] for i in pieces):
338-
raise ValueError("Multiple unequal Content-Lengths: %r" %
338+
raise ValueError("Multiple unequal Content-Lengths: %r" %
339339
self.headers["Content-Length"])
340340
self.headers["Content-Length"] = pieces[0]
341341
content_length = int(self.headers["Content-Length"])
@@ -380,7 +380,7 @@ def _on_body(self, data):
380380
self.request)
381381
if (self.request.follow_redirects and
382382
self.request.max_redirects > 0 and
383-
self.code in (301, 302, 303)):
383+
self.code in (301, 302, 303, 307)):
384384
new_request = copy.copy(self.request)
385385
new_request.url = urlparse.urljoin(self.request.url,
386386
self.headers["Location"])
@@ -391,8 +391,8 @@ def _on_body(self, data):
391391
if self.code == 303:
392392
new_request.method = "GET"
393393
new_request.body = None
394-
for h in ["Content-Length", "Content-Type",
395-
"Content-Encoding", "Transfer-Encoding"]:
394+
for h in ["Content-Length", "Content-Type",
395+
"Content-Encoding", "Transfer-Encoding"]:
396396
try:
397397
del self.request.headers[h]
398398
except KeyError:

tornado/test/simple_httpclient_test.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,16 @@ def get(self):
5656

5757
class SeeOther303PostHandler(RequestHandler):
5858
def post(self):
59+
assert self.request.body == b("blah")
5960
self.set_header("Location", "/303_get")
6061
self.set_status(303)
6162

62-
class SeeOther303GetHandler(RequestHandler):
63+
class SeeOther303GetHandler(RequestHandler):
6364
def get(self):
65+
assert not self.request.body
6466
self.write("ok")
65-
66-
67+
68+
6769
class SimpleHTTPClientTestCase(AsyncHTTPTestCase, LogTrapTestCase):
6870
def setUp(self):
6971
super(SimpleHTTPClientTestCase, self).setUp()
@@ -163,13 +165,13 @@ def test_max_redirects(self):
163165
self.assertTrue(response.headers["Location"].endswith("/countdown/1"))
164166

165167
def test_303_redirect(self):
166-
response = self.fetch("/303_post", method="POST", body="")
168+
response = self.fetch("/303_post", method="POST", body="blah")
167169
self.assertEqual(200, response.code)
168170
self.assertTrue(response.request.url.endswith("/303_post"))
169171
self.assertTrue(response.effective_url.endswith("/303_get"))
170172
#request is the original request, is a POST still
171173
self.assertEqual("POST", response.request.method)
172-
174+
173175
def test_request_timeout(self):
174176
response = self.fetch('/hang', request_timeout=0.1)
175177
self.assertEqual(response.code, 599)

website/sphinx/releases/next.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ Other modules
7474

7575
* `SimpleAsyncHTTPClient` no longer hangs on ``HEAD`` requests,
7676
responses with no content, or empty ``POST``/``PUT`` response bodies.
77+
* `SimpleAsyncHTTPClient` now supports 303 and 307 redirect codes.
7778
* `tornado.platform.twisted` compatibility has been significantly improved.
7879
Twisted version 11.1.0 is now supported in addition to 11.0.0.
7980
* `tornado.testing.main` supports a new flag ``--exception_on_interrupt``,

0 commit comments

Comments
 (0)