djresttoolkit 0.3.0__py3-none-any.whl → 0.4.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {djresttoolkit-0.3.0.dist-info → djresttoolkit-0.4.0.dist-info}/METADATA +1 -1
- {djresttoolkit-0.3.0.dist-info → djresttoolkit-0.4.0.dist-info}/RECORD +7 -5
- src/djresttoolkit/middlewares/__init__.py +3 -0
- src/djresttoolkit/middlewares/_response_time_middleware.py +32 -0
- {djresttoolkit-0.3.0.dist-info → djresttoolkit-0.4.0.dist-info}/WHEEL +0 -0
- {djresttoolkit-0.3.0.dist-info → djresttoolkit-0.4.0.dist-info}/entry_points.txt +0 -0
- {djresttoolkit-0.3.0.dist-info → djresttoolkit-0.4.0.dist-info}/licenses/LICENSE +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: djresttoolkit
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.4.0
|
4
4
|
Summary: A collection of Django and DRF utilities to simplify API development.
|
5
5
|
Project-URL: Homepage, https://github.com/shaileshpandit141/djresttoolkit
|
6
6
|
Project-URL: Documentation, https://shaileshpandit141.github.io/djresttoolkit
|
@@ -8,13 +8,15 @@ src/djresttoolkit/mail/__init__.py,sha256=tB9SdMlhfWQ640q4aobZ0H1c7fTWalpDL2I-on
|
|
8
8
|
src/djresttoolkit/mail/_email_sender.py,sha256=vvTPZzSAfX2FXHv1IY0ST8dEsq8M4wAxkihm0JbRh1Y,3136
|
9
9
|
src/djresttoolkit/mail/_models.py,sha256=_41pH3xC0jP8SHSty2FkxvRh2_ddKk-4peT11OHcBBE,1462
|
10
10
|
src/djresttoolkit/mail/_types.py,sha256=est1mrN80vB_4-j-2yuAr_l_7rNzO4AJlqpq74zO5ow,682
|
11
|
+
src/djresttoolkit/middlewares/__init__.py,sha256=GZHU3Yy4xXoEi62tHn0UJNxN6XgGM2_HES8Bt5AS5Lk,100
|
12
|
+
src/djresttoolkit/middlewares/_response_time_middleware.py,sha256=1wCwdkW5Ng6HJo8zx0F7ylms84OGP-1K0kbyG6Vacuk,908
|
11
13
|
src/djresttoolkit/migrations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
12
14
|
src/djresttoolkit/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
13
15
|
src/djresttoolkit/views/__init__.py,sha256=XrxBrs6sH4HmUzp41omcmy_y94pSaXAVn01ttQ022-4,76
|
14
16
|
src/djresttoolkit/views/_exceptions/__init__.py,sha256=DrCUxuPNyBR4WhzNutn5HDxLa--q51ykIxSG7_bFsOI,83
|
15
17
|
src/djresttoolkit/views/_exceptions/_exception_handler.py,sha256=lg6kfAABex-UbAsF78uX-M-ZnJ3u1vK1eIXytb-4KSw,2375
|
16
|
-
djresttoolkit-0.
|
17
|
-
djresttoolkit-0.
|
18
|
-
djresttoolkit-0.
|
19
|
-
djresttoolkit-0.
|
20
|
-
djresttoolkit-0.
|
18
|
+
djresttoolkit-0.4.0.dist-info/METADATA,sha256=FGDP5PR0AZoaPvEyrG95DVC516vGOWlXk2ZgyLfm8kE,4374
|
19
|
+
djresttoolkit-0.4.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
20
|
+
djresttoolkit-0.4.0.dist-info/entry_points.txt,sha256=YMhfTF-7mYppO8QqqWnvR_hyMWvoYxD6XI94_ViFu3k,60
|
21
|
+
djresttoolkit-0.4.0.dist-info/licenses/LICENSE,sha256=8-oZM3yuuTRjySMbVKX9YXYA7Y4M_KhQNBYXPFjeWUo,1074
|
22
|
+
djresttoolkit-0.4.0.dist-info/RECORD,,
|
@@ -0,0 +1,32 @@
|
|
1
|
+
import logging
|
2
|
+
import time
|
3
|
+
from collections.abc import Callable
|
4
|
+
|
5
|
+
from django.http import HttpRequest, HttpResponse
|
6
|
+
|
7
|
+
# Get logger from logging.
|
8
|
+
logger = logging.getLogger(__name__)
|
9
|
+
|
10
|
+
|
11
|
+
class ResponseTimeMiddleware:
|
12
|
+
"""Calculte response response time."""
|
13
|
+
|
14
|
+
def __init__(
|
15
|
+
self,
|
16
|
+
get_response: Callable[[HttpRequest], HttpResponse],
|
17
|
+
) -> None:
|
18
|
+
"Initilize response time middleware."
|
19
|
+
self.get_response = get_response
|
20
|
+
|
21
|
+
def __call__(self, request: HttpRequest) -> HttpResponse:
|
22
|
+
"""Handle to response response time calculation."""
|
23
|
+
start_time = time.perf_counter()
|
24
|
+
response = self.get_response(request)
|
25
|
+
end_time = time.perf_counter()
|
26
|
+
|
27
|
+
response_time = f"{round(end_time - start_time, 5)} seconds"
|
28
|
+
response["X-Response-Time"] = response_time
|
29
|
+
|
30
|
+
logger.info(f"Request processed in {response_time}")
|
31
|
+
|
32
|
+
return response
|
File without changes
|
File without changes
|
File without changes
|