Skip to content

Commit 00bcd15

Browse files
committed
Addons: add X-RTD-Load-Addons-When-Embedded HTTP header
Add an extra HTTP header to decide whether or not force the injection of addons when the page is embedded (eg. iframe). By default, we are not loading addons if embedded. Required by readthedocs/addons#415 Closes readthedocs/addons#412
1 parent 404d82a commit 00bcd15

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

readthedocs/projects/models.py

+4
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,10 @@ class AddonsConfig(TimeStampedModel):
167167
help_text="Enable/Disable all the addons on this project",
168168
)
169169

170+
# Whether or not load addons library when the requested page is embedded (e.g. inside an iframe)
171+
# https://github.com/readthedocs/addons/pull/415
172+
load_when_embedded = models.BooleanField(default=False)
173+
170174
# Analytics
171175

172176
# NOTE: we keep analytics disabled by default to save resources.

readthedocs/proxito/middleware.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
unresolver,
3131
)
3232
from readthedocs.core.utils import get_cache_tag
33-
from readthedocs.projects.models import Project
33+
from readthedocs.projects.models import AddonsConfig
3434
from readthedocs.proxito.cache import add_cache_tags, cache_response, private_response
3535
from readthedocs.proxito.redirects import redirect_to_https
3636

@@ -283,12 +283,13 @@ def add_hosting_integrations_headers(self, request, response):
283283
project_slug = getattr(request, "path_project_slug", "")
284284

285285
if project_slug:
286-
addons = Project.objects.filter(
287-
slug=project_slug, addons__enabled=True
288-
).exists()
286+
addons = AddonsConfig.objects.filter(project__slug=project_slug).first()
289287

290288
if addons:
291-
response["X-RTD-Force-Addons"] = "true"
289+
if addons.enabled:
290+
response["X-RTD-Force-Addons"] = "true"
291+
if addons.load_when_embedded:
292+
response["X-RTD-Load-Addons-When-Embedded"] = "true"
292293

293294
def add_cors_headers(self, request, response):
294295
"""

0 commit comments

Comments
 (0)