Skip to content

Commit

Permalink
Merge pull request #6606 from readthedocs/humitos/proxito-infinite-re…
Browse files Browse the repository at this point in the history
…direct

Avoid infinite redirect on El Proxito on 404
  • Loading branch information
ericholscher authored Jan 29, 2020
2 parents 1dd5c7a + 5e4eb75 commit 9cb638d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
25 changes: 25 additions & 0 deletions readthedocs/proxito/tests/test_old_redirects.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import django_dynamic_fixture as fixture
import pytest
from django.urls import reverse
from django.test.utils import override_settings

from readthedocs.builds.models import Version
Expand Down Expand Up @@ -516,6 +517,30 @@ def test_redirect_root_with_301_status(self):
'http://project.dev.readthedocs.io/en/latest/faq.html',
)

def test_not_found_page_without_trailing_slash(self):
# https://github.com/readthedocs/readthedocs.org/issues/4673
fixture.get(
Redirect,
project=self.project,
redirect_type='prefix',
from_url='/',
)

# Use ``proxito_404_handler`` URL here to emulate the internal redirect
# that happens on NGINX (URL path will be
# http://project.dev.readthedocs.io/_proxito_404_/en/latest/section/file-not-found
# when the view receives it)
r = self.client.get(
reverse(
'proxito_404_handler',
kwargs={
'proxito_path': '/en/latest/section/file-not-found',
}),
HTTP_HOST='project.dev.readthedocs.io',
)
# Avoid infinite redirect
self.assertEqual(r.status_code, 404)


# FIXME: these tests are valid, but the problem I'm facing is that the request
# is received as ``GET '//my.host/path/'`` (note that we are loosing the http:)
Expand Down
4 changes: 2 additions & 2 deletions readthedocs/proxito/views/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,12 @@ def get_redirect_response(self, request, redirect_path, proxito_path, http_statu
new_path = request.build_absolute_uri(new_path)
log.info(
'Redirecting: from=%s to=%s http_status=%s',
request.build_absolute_uri(),
request.build_absolute_uri(proxito_path),
new_path,
http_status,
)

if request.build_absolute_uri() == new_path:
if request.build_absolute_uri(proxito_path) == new_path:
# 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',
Expand Down

0 comments on commit 9cb638d

Please sign in to comment.