From: Ben Darnell Date: Sat, 21 Apr 2018 20:20:30 +0000 (-0400) Subject: test: Reinstate a test that was mistakenly left disabled X-Git-Tag: v5.1.0b1~25^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a843bc9ff159a15aa4b91333272cd61053533ac2;p=thirdparty%2Ftornado.git test: Reinstate a test that was mistakenly left disabled This test required some refactoring to construct invalid headers that we no longer allow handlers to return directly. --- diff --git a/tornado/test/simple_httpclient_test.py b/tornado/test/simple_httpclient_test.py index b7daeda9c..bff9cb50f 100644 --- a/tornado/test/simple_httpclient_test.py +++ b/tornado/test/simple_httpclient_test.py @@ -11,7 +11,7 @@ import socket import ssl import sys -from tornado.escape import to_unicode +from tornado.escape import to_unicode, utf8 from tornado import gen from tornado.httpclient import AsyncHTTPClient from tornado.httputil import HTTPHeaders, ResponseStartLine @@ -57,9 +57,16 @@ class HangHandler(RequestHandler): class ContentLengthHandler(RequestHandler): + @asynchronous def get(self): - self.set_header("Content-Length", self.get_argument("value")) - self.write("ok") + self.stream = self.request.connection.detach() + IOLoop.current().spawn_callback(self.write_response) + + @gen.coroutine + def write_response(self): + yield self.stream.write(utf8("HTTP/1.0 200 OK\r\nContent-Length: %s\r\n\r\nok" % + self.get_argument("value"))) + self.stream.close() class HeadHandler(RequestHandler): @@ -289,16 +296,17 @@ class SimpleHTTPClientTestMixin(object): response = self.fetch(url) self.assertEqual(response.body, b"Hello world!") - def xtest_multiple_content_length_accepted(self): + def test_multiple_content_length_accepted(self): response = self.fetch("/content_length?value=2,2") self.assertEqual(response.body, b"ok") response = self.fetch("/content_length?value=2,%202,2") self.assertEqual(response.body, b"ok") - response = self.fetch("/content_length?value=2,4") - self.assertEqual(response.code, 599) - response = self.fetch("/content_length?value=2,%202,3") - self.assertEqual(response.code, 599) + with ExpectLog(gen_log, ".*Multiple unequal Content-Lengths"): + with self.assertRaises(HTTPStreamClosedError): + self.fetch("/content_length?value=2,4", raise_error=True) + with self.assertRaises(HTTPStreamClosedError): + self.fetch("/content_length?value=2,%202,3", raise_error=True) def test_head_request(self): response = self.fetch("/head", method="HEAD")