Repository: readthedocs/readthedocs.org
Issue: .inv files are over-cached?

## Details

* Read the Docs project URL: https://edx.readthedocs.io/projects/edx-guide-for-students/en/nedbat-fix-learner-links/objects.inv
* Build URL (if applicable):
* Read the Docs username (if applicable): edx

## Expected Result

We have a multi-book docset, with references between the books.  We use an intersphinx_mapping to resolve these references:
```
intersphinx_mapping = {
    'opencoursestaff' : ('https://edx.readthedocs.io/projects/open-edx-building-and-running-a-course/en/latest/', None),
    'data' : ('https://edx.readthedocs.io/projects/devdata/en/latest/', None),
    'partnercoursestaff': ('https://edx.readthedocs.io/projects/edx-partner-course-staff/en/latest/', None),
    'insights' : ('https://edx.readthedocs.io/projects/edx-insights/en/latest/', None),
    'xblockapi' : ('https://edx.readthedocs.io/projects/xblock/en/latest/', None),
    'xblocktutorial' : ('https://edx.readthedocs.io/projects/xblock-tutorial/en/latest/', None),
    'installation' : ('https://edx.readthedocs.io/projects/edx-installing-configuring-and-running/en/latest/', None),
    'olx' : ('https://edx.readthedocs.io/projects/edx-open-learning-xml/en/latest/', None),
    'learners' : ('https://edx.readthedocs.io/projects/edx-guide-for-students/en/nedbat-fix-learner-links/', None),
    'openlearners' : ('https://edx.readthedocs.io/projects/open-edx-learner-guide/en/latest/', None),
    'opendevelopers' : ('https://edx.readthedocs.io/projects/edx-developer-guide/en/latest/', None),
    'opendataapi' : ('https://edx.readthedocs.io/projects/edx-data-analytics-api/en/latest/', None),
    'openreleasenotes' : ('https://edx.readthedocs.io/projects/open-edx-release-notes/en/latest/', None),
    'partnerreleasenotes': ('https://edx.readthedocs.io/projects/edx-release-notes/en/latest/', None),
    '2014releasenotes' : ('https://edx.readthedocs.io/projects/edx-2013-2014-release-notes/en/latest/', None),
    'retirement' : ('https://user-retirement-guide.readthedocs.io/en/latest/', None),
}
```
(The "learners" reference is to a particular branch so that my new references will be found as I work on the pull request.)

When I update one book, I find the next local build still can't resolve the new references.  Using wget to pull the .inv file, it seems that the old content is still being served, but if I add a nonsense query parameter, I get the new content:
```
$ wget -q -O - https://edx.readthedocs.io/projects/edx-guide-for-students/en/nedbat-fix-learner-links/objects.inv | wc -c
    2923
$ wget -q -O - https://edx.readthedocs.io/projects/edx-guide-for-students/en/nedbat-fix-learner-links/objects.inv\\?bust | wc -c
    3821
$ wget -q -O - https://edx.readthedocs.io/projects/edx-guide-for-students/en/nedbat-fix-learner-links/objects.inv | wc -c
    2923
```

I saw the problem yesterday, and then new references seemed to resolve this morning, so it seems that waiting long enough will bring the new content, as if a cache expires.  I don't know how long that time is.

Changed files:
readthedocs/proxito/views/utils.py, readthedocs/proxito/middleware.py, readthedocs/proxito/tests/test_headers.py

diff --git a/readthedocs/proxito/middleware.py b/readthedocs/proxito/middleware.py
index 4bad76c07..a3988b422 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 a2f8ec9cd..b985cb1bd 100644
--- a/readthedocs/proxito/tests/test_headers.py
+++ b/readthedocs/proxito/tests/test_headers.py
@@ -38,6 +38,22 @@ class ProxitoHeaderTests(BaseDocServing):
         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 378e47c76..1300c250d 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