-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Add proxito headers to redirect responses #7007
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f4e57b5
Add proxito headers to redirect responses
ericholscher 1a068ef
Include Method logic
ericholscher 5fa4014
Merge branch 'master' into expand-proxito-headers
ericholscher 520e739
Be more defensive in how we get headers
ericholscher 244bf61
Move header tests to their own file and expand them
ericholscher 35fb1f5
Merge branch 'master' of github.com:readthedocs/readthedocs.org into …
ericholscher 0709170
Remove mixin and add header logic to middleware
ericholscher File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import pytest | ||
from django.test import override_settings | ||
|
||
import django_dynamic_fixture as fixture | ||
|
||
from readthedocs.projects.models import Domain | ||
from .base import BaseDocServing | ||
|
||
|
||
@override_settings( | ||
PUBLIC_DOMAIN='dev.readthedocs.io', | ||
PUBLIC_DOMAIN_USES_HTTPS=True, | ||
) | ||
class ProxitoHeaderTests(BaseDocServing): | ||
|
||
def test_redirect_headers(self): | ||
r = self.client.get('', HTTP_HOST='project.dev.readthedocs.io') | ||
self.assertEqual(r.status_code, 302) | ||
self.assertEqual(r['X-RTD-Redirect'], 'system') | ||
self.assertEqual( | ||
r['Location'], 'https://project.dev.readthedocs.io/en/latest/', | ||
) | ||
self.assertEqual(r['Cache-Tag'], 'project') | ||
self.assertEqual(r['X-RTD-Project'], 'project') | ||
self.assertEqual(r['X-RTD-Project-Method'], 'subdomain') | ||
self.assertEqual(r['X-RTD-Domain'], 'project.dev.readthedocs.io') | ||
self.assertIsNone(r.get('X-RTD-Version')) | ||
self.assertIsNone(r.get('X-RTD-Path')) | ||
|
||
def test_serve_headers(self): | ||
r = self.client.get('/en/latest/', HTTP_HOST='project.dev.readthedocs.io') | ||
self.assertEqual(r.status_code, 200) | ||
self.assertEqual(r['Cache-Tag'], 'project,project-latest') | ||
self.assertEqual(r['X-RTD-Domain'], 'project.dev.readthedocs.io') | ||
self.assertEqual(r['X-RTD-Project'], 'project') | ||
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/project/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) | ||
self.assertEqual(r['Cache-Tag'], 'project') | ||
self.assertEqual(r['X-RTD-Domain'], 'project.dev.readthedocs.io') | ||
self.assertEqual(r['X-RTD-Project'], 'project') | ||
self.assertEqual(r['X-RTD-Project-Method'], 'subdomain') | ||
self.assertEqual(r['X-RTD-version-Method'], 'path') | ||
self.assertIsNone(r.get('X-RTD-Version')) | ||
self.assertIsNone(r.get('X-RTD-Path')) | ||
|
||
def test_custom_domain_headers(self): | ||
hostname = 'docs.random.com' | ||
self.domain = fixture.get( | ||
Domain, | ||
project=self.project, | ||
domain=hostname, | ||
) | ||
r = self.client.get("/en/latest/", HTTP_HOST=hostname) | ||
self.assertEqual(r.status_code, 200) | ||
self.assertEqual(r['Cache-Tag'], 'project,project-latest') | ||
self.assertEqual(r['X-RTD-Domain'], self.domain.domain) | ||
self.assertEqual(r['X-RTD-Project'], self.project.slug) | ||
self.assertEqual(r['X-RTD-Project-Method'], 'cname') | ||
self.assertEqual(r['X-RTD-Version'], 'latest') | ||
self.assertEqual(r['X-RTD-version-Method'], 'path') | ||
self.assertEqual(r['X-RTD-Path'], '/proxito/media/html/project/latest/index.html') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Rather than adding a single-use mixin in a separate file, couldn't this method just be a method on this class?
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.
Yea, I thought we'd have to use it more places, but we haven't yet, so that seems fine. 👍