Skip to content

Commit 91a9979

Browse files
committed
Proxito: remove redirect for README.html files
Fully removal after deprecation and browndates. Reference: * #9993 * #11348 * https://about.readthedocs.com/blog/2024/05/readme-html-deprecated/
1 parent 00c256e commit 91a9979

File tree

4 files changed

+4
-141
lines changed

4 files changed

+4
-141
lines changed

readthedocs/projects/tasks/search.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,7 @@ def _create_imported_files_and_search_index(
203203

204204
# Create the imported file only if it's a top-level 404 file,
205205
# or if it's an index file. We don't need to keep track of all files.
206-
# TODO: delete README.html from this list after deprecation.
207-
tryfiles = ["index.html", "README.html"]
206+
tryfiles = ["index.html"]
208207
if relpath == "404.html" or filename in tryfiles:
209208
html_files_to_save.append(html_file)
210209

readthedocs/proxito/tests/test_full.py

-91
Original file line numberDiff line numberDiff line change
@@ -994,32 +994,6 @@ def test_versioned_no_slash(self):
994994
"/en/latest/",
995995
)
996996

997-
@mock.patch.object(BuildMediaFileSystemStorageTest, "open")
998-
def test_directory_indexes_readme_serving(self, storage_open):
999-
self.project.versions.update(active=True, built=True)
1000-
1001-
get(
1002-
HTMLFile,
1003-
project=self.project,
1004-
version=self.version,
1005-
path="readme-exists/README.html",
1006-
name="README.html",
1007-
)
1008-
1009-
# Confirm we've serving from storage for the `index-exists/index.html` file
1010-
response = self.client.get(
1011-
reverse(
1012-
"proxito_404_handler",
1013-
kwargs={"proxito_path": "/en/latest/readme-exists"},
1014-
),
1015-
headers={"host": "project.readthedocs.io"},
1016-
)
1017-
self.assertEqual(response.status_code, 302)
1018-
self.assertEqual(
1019-
response["location"],
1020-
"/en/latest/readme-exists/README.html",
1021-
)
1022-
1023997
def test_directory_indexes_get_args(self):
1024998
self.project.versions.update(active=True, built=True)
1025999
get(
@@ -1075,71 +1049,6 @@ def test_404_storage_serves_custom_404_sphinx(self, storage_open):
10751049
self.assertEqual(response.status_code, 404)
10761050
storage_open.assert_called_once_with("html/project/fancy-version/404.html")
10771051

1078-
def test_redirects_to_correct_index_ending_with_slash(self):
1079-
"""When the path ends with a slash, we try README.html as index."""
1080-
self.project.versions.update(active=True, built=True)
1081-
version = fixture.get(
1082-
Version,
1083-
slug="fancy-version",
1084-
privacy_level=constants.PUBLIC,
1085-
active=True,
1086-
built=True,
1087-
project=self.project,
1088-
documentation_type=SPHINX,
1089-
)
1090-
1091-
get(
1092-
HTMLFile,
1093-
project=self.project,
1094-
version=version,
1095-
path="not-found/README.html",
1096-
name="README.html",
1097-
)
1098-
response = self.client.get(
1099-
reverse(
1100-
"proxito_404_handler",
1101-
kwargs={"proxito_path": "/en/fancy-version/not-found/"},
1102-
),
1103-
headers={"host": "project.readthedocs.io"},
1104-
)
1105-
self.assertEqual(response.status_code, 302)
1106-
self.assertEqual(
1107-
response["location"], "/en/fancy-version/not-found/README.html"
1108-
)
1109-
1110-
def test_redirects_to_correct_index_ending_without_slash(self):
1111-
"""When the path doesn't end with a slash, we try both, index.html and README.html."""
1112-
self.project.versions.update(active=True, built=True)
1113-
version = fixture.get(
1114-
Version,
1115-
slug="fancy-version",
1116-
privacy_level=constants.PUBLIC,
1117-
active=True,
1118-
built=True,
1119-
project=self.project,
1120-
documentation_type=SPHINX,
1121-
)
1122-
1123-
get(
1124-
HTMLFile,
1125-
project=self.project,
1126-
version=version,
1127-
path="not-found/README.html",
1128-
name="README.html",
1129-
)
1130-
1131-
response = self.client.get(
1132-
reverse(
1133-
"proxito_404_handler",
1134-
kwargs={"proxito_path": "/en/fancy-version/not-found"},
1135-
),
1136-
headers={"host": "project.readthedocs.io"},
1137-
)
1138-
self.assertEqual(response.status_code, 302)
1139-
self.assertEqual(
1140-
response["location"], "/en/fancy-version/not-found/README.html"
1141-
)
1142-
11431052
@mock.patch.object(BuildMediaFileSystemStorageTest, "open")
11441053
def test_404_index_redirect_skips_not_built_versions(self, storage_open):
11451054
self.version.built = False

readthedocs/proxito/views/serve.py

+3-22
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
ServeRedirectMixin,
4242
StorageFileNotFound,
4343
)
44-
from readthedocs.proxito.views.utils import allow_readme_html_as_index
4544
from readthedocs.redirects.exceptions import InfiniteRedirectException
4645
from readthedocs.storage import build_media_storage
4746

