Skip to content
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

Proxito middleware: reset to original urlconf after request #7137

Merged
merged 5 commits into from May 28, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions readthedocs/proxito/middleware.py
Expand Up @@ -10,6 +10,7 @@

from django.conf import settings
from django.shortcuts import render
from django.urls.base import set_urlconf
from django.utils.deprecation import MiddlewareMixin

from readthedocs.projects.models import Domain, Project
Expand Down Expand Up @@ -199,6 +200,10 @@ def process_response(self, request, response): # noqa
* For custom domains, check the HSTS values on the Domain object.
The domain object should be saved already in request.domain.
"""
# Reset URLconf for this thread
# to the original one.
Comment on lines +203 to +204
Copy link
Member

Choose a reason for hiding this comment

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

why not put the comment in just one line? 😄

Copy link
Member Author

Choose a reason for hiding this comment

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

I just like short lines to have more space in my monitor 🤷‍♂️

set_urlconf(None)

host = request.get_host().lower().split(':')[0]
public_domain = settings.PUBLIC_DOMAIN.lower().split(':')[0]

Expand Down
2 changes: 0 additions & 2 deletions readthedocs/proxito/tests/test_middleware.py
Expand Up @@ -242,8 +242,6 @@ def setUp(self):
sys.modules['fake_urlconf'] = self.pip.proxito_urlconf
set_urlconf('fake_urlconf')

# TODO: Figure out why this is failing in travis
@pytest.mark.xfail(strict=True)
def test_middleware_urlconf_subproject(self):
resp = self.client.get('/subpath/subproject/testing/en/foodex.html', HTTP_HOST=self.domain)
self.assertEqual(resp.status_code, 200)
Expand Down