Skip to content

Commit fad501f

Browse files
committed
Proxito: browndate for redirecting / to README.html
Related #9993
1 parent 266ea25 commit fad501f

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

readthedocs/proxito/views/serve.py

+11-6
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
ServeRedirectMixin,
4242
StorageFileNotFound,
4343
)
44+
from readthedocs.proxito.views.utils import allow_readme_html_at_root_url
4445
from readthedocs.redirects.exceptions import InfiniteRedirectException
4546
from readthedocs.storage import build_media_storage
4647

@@ -641,12 +642,16 @@ def _get_index_file_redirect(self, request, project, version, filename, full_pat
641642
- /en/latest/foo -> /en/latest/foo/README.html
642643
- /en/latest/foo/ -> /en/latest/foo/README.html
643644
"""
644-
tryfiles = ["index.html", "README.html"]
645-
# If the path ends with `/`, we already tried to serve
646-
# the `/index.html` file, so we only need to test for
647-
# the `/README.html` file.
648-
if full_path.endswith("/"):
649-
tryfiles = ["README.html"]
645+
646+
if allow_readme_html_at_root_url():
647+
tryfiles = ["index.html", "README.html"]
648+
# If the path ends with `/`, we already tried to serve
649+
# the `/index.html` file, so we only need to test for
650+
# the `/README.html` file.
651+
if full_path.endswith("/"):
652+
tryfiles = ["README.html"]
653+
else:
654+
tryfiles = ["index.html"]
650655

651656
tryfiles = [
652657
(filename.rstrip("/") + f"/{tryfile}").lstrip("/") for tryfile in tryfiles

readthedocs/proxito/views/utils.py

+23
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1+
import datetime
2+
3+
import pytz
14
import structlog
5+
from django.conf import settings
26
from django.http import HttpResponse
37
from django.shortcuts import render
48

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

0 commit comments

Comments
 (0)