Skip to content

Commit

Permalink
Proxito: inject hosting integration header for build.commands (#10219)
Browse files Browse the repository at this point in the history
* Proxito: inject hosting integration header for `build.commands`

Versions using `build.commands` will start using the new Read the Docs
JavaScript client.

This is still under beta testing, but we want to move forward slowly and start
exposing these features to projects that don't have access currently.

Related readthedocs/addons#26

* Proxito: check if the version exists first
  • Loading branch information
humitos authored Apr 17, 2023
1 parent d8774cf commit 27215d2
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions readthedocs/proxito/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,11 +281,22 @@ def process_request(self, request): # noqa

def add_hosting_integrations_headers(self, request, response):
project_slug = getattr(request, "path_project_slug", "")
version_slug = getattr(request, "path_version_slug", "")

if project_slug:
project = Project.objects.get(slug=project_slug)
if project.has_feature(Feature.HOSTING_INTEGRATIONS):
response["X-RTD-Hosting-Integrations"] = "true"

# Inject the new integrations for versions using `build.commands`
version = project.versions.filter(slug=version_slug).first()
if (
version
and version.config
and version.config.get("build", {}).get("commands", {}) != []
):
response["X-RTD-Hosting-Integrations"] = "true"

def process_response(self, request, response): # noqa
self.add_proxito_headers(request, response)
self.add_cache_headers(request, response)
Expand Down

0 comments on commit 27215d2

Please sign in to comment.