Skip to content

Commit

Permalink
Merge pull request #93 from OmarNunezG/custom-content-types-support
Browse files Browse the repository at this point in the history
Added support for `application/vnd.*+json` media types
  • Loading branch information
vishalanandl177 authored Mar 9, 2024
2 parents ab292a5 + 8f985cf commit 88b97b1
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions drf_api_logger/middleware/api_logger_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import sys
import time
import uuid
import re

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

if response.get('content-type') in (
'application/json', 'application/vnd.api+json', 'application/gzip', 'application/octet-stream'):

self.DRF_API_LOGGER_CONTENT_TYPES = [
"application/json",
"application/vnd.api+json",
"application/gzip",
"application/octet-stream",
]
if hasattr(settings, "DRF_API_LOGGER_CONTENT_TYPES") and type(
settings.DRF_API_LOGGER_CONTENT_TYPES
) in (list, tuple):
for content_type in settings.DRF_API_LOGGER_CONTENT_TYPES:
if re.match(r"^application\/vnd\..+\+json$", content_type):
self.DRF_API_LOGGER_CONTENT_TYPES.append(content_type)

if response.get("content-type") in self.DRF_API_LOGGER_CONTENT_TYPES:
if response.get('content-type') == 'application/gzip':
response_body = '** GZIP Archive **'
elif response.get('content-type') == 'application/octet-stream':
Expand Down

0 comments on commit 88b97b1

Please sign in to comment.