Skip to content

Commit 09d38d2

Browse files
2 parents 15ec845 + aa2d940 commit 09d38d2

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

drf_api_logger/middleware/api_logger_middleware.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,16 @@ def __init__(self, get_response):
7979
if type(settings.DRF_API_LOGGER_MAX_RESPONSE_BODY_SIZE) is int:
8080
self.DRF_API_LOGGER_MAX_RESPONSE_BODY_SIZE = settings.DRF_API_LOGGER_MAX_RESPONSE_BODY_SIZE
8181

82+
def is_static_or_media_request(self, path):
83+
static_url = getattr(settings, 'STATIC_URL', '/static/')
84+
media_url = getattr(settings, 'MEDIA_URL', '/media/')
85+
86+
return path.startswith(static_url) or path.startswith(media_url)
87+
8288
def __call__(self, request):
89+
# Skip logging for static and media files
90+
if self.is_static_or_media_request(request.path):
91+
return self.get_response(request)
8392

8493
# Run only if logger is enabled.
8594
if self.DRF_API_LOGGER_DATABASE or self.DRF_API_LOGGER_SIGNAL:
@@ -150,6 +159,7 @@ def __call__(self, request):
150159
"application/vnd.api+json",
151160
"application/gzip",
152161
"application/octet-stream",
162+
"text/calendar",
153163
]
154164
if hasattr(settings, "DRF_API_LOGGER_CONTENT_TYPES") and type(
155165
settings.DRF_API_LOGGER_CONTENT_TYPES
@@ -165,6 +175,9 @@ def __call__(self, request):
165175
response_body = '** Binary File **'
166176
elif getattr(response, 'streaming', False):
167177
response_body = '** Streaming **'
178+
elif response.get('content-type') == 'text/calendar':
179+
response_body = '** Calendar **'
180+
168181
else:
169182
if type(response.content) is bytes:
170183
response_body = json.loads(response.content.decode())

0 commit comments

Comments
 (0)