diff --git a/zerver/lib/rest.py b/zerver/lib/rest.py index 9fdd206658..614cadd3f4 100644 --- a/zerver/lib/rest.py +++ b/zerver/lib/rest.py @@ -104,6 +104,7 @@ def rest_dispatch(request, **kwargs): # If this looks like a request from a top-level page in a # browser, send the user to the login page if 'text/html' in request.META.get('HTTP_ACCEPT', ''): + # TODO: It seems like the `?next=` part is unlikely to be helpful return HttpResponseRedirect('%s/?next=%s' % (settings.HOME_NOT_LOGGED_IN, request.path)) # Ask for basic auth (email:apiKey) elif request.path.startswith("/api"): diff --git a/zerver/tests/test_decorators.py b/zerver/tests/test_decorators.py index 9de5bd14fd..6620606efd 100644 --- a/zerver/tests/test_decorators.py +++ b/zerver/tests/test_decorators.py @@ -1023,3 +1023,10 @@ class RestAPITest(ZulipTestCase): result = self.client_options('/json/streams/15') self.assertEqual(result.status_code, 204) self.assertEqual(str(result['Allow']), 'DELETE, PATCH') + + def test_http_accept_redirect(self): + # type: () -> None + result = self.client_get('/json/users', + HTTP_ACCEPT='text/html') + self.assertEqual(result.status_code, 302) + self.assertTrue(result["Location"].endswith("/login/?next=/json/users"))