Skip to content

Addons: move the HTTP header to a GET parameter #10753

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

Merged
merged 1 commit into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion readthedocs/proxito/tests/responses/v2.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"error": "The version specified in 'X-RTD-Hosting-Integrations-Version' is currently not supported"
"error": "The version specified in 'api-version' is currently not supported"
}
18 changes: 12 additions & 6 deletions readthedocs/proxito/tests/test_hosting.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,13 @@ def _normalize_datetime_fields(self, obj):
def test_get_config_v0(self):
r = self.client.get(
reverse("proxito_readthedocs_docs_addons"),
{"url": "https://project.dev.readthedocs.io/en/latest/"},
{
"url": "https://project.dev.readthedocs.io/en/latest/",
"api-version": "0.1.0",
},
secure=True,
headers={
"host": "project.dev.readthedocs.io",
"x-rtd-hosting-integrations-version": "0.1.0",
},
)
assert r.status_code == 200
Expand All @@ -95,11 +97,13 @@ def test_get_config_v0(self):
def test_get_config_v1(self):
r = self.client.get(
reverse("proxito_readthedocs_docs_addons"),
{"url": "https://project.dev.readthedocs.io/en/latest/"},
{
"url": "https://project.dev.readthedocs.io/en/latest/",
"api-version": "1.0.0",
},
secure=True,
headers={
"host": "project.dev.readthedocs.io",
"x-rtd-hosting-integrations-version": "1.0.0",
},
)
assert r.status_code == 200
Expand All @@ -108,11 +112,13 @@ def test_get_config_v1(self):
def test_get_config_unsupported_version(self):
r = self.client.get(
reverse("proxito_readthedocs_docs_addons"),
{"url": "https://project.dev.readthedocs.io/en/latest/"},
{
"url": "https://project.dev.readthedocs.io/en/latest/",
"api-version": "2.0.0",
},
secure=True,
headers={
"host": "project.dev.readthedocs.io",
"x-rtd-hosting-integrations-version": "2.0.0",
},
)
assert r.status_code == 400
Expand Down
16 changes: 6 additions & 10 deletions readthedocs/proxito/views/hosting.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,9 @@

class ClientError(Exception):
VERSION_NOT_CURRENTLY_SUPPORTED = (
"The version specified in 'X-RTD-Hosting-Integrations-Version'"
" is currently not supported"
)
VERSION_INVALID = "'X-RTD-Hosting-Integrations-Version' header version is invalid"
VERSION_HEADER_MISSING = (
"'X-RTD-Hosting-Integrations-Version' header attribute is required"
"The version specified in 'api-version' is currently not supported"
)
VERSION_INVALID = "The version specifified in 'api-version' is invalid"


class BaseReadTheDocsConfigJson(CDNCacheTagsMixin, APIView):
Expand All @@ -52,6 +48,8 @@ class BaseReadTheDocsConfigJson(CDNCacheTagsMixin, APIView):

url (required): absolute URL from where the request is performed
(e.g. ``window.location.href``)

api-version (required): API JSON structure version (e.g. ``0``, ``1``, ``2``).
"""

http_method_names = ["get"]
Expand Down Expand Up @@ -112,12 +110,10 @@ def get(self, request, format=None):
status=400,
)

addons_version = request.headers.get("X-RTD-Hosting-Integrations-Version")
addons_version = request.GET.get("api-version")
if not addons_version:
return JsonResponse(
{
"error": ClientError.VERSION_HEADER_MISSING,
},
{"error": "'api-version' GET attribute is required"},
status=400,
)
try:
Expand Down