Skip to content

Commit

Permalink
Merge pull request readthedocs#7593 from readthedocs/humitos/cache-ta…
Browse files Browse the repository at this point in the history
…g-subprojects

Use correct Cache-Tag (CDN) and X-RTD-Project header on subprojects
  • Loading branch information
ericholscher authored Oct 26, 2020
2 parents 7a0ac17 + 064bacb commit 4cf4aca
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion readthedocs/proxito/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class ProxitoMiddleware(MiddlewareMixin):
def add_proxito_headers(self, request, response):
"""Add debugging headers to proxito responses."""

project_slug = getattr(request, 'host_project_slug', '')
project_slug = getattr(request, 'path_project_slug', '')
version_slug = getattr(request, 'path_version_slug', '')
path = getattr(response, 'proxito_path', '')

Expand Down
16 changes: 16 additions & 0 deletions readthedocs/proxito/tests/test_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,22 @@ def test_serve_headers(self):
self.assertEqual(r['X-RTD-version-Method'], 'path')
self.assertEqual(r['X-RTD-Path'], '/proxito/media/html/project/latest/index.html')

def test_subproject_serve_headers(self):
r = self.client.get('/projects/subproject/en/latest/', HTTP_HOST='project.dev.readthedocs.io')
self.assertEqual(r.status_code, 200)
self.assertEqual(r['Cache-Tag'], 'subproject,subproject-latest')
self.assertEqual(r['X-RTD-Domain'], 'project.dev.readthedocs.io')
self.assertEqual(r['X-RTD-Project'], 'subproject')

# I think it's not accurate saying that it's `subdomain` the method
# that we use to get the project slug here, since it was in fact the
# URL's path but we don't have that feature built
self.assertEqual(r['X-RTD-Project-Method'], 'subdomain')

self.assertEqual(r['X-RTD-Version'], 'latest')
self.assertEqual(r['X-RTD-version-Method'], 'path')
self.assertEqual(r['X-RTD-Path'], '/proxito/media/html/subproject/latest/index.html')

def test_404_headers(self):
r = self.client.get('/foo/bar.html', HTTP_HOST='project.dev.readthedocs.io')
self.assertEqual(r.status_code, 404)
Expand Down
3 changes: 2 additions & 1 deletion readthedocs/proxito/views/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ def _get_project_data_from_request(
# * Subproject
# * Translations

# Set the version slug on the request so we can log it in middleware
# Set the project and version slug on the request so we can log it in middleware
request.path_project_slug = final_project.slug
request.path_version_slug = version_slug

return final_project, lang_slug, version_slug, filename

0 comments on commit 4cf4aca

Please sign in to comment.