Skip to content

Commit

Permalink
Addons: remove old X-RTD-Hosting-Integrations HTTP header (#11653)
Browse files Browse the repository at this point in the history
Remove old HTTP header used by `build.commands`. All the projects are
using the new addons now, so this header is not used anymore.

---------

Co-authored-by: Eric Holscher <[email protected]>
  • Loading branch information
humitos and ericholscher authored Nov 12, 2024
1 parent 7bceb65 commit b207d2e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 57 deletions.
2 changes: 0 additions & 2 deletions dockerfiles/nginx/proxito.conf.template
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,6 @@ server {

# This header allows us to decide whether or not inject the script at CloudFlare level
# Now, I'm injecting it in all the NGINX responses because `sub_filter` is not allowed inside an `if` statement.
set $rtd_hosting_integrations $upstream_http_x_rtd_hosting_integrations;
add_header X-RTD-Hosting-Integrations $rtd_hosting_integrations always;
set $rtd_force_addons $upstream_http_x_rtd_force_addons;
add_header X-RTD-Force-Addons $rtd_force_addons always;
}
Expand Down
62 changes: 7 additions & 55 deletions readthedocs/proxito/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
Additional processing is done to get the project from the URL in the ``views.py`` as well.
"""
import datetime
import re
from urllib.parse import urlparse

import pytz
import structlog
from corsheaders.middleware import (
ACCESS_CONTROL_ALLOW_METHODS,
Expand All @@ -19,12 +17,10 @@
from django.core.exceptions import SuspiciousOperation
from django.shortcuts import redirect
from django.urls import reverse
from django.utils import timezone
from django.utils.deprecation import MiddlewareMixin
from django.utils.encoding import iri_to_uri
from django.utils.html import escape

from readthedocs.builds.models import Version
from readthedocs.core.unresolver import (
InvalidCustomDomainError,
InvalidExternalDomainError,
Expand All @@ -34,7 +30,7 @@
unresolver,
)
from readthedocs.core.utils import get_cache_tag
from readthedocs.projects.models import Feature, Project
from readthedocs.projects.models import Project
from readthedocs.proxito.cache import add_cache_tags, cache_response, private_response
from readthedocs.proxito.redirects import redirect_to_https

Expand Down Expand Up @@ -278,65 +274,21 @@ def add_hosting_integrations_headers(self, request, response):
the old flyout integration based on HTTP headers.
This method uses two different headers for these purposes:
- ``X-RTD-Hosting-Integrations``: inject ``readthedocs-addons.js`` to enable addons.
Enabled by default on projects using ``build.commands``.
- ``X-RTD-Force-Addons``: inject ``readthedocs-addons.js``
and remove old flyout integration (via ``readthedocs-doc-embed.js``).
Enabled only on projects that opted-in via the admin settings.
Enabled on all projects by default starting on Oct 7, 2024.
Note these headers will not be required anymore eventually
since all the project will be using the new addons once we fully roll them out.
"""
addons = False
project_slug = getattr(request, "path_project_slug", "")
version_slug = getattr(request, "path_version_slug", "")

if project_slug:
tzinfo = pytz.timezone("America/Los_Angeles")
addons_enabled_by_default = timezone.now() > datetime.datetime(
2024,
10,
7,
0,
0,
0,
tzinfo=tzinfo,
)
if addons_enabled_by_default:
addons = Project.objects.filter(
slug=project_slug, addons__enabled=True
).exists()
addons = Project.objects.filter(
slug=project_slug, addons__enabled=True
).exists()

if addons:
response["X-RTD-Force-Addons"] = "true"
return

else:
# TODO: remove "else" code once DISABLE_SPHINX_MANIPULATION and addons becomes the default
# https://about.readthedocs.com/blog/2024/07/addons-by-default/
disable_sphinx_manipulation_enabled = Feature.objects.filter(
feature_id=Feature.DISABLE_SPHINX_MANIPULATION,
projects__slug=Project.objects.filter(slug=project_slug).first(),
).exists()

force_addons = Project.objects.filter(
slug=project_slug,
addons__enabled=True,
).exists()

if force_addons or disable_sphinx_manipulation_enabled:
response["X-RTD-Force-Addons"] = "true"
return

if version_slug:
addons = Version.objects.filter(
project__slug=project_slug,
slug=version_slug,
addons=True,
).exists()

if addons:
response["X-RTD-Hosting-Integrations"] = "true"
if addons:
response["X-RTD-Force-Addons"] = "true"

def add_cors_headers(self, request, response):
"""
Expand Down

0 comments on commit b207d2e

Please sign in to comment.