Skip to content

Commit d1366df

Browse files
committed
Add ability to control what http method to handle.
1 parent 85c28f9 commit d1366df

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ REQUESTLOGS = {
107107
'SERIALIZER_CLASS': 'requestlogs.storages.BaseEntrySerializer',
108108
'SECRETS': ['password', 'token'],
109109
'ATTRIBUTE_NAME': '_requestlog',
110+
'METHODS': ('GET', 'PUT', 'PATCH', 'POST', 'DELETE'),
110111
}
111112
```
112113

@@ -120,6 +121,8 @@ REQUESTLOGS = {
120121
- List of keys in request/response data which will be replaced with `'***'` in the stored entry.
121122
- **ATTRIBUTE_NAME**
122123
- django-requestlogs internally attaches the entry object to the Django request object, and uses this attribute name. Override if it causes collisions.
124+
- **METHODS**
125+
- django-requestlogs will handle only HTTP methods defined by this setting. By default it handles all HTTP methods.
123126

124127

125128
# Logging with Request ID

requestlogs/base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
'SECRETS': ['password', 'token'],
1212
'REQUEST_ID_ATTRIBUTE_NAME': 'request_id',
1313
'REQUEST_ID_HTTP_HEADER': None,
14+
'METHODS': ('GET', 'PUT', 'PATCH', 'POST', 'DELETE')
1415
}
1516

1617

requestlogs/middleware.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ def process_view(self, request, view_func, view_args, view_kwargs):
1414

1515
def __call__(self, request):
1616
response = self.get_response(request)
17-
get_requestlog_entry(request).finalize(response)
17+
18+
# handle only methods defined in the settings
19+
if request.method.upper() in tuple(m.upper() for m in SETTINGS['METHODS']):
20+
get_requestlog_entry(request).finalize(response)
21+
1822
return response
1923

2024

0 commit comments

Comments
 (0)