Add section for internal configuration
This commit is contained in:
parent
59f7104dce
commit
4282ea46e4
@ -93,7 +93,7 @@ DAV_HEADERS = "1, 2, 3, calendar-access, addressbook, extended-mkcol"
|
|||||||
class Application:
|
class Application:
|
||||||
"""WSGI application managing collections."""
|
"""WSGI application managing collections."""
|
||||||
|
|
||||||
def __init__(self, configuration, internal_server=False):
|
def __init__(self, configuration):
|
||||||
"""Initialize application."""
|
"""Initialize application."""
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.configuration = configuration
|
self.configuration = configuration
|
||||||
@ -102,7 +102,6 @@ class Application:
|
|||||||
self.Rights = rights.load(configuration)
|
self.Rights = rights.load(configuration)
|
||||||
self.Web = web.load(configuration)
|
self.Web = web.load(configuration)
|
||||||
self.encoding = configuration.get("encoding", "request")
|
self.encoding = configuration.get("encoding", "request")
|
||||||
self.internal_server = internal_server
|
|
||||||
|
|
||||||
def headers_log(self, environ):
|
def headers_log(self, environ):
|
||||||
"""Sanitize headers for logging."""
|
"""Sanitize headers for logging."""
|
||||||
@ -333,14 +332,15 @@ class Application:
|
|||||||
logger.warning("Access to principal path %r denied by "
|
logger.warning("Access to principal path %r denied by "
|
||||||
"rights backend", principal_path)
|
"rights backend", principal_path)
|
||||||
|
|
||||||
# Verify content length
|
if self.configuration.getboolean("internal", "internal_server"):
|
||||||
content_length = int(environ.get("CONTENT_LENGTH") or 0)
|
# Verify content length
|
||||||
if self.internal_server and content_length:
|
content_length = int(environ.get("CONTENT_LENGTH") or 0)
|
||||||
max_content_length = self.configuration.getint(
|
if content_length:
|
||||||
"server", "max_content_length")
|
max_content_length = self.configuration.getint(
|
||||||
if max_content_length and content_length > max_content_length:
|
"server", "max_content_length")
|
||||||
logger.info("Request body too large: %d", content_length)
|
if max_content_length and content_length > max_content_length:
|
||||||
return response(*REQUEST_ENTITY_TOO_LARGE)
|
logger.info("Request body too large: %d", content_length)
|
||||||
|
return response(*REQUEST_ENTITY_TOO_LARGE)
|
||||||
|
|
||||||
if not login or user:
|
if not login or user:
|
||||||
status, headers, answer = function(
|
status, headers, answer = function(
|
||||||
|
@ -187,6 +187,12 @@ INITIAL_CONFIG = OrderedDict([
|
|||||||
"value": "True",
|
"value": "True",
|
||||||
"help": "mask passwords in logs",
|
"help": "mask passwords in logs",
|
||||||
"type": bool})]))])
|
"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):
|
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: "
|
"Invalid %s value for option %r in section %r in config: "
|
||||||
"%r" % (type_.__name__, option, section,
|
"%r" % (type_.__name__, option, section,
|
||||||
config.get(section, option))) from e
|
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
|
return config
|
||||||
|
@ -192,6 +192,7 @@ class RequestHandler(wsgiref.simple_server.WSGIRequestHandler):
|
|||||||
def serve(configuration):
|
def serve(configuration):
|
||||||
"""Serve radicale from configuration."""
|
"""Serve radicale from configuration."""
|
||||||
logger.info("Starting Radicale")
|
logger.info("Starting Radicale")
|
||||||
|
configuration["internal"]["internal_server"] = "True"
|
||||||
|
|
||||||
# Create collection servers
|
# Create collection servers
|
||||||
servers = {}
|
servers = {}
|
||||||
@ -232,7 +233,7 @@ def serve(configuration):
|
|||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
"Failed to parse address %r: %s" % (host, e)) from e
|
"Failed to parse address %r: %s" % (host, e)) from e
|
||||||
application = Application(configuration, internal_server=True)
|
application = Application(configuration)
|
||||||
try:
|
try:
|
||||||
server = wsgiref.simple_server.make_server(
|
server = wsgiref.simple_server.make_server(
|
||||||
address, port, application, server_class, RequestHandler)
|
address, port, application, server_class, RequestHandler)
|
||||||
|
Loading…
Reference in New Issue
Block a user