Skip to content

Commit

Permalink
Restore urlconf on middleware on process_response
Browse files Browse the repository at this point in the history
  • Loading branch information
stsewd committed Apr 27, 2018
1 parent c7b5c07 commit c69eedb
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions readthedocs/core/middleware.py
Expand Up @@ -9,6 +9,7 @@
from django.contrib.sessions.middleware import SessionMiddleware
from django.core.cache import cache
from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned
from django.core.urlresolvers import set_urlconf, get_urlconf
from django.http import Http404, HttpResponseBadRequest

from readthedocs.core.utils import cname_to_slug
Expand Down Expand Up @@ -53,6 +54,9 @@ def process_request(self, request):
'PRODUCTION_DOMAIN',
'readthedocs.org'
)
# Django sets the urlconf for the current thread
# so we need to set this again later.
self.current_urlconf = get_urlconf()

if public_domain is None:
public_domain = production_domain
Expand Down Expand Up @@ -130,6 +134,12 @@ def process_request(self, request):
# Normal request.
return None

def process_response(self, request, response):
# Reset URLconf for this thread
# to the original one.
set_urlconf(self.current_urlconf)
return response


class SingleVersionMiddleware(object):

Expand Down

0 comments on commit c69eedb

Please sign in to comment.