From 121604bc3052e5be59ed0f08ce7cb56d5b203396 Mon Sep 17 00:00:00 2001 From: Roey Berman Date: Tue, 31 Jul 2012 17:43:12 +0300 Subject: [PATCH] simple_httpclient: ignore 1xx headers --- tornado/simple_httpclient.py | 8 ++++++- tornado/test/simple_httpclient_test.py | 30 ++++++++++++++++++++++---- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/tornado/simple_httpclient.py b/tornado/simple_httpclient.py index c6e8a3a7c..3a81465e5 100644 --- a/tornado/simple_httpclient.py +++ b/tornado/simple_httpclient.py @@ -335,7 +335,13 @@ class _HTTPConnection(object): first_line, _, header_data = data.partition("\n") match = re.match("HTTP/1.[01] ([0-9]+)", first_line) assert match - self.code = int(match.group(1)) + code = int(match.group(1)) + if code != 100: + self.code = code + else: + self.stream.read_until_regex(b("\r?\n\r?\n"), self._on_headers) + return + self.headers = HTTPHeaders.parse(header_data) if "Content-Length" in self.headers: diff --git a/tornado/test/simple_httpclient_test.py b/tornado/test/simple_httpclient_test.py index 237a30f89..5cfffc514 100644 --- a/tornado/test/simple_httpclient_test.py +++ b/tornado/test/simple_httpclient_test.py @@ -12,7 +12,7 @@ from tornado.httputil import HTTPHeaders from tornado.ioloop import IOLoop from tornado.simple_httpclient import SimpleAsyncHTTPClient, _DEFAULT_CA_CERTS from tornado.test.httpclient_test import HTTPClientCommonTestCase, ChunkHandler, CountdownHandler, HelloWorldHandler -from tornado.testing import AsyncHTTPTestCase, AsyncTestCase, LogTrapTestCase +from tornado.testing import AsyncHTTPTestCase, AsyncTestCase, LogTrapTestCase, get_unused_port from tornado.util import b from tornado.web import RequestHandler, Application, asynchronous, url @@ -284,15 +284,17 @@ class SimpleHTTPClientTestCase(AsyncHTTPTestCase, LogTrapTestCase): self.assertTrue(host_re.match(response.body), response.body) -class CreateAsyncHTTPClientTestCase(AsyncTestCase, LogTrapTestCase): +class SaveAsyncHTTPClientConfigurationTestCase(AsyncTestCase, LogTrapTestCase): def setUp(self): - super(CreateAsyncHTTPClientTestCase, self).setUp() + super(SaveAsyncHTTPClientConfigurationTestCase, self).setUp() self.saved = AsyncHTTPClient._save_configuration() def tearDown(self): AsyncHTTPClient._restore_configuration(self.saved) - super(CreateAsyncHTTPClientTestCase, self).tearDown() + super(SaveAsyncHTTPClientConfigurationTestCase, self).tearDown() + +class CreateAsyncHTTPClientTestCase(SaveAsyncHTTPClientConfigurationTestCase): def test_max_clients(self): # The max_clients argument is tricky because it was originally # allowed to be passed positionally; newer arguments are keyword-only. @@ -319,3 +321,23 @@ class CreateAsyncHTTPClientTestCase(AsyncTestCase, LogTrapTestCase): with closing(AsyncHTTPClient( self.io_loop, max_clients=14, force_instance=True)) as client: self.assertEqual(client.max_clients, 14) + + +class HTTP100ContinueTestCase(SaveAsyncHTTPClientConfigurationTestCase): + def respond_100(self, request): + self.request = request + self.request.connection.stream.write("HTTP/1.1 100 CONTINUE\r\n\r\n", self.respond_200) + + def respond_200(self): + self.request.connection.stream.write("HTTP/1.1 200 OK\r\nContent-Length: 1\r\n\r\nA") + + def test_100_continue(self): + from tornado.httpserver import HTTPServer + + port = get_unused_port() + server = HTTPServer(self.respond_100, io_loop = self.io_loop) + server.listen(port) + client = SimpleAsyncHTTPClient(io_loop = self.io_loop) + client.fetch('http://localhost:%d/' % port, self.stop) + res = self.wait() + self.assertEquals(res.body, 'A') -- 2.47.2