misc: use the same content-types list for logging and substitutions (#738050

This commit is contained in:
Benjamin Dauvergne 2023-01-26 18:01:30 +01:00 committed by Gitea
parent c218597faa
commit cd9b550d50
2 changed files with 4 additions and 3 deletions

View File

@ -274,7 +274,7 @@ DATA_UPLOAD_MAX_MEMORY_SIZE = 100 * 1024 * 1024
SITE_BASE_URL = 'http://localhost'
# List of passerelle.utils.Request response Content-Type to log
LOGGED_CONTENT_TYPES_MESSAGES = (r'text/', r'application/(json|xml)')
LOGGED_CONTENT_TYPES_MESSAGES = [r'text/.*', r'application/(.*\+)?json', r'application/(.*\+)?xml']
# Max size of the response to log
LOGGED_RESPONSES_MAX_SIZE = 5000

View File

@ -176,7 +176,7 @@ def protected_api(perm):
return decorator
def content_type_match(ctype):
def should_content_type_body_be_logged(ctype):
content_types = settings.LOGGED_CONTENT_TYPES_MESSAGES
if not ctype:
return False
@ -219,7 +219,8 @@ def log_http_request(
if logger.level == 10: # DEBUG
extra['response_headers'] = make_headers_safe(response.headers)
# log body only if content type is allowed
if content_type_match(response.headers.get('Content-Type')):
content_type = response.headers.get('Content-Type', '').split(';')[0].strip().lower()
if should_content_type_body_be_logged(content_type):
max_size = settings.LOGGED_RESPONSES_MAX_SIZE
if hasattr(logger, 'connector'):
max_size = logger.connector.logging_parameters.responses_max_size or max_size