From: Ben Darnell Date: Mon, 24 Sep 2012 03:26:24 +0000 (-0400) Subject: Merge branch 'master' into merge X-Git-Tag: v3.0.0~272 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=54f1bd33755c0958a38fab0929f3da05688d810a;p=thirdparty%2Ftornado.git Merge branch 'master' into merge Conflicts: tornado/simple_httpclient.py tornado/test/web_test.py --- 54f1bd33755c0958a38fab0929f3da05688d810a diff --cc tornado/simple_httpclient.py index ab70b519e,6bd10c17c..ae2988424 --- a/tornado/simple_httpclient.py +++ b/tornado/simple_httpclient.py @@@ -333,10 -334,15 +334,15 @@@ class _HTTPConnection(object) def _on_headers(self, data): data = native_str(data.decode("latin1")) first_line, _, header_data = data.partition("\n") - match = re.match("HTTP/1.[01] ([0-9]+)", first_line) + match = re.match("HTTP/1.[01] ([0-9]+) ([^\r]*)", first_line) assert match - self.code = int(match.group(1)) - self.reason = match.group(2) + code = int(match.group(1)) + if 100 <= code < 200: + self.stream.read_until_regex(b("\r?\n\r?\n"), self._on_headers) + return + else: + self.code = code - ++ self.reason = match.group(2) self.headers = HTTPHeaders.parse(header_data) if "Content-Length" in self.headers: diff --cc tornado/test/web_test.py index acca76654,4ce5b616b..8cb6af2ad --- a/tornado/test/web_test.py +++ b/tornado/test/web_test.py @@@ -1,10 -1,11 +1,12 @@@ from __future__ import absolute_import, division, with_statement from tornado import gen - from tornado.escape import json_decode, utf8, to_unicode, recursive_unicode, native_str + from tornado.escape import json_decode, utf8, to_unicode, recursive_unicode, native_str, to_basestring from tornado.iostream import IOStream + from tornado.log import app_log, gen_log +from tornado.simple_httpclient import SimpleAsyncHTTPClient from tornado.template import DictLoader - from tornado.testing import LogTrapTestCase, AsyncHTTPTestCase + from tornado.testing import AsyncHTTPTestCase, ExpectLog + from tornado.test.util import unittest from tornado.util import b, bytes_type, ObjectDict from tornado.web import RequestHandler, authenticated, Application, asynchronous, url, HTTPError, StaticFileHandler, _create_signature, create_signed_value @@@ -850,28 -890,17 +891,45 @@@ class Header304Test(SimpleHandlerTestCa self.assertTrue("Content-Language" not in response2.headers) # Not an entity header, but should not be added to 304s by chunking self.assertTrue("Transfer-Encoding" not in response2.headers) + wsgi_safe.append(Header304Test) - class StatusReasonTest(SimpleHandlerTestCase, LogTrapTestCase): ++ ++class StatusReasonTest(SimpleHandlerTestCase): + class Handler(RequestHandler): + def get(self): + reason = self.request.arguments.get('reason', []) + self.set_status(int(self.get_argument('code')), + reason=reason[0] if reason else None) + + def get_http_client(self): + # simple_httpclient only: curl doesn't expose the reason string + return SimpleAsyncHTTPClient(io_loop=self.io_loop) + + def test_status(self): + response = self.fetch("/?code=304") + self.assertEqual(response.code, 304) + self.assertEqual(response.reason, "Not Modified") + response = self.fetch("/?code=304&reason=Foo") + self.assertEqual(response.code, 304) + self.assertEqual(response.reason, "Foo") + response = self.fetch("/?code=682&reason=Bar") + self.assertEqual(response.code, 682) + self.assertEqual(response.reason, "Bar") - response = self.fetch("/?code=682") ++ with ExpectLog(app_log, 'Uncaught exception'): ++ response = self.fetch("/?code=682") + self.assertEqual(response.code, 500) ++wsgi_safe.append(StatusReasonTest) ++ ++ + class DateHeaderTest(SimpleHandlerTestCase): + class Handler(RequestHandler): + def get(self): + self.write("hello") + def test_date_header(self): + response = self.fetch('/') + header_date = datetime.datetime.strptime(response.headers['Date'], + "%a, %d %b %Y %H:%M:%S GMT") + self.assertTrue(header_date - datetime.datetime.utcnow() < + datetime.timedelta(seconds=2)) + wsgi_safe.append(DateHeaderTest)