From 4282ea46e439e6b18f072d737ffc3aaa549591a2 Mon Sep 17 00:00:00 2001 From: Unrud Date: Sat, 18 Aug 2018 12:56:38 +0200 Subject: [PATCH] Add section for internal configuration --- radicale/__init__.py | 20 ++++++++++---------- radicale/config.py | 10 ++++++++++ radicale/server.py | 3 ++- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/radicale/__init__.py b/radicale/__init__.py index 71373e5..ed0654d 100644 --- a/radicale/__init__.py +++ b/radicale/__init__.py @@ -93,7 +93,7 @@ DAV_HEADERS = "1, 2, 3, calendar-access, addressbook, extended-mkcol" class Application: """WSGI application managing collections.""" - def __init__(self, configuration, internal_server=False): + def __init__(self, configuration): """Initialize application.""" super().__init__() self.configuration = configuration @@ -102,7 +102,6 @@ class Application: self.Rights = rights.load(configuration) self.Web = web.load(configuration) self.encoding = configuration.get("encoding", "request") - self.internal_server = internal_server def headers_log(self, environ): """Sanitize headers for logging.""" @@ -333,14 +332,15 @@ class Application: logger.warning("Access to principal path %r denied by " "rights backend", principal_path) - # Verify content length - content_length = int(environ.get("CONTENT_LENGTH") or 0) - if self.internal_server and content_length: - max_content_length = self.configuration.getint( - "server", "max_content_length") - if max_content_length and content_length > max_content_length: - logger.info("Request body too large: %d", content_length) - return response(*REQUEST_ENTITY_TOO_LARGE) + if self.configuration.getboolean("internal", "internal_server"): + # Verify content length + content_length = int(environ.get("CONTENT_LENGTH") or 0) + if content_length: + max_content_length = self.configuration.getint( + "server", "max_content_length") + if max_content_length and content_length > max_content_length: + logger.info("Request body too large: %d", content_length) + return response(*REQUEST_ENTITY_TOO_LARGE) if not login or user: status, headers, answer = function( diff --git a/radicale/config.py b/radicale/config.py index d9378d3..9c3fc7a 100644 --- a/radicale/config.py +++ b/radicale/config.py @@ -187,6 +187,12 @@ INITIAL_CONFIG = OrderedDict([ "value": "True", "help": "mask passwords in logs", "type": bool})]))]) +# Default configuration for "internal" settings +INTERNAL_CONFIG = OrderedDict([ + ("internal_server", { + "value": "False", + "help": "the internal server is used", + "type": bool})]) def load(paths=(), extra_config=None, ignore_missing_paths=True): @@ -234,4 +240,8 @@ def load(paths=(), extra_config=None, ignore_missing_paths=True): "Invalid %s value for option %r in section %r in config: " "%r" % (type_.__name__, option, section, config.get(section, option))) from e + # Add internal configuration + config.add_section("internal") + for key, data in INTERNAL_CONFIG.items(): + config.set("internal", key, data["value"]) return config diff --git a/radicale/server.py b/radicale/server.py index 694d838..78b33c1 100644 --- a/radicale/server.py +++ b/radicale/server.py @@ -192,6 +192,7 @@ class RequestHandler(wsgiref.simple_server.WSGIRequestHandler): def serve(configuration): """Serve radicale from configuration.""" logger.info("Starting Radicale") + configuration["internal"]["internal_server"] = "True" # Create collection servers servers = {} @@ -232,7 +233,7 @@ def serve(configuration): except ValueError as e: raise RuntimeError( "Failed to parse address %r: %s" % (host, e)) from e - application = Application(configuration, internal_server=True) + application = Application(configuration) try: server = wsgiref.simple_server.make_server( address, port, application, server_class, RequestHandler)