Permalink
Browse files

simple_httpclient: ignore 1xx headers

  • Loading branch information...
1 parent 303e963 commit 121604bc3052e5be59ed0f08ce7cb56d5b203396 @bergundy bergundy committed Jul 31, 2012
Showing with 33 additions and 5 deletions.
  1. +7 −1 tornado/simple_httpclient.py
  2. +26 −4 tornado/test/simple_httpclient_test.py
@@ -335,7 +335,13 @@ def _on_headers(self, data):
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:
@@ -12,7 +12,7 @@
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 @@ def test_host_header(self):
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 @@ def test_max_clients(self):
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')

0 comments on commit 121604b

Please sign in to comment.