Skip to content

Commit 8ae0049

Browse files
committed
Modernize the code for Django 4.2
Applied via django-upgrade
1 parent 64c0206 commit 8ae0049

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

django_prometheus/middleware.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,10 @@ def process_request(self, request):
219219
self.label_metric(self.metrics.requests_by_transport, request, transport=transport).inc()
220220

221221
# Mimic the behaviour of the deprecated "Request.is_ajax()" method.
222-
if request.META.get("HTTP_X_REQUESTED_WITH") == "XMLHttpRequest":
222+
if request.headers.get("x-requested-with") == "XMLHttpRequest":
223223
self.label_metric(self.metrics.requests_ajax, request).inc()
224224

225-
content_length = int(request.META.get("CONTENT_LENGTH") or 0)
225+
content_length = int(request.headers.get("content-length") or 0)
226226
self.label_metric(self.metrics.requests_body_bytes, request).observe(content_length)
227227
request.prometheus_after_middleware_event = Time()
228228

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
from django.contrib import admin
2-
from django.urls import include, path, re_path
2+
from django.urls import include, path
33

44
from testapp import views
55

66
urlpatterns = [
7-
re_path(r"^$", views.index),
8-
re_path(r"^help$", views.help),
9-
re_path(r"^slow$", views.slow, name="slow"),
10-
re_path(r"^objection$", views.objection),
11-
re_path(r"^sql$", views.sql),
12-
re_path(r"^newlawn/(?P<location>[a-zA-Z0-9 ]+)$", views.newlawn),
13-
re_path(r"^file$", views.file),
7+
path("", views.index),
8+
path("help", views.help),
9+
path("slow", views.slow, name="slow"),
10+
path("objection", views.objection),
11+
path("sql", views.sql),
12+
path("newlawn/<str:location>", views.newlawn),
13+
path("file", views.file),
1414
path("", include("django_prometheus.urls")),
15-
re_path(r"^admin/", admin.site.urls),
15+
path("admin/", admin.site.urls),
1616
]

0 commit comments

Comments
 (0)