]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
simple_httpclient: ignore 1xx headers
authorRoey Berman <roey.berman@gmail.com>
Tue, 31 Jul 2012 14:43:12 +0000 (17:43 +0300)
committerRoey Berman <roey.berman@gmail.com>
Tue, 31 Jul 2012 15:15:52 +0000 (18:15 +0300)
tornado/simple_httpclient.py
tornado/test/simple_httpclient_test.py

index c6e8a3a7ce0e0594d725cf5a09571651ab69b779..3a81465e58a568b79797fcf2a3d19ffb81c06663 100644 (file)
@@ -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:
index 237a30f894b6fce22b6b94ca1f6efe14017c8bea..5cfffc514156760a6786cfd608e8f80b73635ff2 100644 (file)
@@ -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')