Catch inifinite canonical redirects
@@ -187,7 +187,8 @@ class ServeRedirectMixin:
This is normally used HTTP -> HTTPS redirects or redirects to/from custom domains.
"""
- urlparse_result = urlparse(request.get_full_path())
+ full_path = request.get_full_path()
+ urlparse_result = urlparse()
to = resolve(
project=final_project,
version_slug=version_slug,
@@ -195,6 +196,15 @@ class ServeRedirectMixin:
query_params=urlparse_result.query,
external=hasattr(request, 'external_domain'),
)
+
+ if full_path == to:
+ # check that we do have a response and avoid infinite redirect
+ log.warning(
+ 'Infinite Redirect: FROM URL is the same than TO URL. url=%s',
+ to,
+ )
+ raise InfiniteRedirectException()
+
log.info('Canonical Redirect: host=%s, from=%s, to=%s', request.get_host(), filename, to)
resp = HttpResponseRedirect(to)
resp['X-RTD-Redirect'] = getattr(request, 'canonicalize', 'unknown')