@@ -389,7 +388,6 @@ def get(self, request, proxito_path):
389388
This does a couple of things:
390389
391390
* Handles directory indexing for URLs that don't end in a slash
392-
* Handles directory indexing for README.html (for now)
393391
* Check for user redirects
394392
* Record the broken link for analytics
395393
* Handles custom 404 serving
@@ -491,7 +489,7 @@ def get(self, request, proxito_path):
491489

492490
# Check and perform redirects on 404 handler for non-external domains only.
493491
# NOTE: This redirect check must be done after trying files like
494-
# ``index.html`` and ``README.html`` to emulate the behavior we had when
492+
# ``index.html`` to emulate the behavior we had when
495493
# serving directly from NGINX without passing through Python.
496494
if not unresolved_domain.is_from_external_domain:
497495
try:
@@ -642,23 +640,9 @@ def _get_index_file_redirect(self, request, project, version, filename, full_pat
642640
For example:
643641
644642
- /en/latest/foo -> /en/latest/foo/index.html
645-
- /en/latest/foo -> /en/latest/foo/README.html
646-
- /en/latest/foo/ -> /en/latest/foo/README.html
647643
"""
648644

649-
if allow_readme_html_as_index():
650-
tryfiles = ["index.html", "README.html"]
651-
# If the path ends with `/`, we already tried to serve
652-
# the `/index.html` file, so we only need to test for
653-
# the `/README.html` file.
654-
if full_path.endswith("/"):
655-
tryfiles = ["README.html"]
656-
else:
657-
tryfiles = ["index.html"]
658-
659-
tryfiles = [
660-
(filename.rstrip("/") + f"/{tryfile}").lstrip("/") for tryfile in tryfiles
661-
]
645+
tryfiles = ["index.html"]
662646
available_index_files = list(
663647
HTMLFile.objects.filter(version=version, path__in=tryfiles).values_list(
664648
"path", flat=True
@@ -672,10 +656,7 @@ def _get_index_file_redirect(self, request, project, version, filename, full_pat
672656
log.info("Redirecting to index file.", tryfile=tryfile)
673657
# Use urlparse so that we maintain GET args in our redirect
674658
parts = urlparse(full_path)
675-
if allow_readme_html_as_index() and tryfile.endswith("README.html"):
676-
new_path = parts.path.rstrip("/") + "/README.html"
677-
else:
678-
new_path = parts.path.rstrip("/") + "/"
659+
new_path = parts.path.rstrip("/") + "/"
679660

680661
# `full_path` doesn't include query params.`
681662
query = urlparse(request.get_full_path()).query

readthedocs/proxito/views/utils.py

-26
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
import datetime
2-
3-
import pytz
41
import structlog
5-
from django.conf import settings
62
from django.http import HttpResponse
73
from django.shortcuts import render
84

@@ -60,25 +56,3 @@ def proxito_404_page_handler(
6056
)
6157
r.status_code = http_status
6258
return r
63-
64-
65-
def allow_readme_html_as_index():
66-
if not settings.RTD_ENFORCE_BROWNOUTS_FOR_DEPRECATIONS:
67-
return True
68-
69-
tzinfo = pytz.timezone("America/Los_Angeles")
70-
now = datetime.datetime.now(tz=tzinfo)
71-
72-
# Brownout dates as published in https://about.readthedocs.com/blog/2024/05/readme-html-deprecated/
73-
# fmt: off
74-
return not any([
75-
# 12 hours browndate
76-
datetime.datetime(2024, 6, 10, 0, 0, 0, tzinfo=tzinfo) < now < datetime.datetime(2024, 6, 10, 12, 0, 0, tzinfo=tzinfo),
77-
# 24 hours browndate
78-
datetime.datetime(2024, 6, 17, 0, 0, 0, tzinfo=tzinfo) < now < datetime.datetime(2024, 6, 18, 0, 0, 0, tzinfo=tzinfo),
79-
# 48 hours browndate
80-
datetime.datetime(2024, 6, 24, 0, 0, 0, tzinfo=tzinfo) < now < datetime.datetime(2024, 6, 26, 0, 0, 0, tzinfo=tzinfo),
81-
# Deprecated after July 1st
82-
datetime.datetime(2024, 7, 1, 0, 0, 0, tzinfo=tzinfo) < now,
83-
])
84-
# fmt: on

0 commit comments

Comments
 (0)