Skip to content

Commit

Permalink
Mark some tests as requiring HTTP/1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
bdarnell committed Mar 14, 2015
1 parent 859df38 commit 9189e8a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions tornado/httputil.py
Expand Up @@ -385,6 +385,8 @@ def write(self, chunk, callback=None):
to write the response.
"""
assert isinstance(chunk, bytes)
assert self.version.startswith("HTTP/1."), \
"deprecated interface ony supported in HTTP/1.x"
self.connection.write(chunk, callback=callback)

def finish(self):
Expand Down
4 changes: 3 additions & 1 deletion tornado/test/httpclient_test.py
Expand Up @@ -178,6 +178,8 @@ def test_chunked_close(self):
sock, port = bind_unused_port()
with closing(sock):
def write_response(stream, request_data):
if b"HTTP/1." not in request_data:
self.skipTest("requires HTTP/1.x")
stream.write(b"""\
HTTP/1.1 200 OK
Transfer-Encoding: chunked
Expand Down Expand Up @@ -316,7 +318,7 @@ def streaming_callback(chunk):
self.fetch('/chunk', header_callback=header_callback,
streaming_callback=streaming_callback)
self.assertEqual(len(first_line), 1)
self.assertRegexpMatches(first_line[0], 'HTTP/1.[01] 200 OK\r\n')
self.assertRegexpMatches(first_line[0], 'HTTP/[0-9]\\.[0-9] 200 OK\r\n')
self.assertEqual(chunks, [b'asdf', b'qwer'])

def test_header_callback_stack_context(self):
Expand Down
3 changes: 3 additions & 0 deletions tornado/test/httpserver_test.py
Expand Up @@ -1058,6 +1058,7 @@ def get_app(self):
# delegate interface, and writes its response via request.write
# instead of request.connection.write_headers.
def handle_request(request):
self.http1 = request.version.startswith("HTTP/1.")
message = b"Hello world"
request.write(utf8("HTTP/1.1 200 OK\r\n"
"Content-Length: %d\r\n\r\n" % len(message)))
Expand All @@ -1067,4 +1068,6 @@ def handle_request(request):

def test_legacy_interface(self):
response = self.fetch('/')
if not self.http1:
self.skipTest("requires HTTP/1.x")
self.assertEqual(response.body, b"Hello world")
6 changes: 6 additions & 0 deletions tornado/test/simple_httpclient_test.py
Expand Up @@ -492,6 +492,7 @@ def test_max_clients(self):

class HTTP100ContinueTestCase(AsyncHTTPTestCase):
def respond_100(self, request):
self.http1 = request.version.startswith('HTTP/1.')
self.request = request
self.request.connection.stream.write(
b"HTTP/1.1 100 CONTINUE\r\n\r\n",
Expand All @@ -508,11 +509,14 @@ def get_app(self):

def test_100_continue(self):
res = self.fetch('/')
if not self.http1:
self.skipTest("requires HTTP/1.x")
self.assertEqual(res.body, b'A')


class HTTP204NoContentTestCase(AsyncHTTPTestCase):
def respond_204(self, request):
self.http1 = request.version.startswith('HTTP/1.')
# A 204 response never has a body, even if doesn't have a content-length
# (which would otherwise mean read-until-close). Tornado always
# sends a content-length, so we simulate here a server that sends
Expand All @@ -528,6 +532,8 @@ def get_app(self):

def test_204_no_content(self):
resp = self.fetch('/')
if not self.http1:
self.skipTest("requires HTTP/1.x")
self.assertEqual(resp.code, 204)
self.assertEqual(resp.body, b'')

Expand Down

0 comments on commit 9189e8a

Please sign in to comment.