diff --git a/readthedocs/proxito/middleware.py b/readthedocs/proxito/middleware.py index 4bad76c0766..a3988b4223c 100644 --- a/readthedocs/proxito/middleware.py +++ b/readthedocs/proxito/middleware.py @@ -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', '') diff --git a/readthedocs/proxito/tests/test_headers.py b/readthedocs/proxito/tests/test_headers.py index a2f8ec9cdda..b985cb1bd4c 100644 --- a/readthedocs/proxito/tests/test_headers.py +++ b/readthedocs/proxito/tests/test_headers.py @@ -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) diff --git a/readthedocs/proxito/views/utils.py b/readthedocs/proxito/views/utils.py index 378e47c76d3..1300c250d7f 100644 --- a/readthedocs/proxito/views/utils.py +++ b/readthedocs/proxito/views/utils.py @@ -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