mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
...
This commit is contained in:
parent
3e180d2fba
commit
42dd04b854
@ -262,7 +262,8 @@ class HTTPPair(object):
|
||||
def __init__(self, conn, handle_request):
|
||||
self.conn = conn
|
||||
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.inheaders = MultiDict()
|
||||
self.outheaders = MultiDict()
|
||||
@ -393,11 +394,11 @@ class HTTPPair(object):
|
||||
self.simple_response(httplib.BAD_REQUEST, as_unicode(e))
|
||||
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(
|
||||
httplib.REQUEST_ENTITY_TOO_LARGE,
|
||||
"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
|
||||
|
||||
# Persistent connection support
|
||||
@ -470,7 +471,7 @@ class HTTPPair(object):
|
||||
|
||||
def response(self):
|
||||
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:
|
||||
self.input_reader = FixedSizeReader(self.conn.socket_file, self.request_content_length)
|
||||
|
||||
|
@ -8,58 +8,74 @@ __copyright__ = '2015, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
|
||||
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 = (
|
||||
|
||||
'Path to the SSL certificate file',
|
||||
'ssl_certfile', None,
|
||||
None,
|
||||
|
||||
'Path to the SSL private key file',
|
||||
'ssl_keyfile', None,
|
||||
None,
|
||||
|
||||
' Max. queued connections while waiting to accept',
|
||||
'Max. queued connections while waiting to accept',
|
||||
'request_queue_size', 5,
|
||||
None,
|
||||
|
||||
'Timeout in seconds for accepted connections',
|
||||
'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,
|
||||
None,
|
||||
|
||||
'Minimum number of connection handling threads',
|
||||
'min_threads', 10,
|
||||
None,
|
||||
|
||||
'Maximum number of simultaneous connections (beyond this number of connections will be dropped)',
|
||||
'max_threads', 500,
|
||||
None,
|
||||
|
||||
'Allow socket pre-allocation, for example, with systemd socket activation',
|
||||
'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,
|
||||
None,
|
||||
|
||||
'Max. size of a request (in MB)',
|
||||
'Max. size of a HTTP request (in MB)',
|
||||
'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'
|
||||
' worse overall performance when sending multiple small packets. It'
|
||||
' prevents the TCP stack from aggregating multiple small TCP packets.',
|
||||
'no_delay', True,
|
||||
)
|
||||
|
||||
options = []
|
||||
|
||||
i = 0
|
||||
while i + 2 < len(raw_options):
|
||||
doc, name, default = raw_options[i:i+3]
|
||||
i += 3
|
||||
while i + 3 < len(raw_options):
|
||||
shortdoc, name, default, doc = raw_options[i:i+4]
|
||||
i += 4
|
||||
choices = None
|
||||
if isinstance(default, set):
|
||||
default = list(default)[0]
|
||||
choices = raw_options[i]
|
||||
i += 1
|
||||
options.append(Option(name, default, doc, choices))
|
||||
if isinstance(default, Choices):
|
||||
choices = default
|
||||
default = default.default
|
||||
options.append(Option(name, default, doc, shortdoc, choices))
|
||||
options = tuple(options)
|
||||
del raw_options
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user