"""
def initialize(self, io_loop, max_clients=10,
hostname_mapping=None, max_buffer_size=104857600,
- resolver=None, defaults=None, max_header_size=None):
+ resolver=None, defaults=None, max_header_size=None,
+ max_body_size=None):
"""Creates a AsyncHTTPClient.
Only a single AsyncHTTPClient instance exists per IOLoop
self.waiting = {}
self.max_buffer_size = max_buffer_size
self.max_header_size = max_header_size
+ self.max_body_size = max_body_size
# TCPClient could create a Resolver for us, but we have to do it
# ourselves to support hostname_mapping.
if resolver:
self._connection_class()(
self.io_loop, self, request, release_callback,
final_callback, self.max_buffer_size, self.tcp_client,
- self.max_header_size)
+ self.max_header_size, self.max_body_size)
def _release_fetch(self, key):
del self.active[key]
def __init__(self, io_loop, client, request, release_callback,
final_callback, max_buffer_size, tcp_client,
- max_header_size):
+ max_header_size, max_body_size):
self.start_time = io_loop.time()
self.io_loop = io_loop
self.client = client
self.max_buffer_size = max_buffer_size
self.tcp_client = tcp_client
self.max_header_size = max_header_size
+ self.max_body_size = max_body_size
self.code = None
self.headers = None
self.chunks = []
HTTP1ConnectionParameters(
no_keep_alive=True,
max_header_size=self.max_header_size,
+ max_body_size=self.max_body_size,
decompress=self.request.decompress_response),
self._sockaddr)
return connection
with ExpectLog(gen_log, "Unsatisfiable read"):
response = self.fetch('/large')
self.assertEqual(response.code, 599)
+
+
+class MaxBodySizeTest(AsyncHTTPTestCase):
+ def get_app(self):
+ class SmallBody(RequestHandler):
+ def get(self):
+ self.write("a"*1024*64)
+
+ class LargeBody(RequestHandler):
+ def get(self):
+ self.write("a"*1024*100)
+
+ return Application([('/small', SmallBody),
+ ('/large', LargeBody)])
+
+ def get_http_client(self):
+ return SimpleAsyncHTTPClient(io_loop=self.io_loop, max_body_size=1024*64)
+
+ def test_small_body(self):
+ response = self.fetch('/small')
+ response.rethrow()
+ self.assertEqual(response.body, "a"*1024*64)
+
+ def test_large_body(self):
+ with ExpectLog(gen_log, "Malformed HTTP message from None: Content-Length too long"):
+ response = self.fetch('/large')
+ self.assertEqual(response.code, 599)
+
+
+class MaxBufferSizeTest(AsyncHTTPTestCase):
+ def get_app(self):
+
+ class LargeBody(RequestHandler):
+ def get(self):
+ self.write("a"*1024*100)
+
+ return Application([('/large', LargeBody)])
+
+ def get_http_client(self):
+ # 100KB body with 64KB buffer
+ return SimpleAsyncHTTPClient(io_loop=self.io_loop, max_body_size=1024*100, max_buffer_size=1024*64)
+
+ def test_large_body(self):
+ response = self.fetch('/large')
+ response.rethrow()
+ self.assertEqual(response.body, "a"*1024*100)
self.tcp_client = TCPClient(io_loop=io_loop)
super(WebSocketClientConnection, self).__init__(
io_loop, None, request, lambda: None, self._on_http_response,
- 104857600, self.tcp_client, 65536)
+ 104857600, self.tcp_client, 65536, 104857600)
def close(self, code=None, reason=None):
"""Closes the websocket connection.