-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Use correct Cache-Tag (CDN) and X-RTD-Project header on subprojects #7593
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -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') | ||||||||||||||
Comment on lines
+48
to
+51
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not related to this PR, but I wanted to make a note here, tho. Maybe a TODO where we set this header is better? readthedocs.org/readthedocs/proxito/middleware.py Lines 141 to 146 in a81d82e
This header is wrong to all the subprojects when they are accessed via the domain of their parent's, eg. |
||||||||||||||
|
||||||||||||||
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) | ||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we not need to use
host_project_slug
sometimes as well? It seems like this is breaking existing logic, unlesspath_project_slug
is getting set other places?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a fallback, you mean? In case that
path_project_slug
is not available? Why it would not be available?What existing logic do you think it's breaking? If you have an example on mind I can try to write a test case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are using the same logic for
version_path_project
that follows this line. It's used here and set in_get_project_data_from_request
(readthedocs.org/readthedocs/proxito/views/utils.py
Line 96 in a81d82e
readthedocs.org/readthedocs/proxito/views/serve.py
Lines 72 to 79 in a81d82e
The
host_project_slug
is returned bymap_host_project_slug
which is accurate,readthedocs.org/readthedocs/proxito/middleware.py
Line 159 in a81d82e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha, are other uses of
host_project_slug
unaffected by this issue? It just seems bad to have 2 different variables for the project_slug, where we use them in different places.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, if I'm understand correctly this they are different things:
host_project_slug
is the project slug that we infer from the host/domain's URL.readthedocs.io
path_project_slug
is the project slug that we can infer from the path's URL mainlyfinal_project
(maybe it's better to call itfinal_project_slug
?)_get_project_data_from_request
which is called from inside theServeDocs
view in Proxito as the first step of the request after all the middlewaresIt seems that both are required. We use
host_project_slug
as first step trying to get theProject
object (map_project_slug
decorator). Then, inside the_get_project_data_from_request
we usehost_project_slug
to check single project, translation and subproject and set thepath_project_slug
which in those cases could be different thanhost_project_slug
.Grepping the code I didn't find anything that clearly needs to be adapted. Maybe there is something deeper that I'm not seeing, tho
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes sense to me. We should probably document all these variables (as you have done above) in the code/docs, so we don't get confused in the future.