Skip to content

Commit 986f415

Browse files
committed
Merge remote-tracking branch 'bergundy/upstream'
2 parents 4daeaeb + 0e1863c commit 986f415

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

tornado/simple_httpclient.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,13 @@ def _on_headers(self, data):
333333
first_line, _, header_data = data.partition("\n")
334334
match = re.match("HTTP/1.[01] ([0-9]+)", first_line)
335335
assert match
336-
self.code = int(match.group(1))
336+
code = int(match.group(1))
337+
if 100 <= code < 200:
338+
self.stream.read_until_regex(b("\r?\n\r?\n"), self._on_headers)
339+
return
340+
else:
341+
self.code = code
342+
337343
self.headers = HTTPHeaders.parse(header_data)
338344

339345
if "Content-Length" in self.headers:

tornado/test/simple_httpclient_test.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from tornado.ioloop import IOLoop
1313
from tornado.simple_httpclient import SimpleAsyncHTTPClient, _DEFAULT_CA_CERTS
1414
from tornado.test.httpclient_test import HTTPClientCommonTestCase, ChunkHandler, CountdownHandler, HelloWorldHandler
15-
from tornado.testing import AsyncHTTPTestCase, AsyncTestCase, LogTrapTestCase
15+
from tornado.testing import AsyncHTTPTestCase, AsyncTestCase, LogTrapTestCase, get_unused_port
1616
from tornado.util import b
1717
from tornado.web import RequestHandler, Application, asynchronous, url
1818

@@ -319,3 +319,23 @@ def test_max_clients(self):
319319
with closing(AsyncHTTPClient(
320320
self.io_loop, max_clients=14, force_instance=True)) as client:
321321
self.assertEqual(client.max_clients, 14)
322+
323+
324+
class HTTP100ContinueTestCase(AsyncTestCase, LogTrapTestCase):
325+
def respond_100(self, request):
326+
self.request = request
327+
self.request.connection.stream.write(b("HTTP/1.1 100 CONTINUE\r\n\r\n"), self.respond_200)
328+
329+
def respond_200(self):
330+
self.request.connection.stream.write(b("HTTP/1.1 200 OK\r\nContent-Length: 1\r\n\r\nA"))
331+
332+
def test_100_continue(self):
333+
from tornado.httpserver import HTTPServer
334+
335+
port = get_unused_port()
336+
server = HTTPServer(self.respond_100, io_loop = self.io_loop)
337+
server.listen(port)
338+
client = SimpleAsyncHTTPClient(io_loop = self.io_loop)
339+
client.fetch('http://localhost:%d/' % port, self.stop)
340+
res = self.wait()
341+
self.assertEqual(res.body, b('A'))

0 commit comments

Comments
 (0)