From a346bc628589bfa3d0305d30df150def1611ae86 Mon Sep 17 00:00:00 2001 From: Oliver Falk Date: Wed, 21 Apr 2021 15:15:02 +0200 Subject: [PATCH 1/3] JSON of course return json, but also normal web requests --- ivatar/views.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ivatar/views.py b/ivatar/views.py index d3de012..57f21f0 100644 --- a/ivatar/views.py +++ b/ivatar/views.py @@ -411,7 +411,8 @@ class StatsView(TemplateView, JsonResponse): 'openids': ConfirmedOpenId.objects.all().count(), # pylint: disable=no-member } - if request.content_type == 'application/json': + # JSON of course return json, but also normal web requests default to JSON + if request.content_type == 'application/json' or request.content_type == 'text/plain': return JsonResponse(retval) return HttpResponseRedirect(reverse_lazy('home')) From b52244b16791a388061edbd2c449e7a99ad246b2 Mon Sep 17 00:00:00 2001 From: Oliver Falk Date: Wed, 21 Apr 2021 15:29:16 +0200 Subject: [PATCH 2/3] We also need to handle 'text/html' this way --- ivatar/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ivatar/views.py b/ivatar/views.py index 57f21f0..09e474b 100644 --- a/ivatar/views.py +++ b/ivatar/views.py @@ -412,7 +412,7 @@ class StatsView(TemplateView, JsonResponse): } # JSON of course return json, but also normal web requests default to JSON - if request.content_type == 'application/json' or request.content_type == 'text/plain': + if request.content_type in ('application/json', 'text/plain', 'text/html'): return JsonResponse(retval) return HttpResponseRedirect(reverse_lazy('home')) From 5733448830ae71fa4b4f18f5b5a6f518e6fc4b65 Mon Sep 17 00:00:00 2001 From: Oliver Falk Date: Wed, 21 Apr 2021 15:41:05 +0200 Subject: [PATCH 3/3] Just default to sending JSON - everything else seems not to work correctly --- ivatar/views.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/ivatar/views.py b/ivatar/views.py index 09e474b..49a8b33 100644 --- a/ivatar/views.py +++ b/ivatar/views.py @@ -411,8 +411,4 @@ class StatsView(TemplateView, JsonResponse): 'openids': ConfirmedOpenId.objects.all().count(), # pylint: disable=no-member } - # JSON of course return json, but also normal web requests default to JSON - if request.content_type in ('application/json', 'text/plain', 'text/html'): - return JsonResponse(retval) - - return HttpResponseRedirect(reverse_lazy('home')) + return JsonResponse(retval)