Skip to content

Proxito: don't require the middleware for proxied apis #8203

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion readthedocs/analytics/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from readthedocs.builds.models import Version
from readthedocs.projects.constants import PUBLIC
from readthedocs.projects.models import Feature, Project
from readthedocs.projects.models import Project

from .models import PageView
from .utils import anonymize_ip_address, anonymize_user_agent, get_client_ip
Expand Down
3 changes: 1 addition & 2 deletions readthedocs/api/v2/proxied_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
so they can make use of features that require to have access to their cookies.
"""

from django.conf import settings
from django.conf.urls import include, url
from django.conf.urls import url

from readthedocs.analytics.proxied_api import AnalyticsView
from readthedocs.api.v2.views.proxied import ProxiedEmbedAPI, ProxiedFooterHTML
Expand Down
26 changes: 20 additions & 6 deletions readthedocs/proxito/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,16 @@ class ProxitoMiddleware(MiddlewareMixin):

"""The actual middleware we'll be using in prod."""

# 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.
skip_views = (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could use a comment explaining why they can be skipped (basically what's in the PR)

'health_check',
'footer_html',
'search_api',
'embed_api',
)

# pylint: disable=no-self-use
def add_proxito_headers(self, request, response):
"""Add debugging and cache headers to proxito responses."""
Expand Down Expand Up @@ -167,12 +177,16 @@ def add_proxito_headers(self, request, response):
response['X-RTD-Version-Method'] = 'path'

def process_request(self, request): # noqa
if any([
not settings.USE_SUBDOMAIN,
'localhost' in request.get_host(),
'testserver' in request.get_host(),
request.path.startswith(reverse('health_check')),
]):
skip = any(
request.path.startswith(reverse(view))
for view in self.skip_views
)
if (
skip
or not settings.USE_SUBDOMAIN
or 'localhost' in request.get_host()
or 'testserver' in request.get_host()
):
log.debug('Not processing Proxito middleware')
return None

Expand Down
2 changes: 1 addition & 1 deletion readthedocs/rtd_tests/tests/test_footer.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ def test_highest_version_without_tags(self):
class TestFooterPerformance(TestCase):
# The expected number of queries for generating the footer
# This shouldn't increase unless we modify the footer API
EXPECTED_QUERIES = 15
EXPECTED_QUERIES = 12
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉


def setUp(self):
self.pip = get(
Expand Down