Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for application/vnd.*+json media types #93

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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