Merge remote-tracking branch 'amorton/master'
Conflicts: tornado/test/simple_httpclient_test.py
This commit is contained in:
commit
24d96f0286
|
@ -380,12 +380,23 @@ class _HTTPConnection(object):
|
||||||
self.request)
|
self.request)
|
||||||
if (self.request.follow_redirects and
|
if (self.request.follow_redirects and
|
||||||
self.request.max_redirects > 0 and
|
self.request.max_redirects > 0 and
|
||||||
self.code in (301, 302)):
|
self.code in (301, 302, 303)):
|
||||||
new_request = copy.copy(self.request)
|
new_request = copy.copy(self.request)
|
||||||
new_request.url = urlparse.urljoin(self.request.url,
|
new_request.url = urlparse.urljoin(self.request.url,
|
||||||
self.headers["Location"])
|
self.headers["Location"])
|
||||||
new_request.max_redirects -= 1
|
new_request.max_redirects -= 1
|
||||||
del new_request.headers["Host"]
|
del new_request.headers["Host"]
|
||||||
|
# http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.4
|
||||||
|
# client SHOULD make a GET request
|
||||||
|
if self.code == 303:
|
||||||
|
new_request.method = "GET"
|
||||||
|
new_request.body = None
|
||||||
|
for h in ["Content-Length", "Content-Type",
|
||||||
|
"Content-Encoding", "Transfer-Encoding"]:
|
||||||
|
try:
|
||||||
|
del self.request.headers[h]
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
new_request.original_request = original_request
|
new_request.original_request = original_request
|
||||||
final_callback = self.final_callback
|
final_callback = self.final_callback
|
||||||
self.final_callback = None
|
self.final_callback = None
|
||||||
|
|
|
@ -54,6 +54,16 @@ class NoContentHandler(RequestHandler):
|
||||||
self.set_header("Content-Length", "7")
|
self.set_header("Content-Length", "7")
|
||||||
self.set_status(204)
|
self.set_status(204)
|
||||||
|
|
||||||
|
class SeeOther303PostHandler(RequestHandler):
|
||||||
|
def post(self):
|
||||||
|
self.set_header("Location", "/303_get")
|
||||||
|
self.set_status(303)
|
||||||
|
|
||||||
|
class SeeOther303GetHandler(RequestHandler):
|
||||||
|
def get(self):
|
||||||
|
self.write("ok")
|
||||||
|
|
||||||
|
|
||||||
class SimpleHTTPClientTestCase(AsyncHTTPTestCase, LogTrapTestCase):
|
class SimpleHTTPClientTestCase(AsyncHTTPTestCase, LogTrapTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(SimpleHTTPClientTestCase, self).setUp()
|
super(SimpleHTTPClientTestCase, self).setUp()
|
||||||
|
@ -72,6 +82,8 @@ class SimpleHTTPClientTestCase(AsyncHTTPTestCase, LogTrapTestCase):
|
||||||
url("/content_length", ContentLengthHandler),
|
url("/content_length", ContentLengthHandler),
|
||||||
url("/head", HeadHandler),
|
url("/head", HeadHandler),
|
||||||
url("/no_content", NoContentHandler),
|
url("/no_content", NoContentHandler),
|
||||||
|
url("/303_post", SeeOther303PostHandler),
|
||||||
|
url("/303_get", SeeOther303GetHandler),
|
||||||
], gzip=True)
|
], gzip=True)
|
||||||
|
|
||||||
def test_singleton(self):
|
def test_singleton(self):
|
||||||
|
@ -150,6 +162,14 @@ class SimpleHTTPClientTestCase(AsyncHTTPTestCase, LogTrapTestCase):
|
||||||
self.assertTrue(response.effective_url.endswith("/countdown/2"))
|
self.assertTrue(response.effective_url.endswith("/countdown/2"))
|
||||||
self.assertTrue(response.headers["Location"].endswith("/countdown/1"))
|
self.assertTrue(response.headers["Location"].endswith("/countdown/1"))
|
||||||
|
|
||||||
|
def test_303_redirect(self):
|
||||||
|
response = self.fetch("/303_post", method="POST", body="")
|
||||||
|
self.assertEqual(200, response.code)
|
||||||
|
self.assertTrue(response.request.url.endswith("/303_post"))
|
||||||
|
self.assertTrue(response.effective_url.endswith("/303_get"))
|
||||||
|
#request is the original request, is a POST still
|
||||||
|
self.assertEqual("POST", response.request.method)
|
||||||
|
|
||||||
def test_request_timeout(self):
|
def test_request_timeout(self):
|
||||||
response = self.fetch('/hang', request_timeout=0.1)
|
response = self.fetch('/hang', request_timeout=0.1)
|
||||||
self.assertEqual(response.code, 599)
|
self.assertEqual(response.code, 599)
|
||||||
|
|
Loading…
Reference in New Issue