This commit is contained in:
Kovid Goyal 2015-05-19 10:29:35 +05:30
parent 3e180d2fba
commit 42dd04b854
2 changed files with 35 additions and 18 deletions

View File

@ -262,7 +262,8 @@ class HTTPPair(object):
def __init__(self, conn, handle_request): def __init__(self, conn, handle_request):
self.conn = conn self.conn = conn
self.server_loop = conn.server_loop self.server_loop = conn.server_loop
self.max_header_line_size = self.server_loop.opts.max_header_line_size self.max_header_line_size = self.server_loop.opts.max_header_line_size * 1024
self.max_request_body_size = self.server_loop.opts.max_request_body_size * 1024 * 1024
self.scheme = 'http' if self.server_loop.ssl_context is None else 'https' self.scheme = 'http' if self.server_loop.ssl_context is None else 'https'
self.inheaders = MultiDict() self.inheaders = MultiDict()
self.outheaders = MultiDict() self.outheaders = MultiDict()
@ -393,11 +394,11 @@ class HTTPPair(object):
self.simple_response(httplib.BAD_REQUEST, as_unicode(e)) self.simple_response(httplib.BAD_REQUEST, as_unicode(e))
return False return False
if self.request_content_length > self.server_loop.opts.max_request_body_size: if self.request_content_length > self.max_request_body_size:
self.simple_response( self.simple_response(
httplib.REQUEST_ENTITY_TOO_LARGE, httplib.REQUEST_ENTITY_TOO_LARGE,
"The entity sent with the request exceeds the maximum " "The entity sent with the request exceeds the maximum "
"allowed bytes (%d)." % self.server_loop.opts.max_request_body_size) "allowed bytes (%d)." % self.max_request_body_size)
return False return False
# Persistent connection support # Persistent connection support
@ -470,7 +471,7 @@ class HTTPPair(object):
def response(self): def response(self):
if self.chunked_read: if self.chunked_read:
self.input_reader = ChunkedReader(self.conn.socket_file, self.server_loop.opts.max_request_body_size) self.input_reader = ChunkedReader(self.conn.socket_file, self.max_request_body_size)
else: else:
self.input_reader = FixedSizeReader(self.conn.socket_file, self.request_content_length) self.input_reader = FixedSizeReader(self.conn.socket_file, self.request_content_length)

View File

@ -8,58 +8,74 @@ __copyright__ = '2015, Kovid Goyal <kovid at kovidgoyal.net>'
from collections import namedtuple from collections import namedtuple
Option = namedtuple('Option', 'name default doc choices') Option = namedtuple('Option', 'name default longdoc shortdoc choices')
class Choices(frozenset):
def __new__(cls, *args):
self = super(Choices, cls).__new__(cls, args)
self.default = args[0]
return self
raw_options = ( raw_options = (
'Path to the SSL certificate file', 'Path to the SSL certificate file',
'ssl_certfile', None, 'ssl_certfile', None,
None,
'Path to the SSL private key file', 'Path to the SSL private key file',
'ssl_keyfile', None, 'ssl_keyfile', None,
None,
' Max. queued connections while waiting to accept', 'Max. queued connections while waiting to accept',
'request_queue_size', 5, 'request_queue_size', 5,
None,
'Timeout in seconds for accepted connections', 'Timeout in seconds for accepted connections',
'timeout', 10.0, 'timeout', 10.0,
None,
'Total time in seconds to wait for worker threads to cleanly exit', 'Total time in seconds to wait for clean shutdown',
'shutdown_timeout', 5.0, 'shutdown_timeout', 5.0,
None,
'Minimum number of connection handling threads', 'Minimum number of connection handling threads',
'min_threads', 10, 'min_threads', 10,
None,
'Maximum number of simultaneous connections (beyond this number of connections will be dropped)', 'Maximum number of simultaneous connections (beyond this number of connections will be dropped)',
'max_threads', 500, 'max_threads', 500,
None,
'Allow socket pre-allocation, for example, with systemd socket activation', 'Allow socket pre-allocation, for example, with systemd socket activation',
'allow_socket_preallocation', True, 'allow_socket_preallocation', True,
None,
'Max. size of single header (in KB)', 'Max. size of single HTTP header (in KB)',
'max_header_line_size', 8, 'max_header_line_size', 8,
None,
'Max. size of a request (in MB)', 'Max. size of a HTTP request (in MB)',
'max_request_body_size', 500, 'max_request_body_size', 500,
None,
'Decrease latency by using the TCP_NODELAY feature',
'no_delay', True,
'no_delay turns on TCP_NODELAY which decreases latency at the cost of' 'no_delay turns on TCP_NODELAY which decreases latency at the cost of'
' worse overall performance when sending multiple small packets. It' ' worse overall performance when sending multiple small packets. It'
' prevents the TCP stack from aggregating multiple small TCP packets.', ' prevents the TCP stack from aggregating multiple small TCP packets.',
'no_delay', True,
) )
options = [] options = []
i = 0 i = 0
while i + 2 < len(raw_options): while i + 3 < len(raw_options):
doc, name, default = raw_options[i:i+3] shortdoc, name, default, doc = raw_options[i:i+4]
i += 3 i += 4
choices = None choices = None
if isinstance(default, set): if isinstance(default, Choices):
default = list(default)[0] choices = default
choices = raw_options[i] default = default.default
i += 1 options.append(Option(name, default, doc, shortdoc, choices))
options.append(Option(name, default, doc, choices))
options = tuple(options) options = tuple(options)
del raw_options del raw_options