Skip to content

Commit 8f985cf

Browse files
committed
Added support for media types
1 parent ab292a5 commit 8f985cf

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

drf_api_logger/middleware/api_logger_middleware.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import sys
44
import time
55
import uuid
6+
import re
67

78
from django.conf import settings
89
from django.urls import resolve
@@ -149,9 +150,20 @@ def __call__(self, request):
149150
if len(self.DRF_API_LOGGER_METHODS) > 0 and method not in self.DRF_API_LOGGER_METHODS:
150151
return response
151152

152-
if response.get('content-type') in (
153-
'application/json', 'application/vnd.api+json', 'application/gzip', 'application/octet-stream'):
154-
153+
self.DRF_API_LOGGER_CONTENT_TYPES = [
154+
"application/json",
155+
"application/vnd.api+json",
156+
"application/gzip",
157+
"application/octet-stream",
158+
]
159+
if hasattr(settings, "DRF_API_LOGGER_CONTENT_TYPES") and type(
160+
settings.DRF_API_LOGGER_CONTENT_TYPES
161+
) in (list, tuple):
162+
for content_type in settings.DRF_API_LOGGER_CONTENT_TYPES:
163+
if re.match(r"^application\/vnd\..+\+json$", content_type):
164+
self.DRF_API_LOGGER_CONTENT_TYPES.append(content_type)
165+
166+
if response.get("content-type") in self.DRF_API_LOGGER_CONTENT_TYPES:
155167
if response.get('content-type') == 'application/gzip':
156168
response_body = '** GZIP Archive **'
157169
elif response.get('content-type') == 'application/octet-stream':

0 commit comments

Comments
 (0)