Merge pull request #22 from bkorty/expose-http-server-options

Support max_body_size and max_buffer_size.
This commit is contained in:
dave-shawley 2018-01-25 09:22:39 -05:00 committed by GitHub
commit 9efd85f197
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 8 deletions

View file

@ -68,13 +68,23 @@ class Runner(object):
going to run in a single-process mode; otherwise, we'll let
tornado decide how many sub-processes to spawn.
The following additional configuration parameters can be set on the
``httpserver.HTTPServer`` instance by setting them in the application
settings: ``xheaders``, ``max_body_size``, ``max_buffer_size``.
"""
signal.signal(signal.SIGTERM, self._on_signal)
signal.signal(signal.SIGINT, self._on_signal)
xheaders = self.application.settings.get('xheaders', False)
max_body_size = self.application.settings.get('max_body_size', None)
max_buffer_size = self.application.settings.get('max_buffer_size',
None)
self.server = httpserver.HTTPServer(
self.application.tornado_application, xheaders=xheaders)
self.application.tornado_application,
xheaders=xheaders,
max_body_size=max_body_size,
max_buffer_size=max_buffer_size)
if self.application.settings.get('debug', False):
self.logger.info('starting 1 process on port %d', port_number)
self.server.listen(port_number)
@ -97,14 +107,18 @@ class Runner(object):
If the application's ``debug`` setting is ``True``, then we are
going to run in a single-process mode; otherwise, we'll let
tornado decide how many sub-processes to spawn. In any case, the
applications *before_run* callbacks are invoked. If a callback
raises an exception, then the application is terminated by calling
:func:`sys.exit`.
tornado decide how many sub-processes based on the value of the
``number_of_procs`` argument. In any case, the application's
*before_run* callbacks are invoked. If a callback raises an exception,
then the application is terminated by calling :func:`sys.exit`.
If any ``on_start`` callbacks are registered, they will be added to
the Tornado IOLoop for execution after the IOLoop is started.
The following additional configuration parameters can be set on the
``httpserver.HTTPServer`` instance by setting them in the application
settings: ``xheaders``, ``max_body_size``, ``max_buffer_size``.
"""
self.start_server(port_number, number_of_procs)
iol = ioloop.IOLoop.instance()

View file

@ -369,7 +369,11 @@ class RunnerTests(MockHelper, unittest.TestCase):
def setUp(self):
super(RunnerTests, self).setUp()
self.application = mock.Mock()
self.application.settings = {}
self.application.settings = {
'xheaders': True,
'max_body_size': 2048,
'max_buffer_size': 1024
}
self.application.runner_callbacks = {}
self.io_loop = mock.Mock()
@ -380,14 +384,21 @@ class RunnerTests(MockHelper, unittest.TestCase):
ioloop_module.IOLoop.instance.return_value = self.io_loop
self.http_server = mock.Mock()
httpserver_module = self.start_mock('sprockets.http.runner.httpserver')
httpserver_module.HTTPServer.return_value = self.http_server
self.httpserver_module = \
self.start_mock('sprockets.http.runner.httpserver')
self.httpserver_module.HTTPServer.return_value = self.http_server
def test_that_run_starts_ioloop(self):
runner = sprockets.http.runner.Runner(self.application)
runner.run(8000)
self.io_loop.start.assert_called_once_with()
def test_that_http_server_settings_are_used(self):
runner = sprockets.http.runner.Runner(self.application)
runner.run(8000)
self.httpserver_module.HTTPServer.assert_called_once_with(
self.application, **self.application.settings)
def test_that_production_run_starts_in_multiprocess_mode(self):
runner = sprockets.http.runner.Runner(self.application)
runner.run(8000)