Only limit content length with internal server

This commit is contained in:
Unrud 2018-08-16 08:00:01 +02:00
parent 6b281e1726
commit 59d10ef9f7
2 changed files with 4 additions and 3 deletions

View File

@ -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): def __init__(self, configuration, internal_server=False):
"""Initialize application.""" """Initialize application."""
super().__init__() super().__init__()
self.configuration = configuration self.configuration = configuration
@ -102,6 +102,7 @@ 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."""
@ -334,7 +335,7 @@ class Application:
# Verify content length # Verify content length
content_length = int(environ.get("CONTENT_LENGTH") or 0) content_length = int(environ.get("CONTENT_LENGTH") or 0)
if content_length: if self.internal_server and content_length:
max_content_length = self.configuration.getint( max_content_length = self.configuration.getint(
"server", "max_content_length") "server", "max_content_length")
if max_content_length and content_length > max_content_length: if max_content_length and content_length > max_content_length:

View File

@ -236,7 +236,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) application = Application(configuration, internal_server=True)
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)