Skip to content

Commit 01d944c

Browse files
committed
Proxito: don't require the middleware for proxied apis
None of these need the proxito request middleware (response is needed). The analytics api isn't listed because it depends on the unresolver, which depends on the proxito middleware.
1 parent b586cf0 commit 01d944c

File tree

4 files changed

+20
-10
lines changed

4 files changed

+20
-10
lines changed

readthedocs/analytics/tests.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from readthedocs.builds.models import Version
1010
from readthedocs.projects.constants import PUBLIC
11-
from readthedocs.projects.models import Feature, Project
11+
from readthedocs.projects.models import Project
1212

1313
from .models import PageView
1414
from .utils import anonymize_ip_address, anonymize_user_agent, get_client_ip

readthedocs/api/v2/proxied_urls.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
so they can make use of features that require to have access to their cookies.
66
"""
77

8-
from django.conf import settings
9-
from django.conf.urls import include, url
8+
from django.conf.urls import url
109

1110
from readthedocs.analytics.proxied_api import AnalyticsView
1211
from readthedocs.api.v2.views.proxied import ProxiedEmbedAPI, ProxiedFooterHTML

readthedocs/proxito/middleware.py

+17-6
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,13 @@ def map_host_to_project_slug(request): # pylint: disable=too-many-return-statem
124124

125125
class ProxitoMiddleware(MiddlewareMixin):
126126

127+
skip_views = (
128+
'health_check',
129+
'footer_html',
130+
'search_api',
131+
'embed_api',
132+
)
133+
127134
"""The actual middleware we'll be using in prod."""
128135

129136
# pylint: disable=no-self-use
@@ -167,12 +174,16 @@ def add_proxito_headers(self, request, response):
167174
response['X-RTD-Version-Method'] = 'path'
168175

169176
def process_request(self, request): # noqa
170-
if any([
171-
not settings.USE_SUBDOMAIN,
172-
'localhost' in request.get_host(),
173-
'testserver' in request.get_host(),
174-
request.path.startswith(reverse('health_check')),
175-
]):
177+
skip = any(
178+
request.path.startswith(reverse(view))
179+
for view in self.skip_views
180+
)
181+
if (
182+
skip
183+
or not settings.USE_SUBDOMAIN
184+
or 'localhost' in request.get_host()
185+
or 'testserver' in request.get_host()
186+
):
176187
log.debug('Not processing Proxito middleware')
177188
return None
178189

readthedocs/rtd_tests/tests/test_footer.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ def test_highest_version_without_tags(self):
424424
class TestFooterPerformance(TestCase):
425425
# The expected number of queries for generating the footer
426426
# This shouldn't increase unless we modify the footer API
427-
EXPECTED_QUERIES = 15
427+
EXPECTED_QUERIES = 12
428428

429429
def setUp(self):
430430
self.pip = get(

0 commit comments

Comments
 (0)