Skip to content

Commit a5af4e5

Browse files
authored
Addons: move the HTTP header to a GET parameter (#10753)
Move `X-RTD-Hosting-Integration-Version` header to `api-version` querystring parameter. This has some benefits: - make links to this URL clickable (there is no need to use a browser extension to send a specific header in the request) - easier to cache using the default strategy supported by CF Related #10536
1 parent 283fd10 commit a5af4e5

File tree

3 files changed

+19
-17
lines changed

3 files changed

+19
-17
lines changed
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"error": "The version specified in 'X-RTD-Hosting-Integrations-Version' is currently not supported"
2+
"error": "The version specified in 'api-version' is currently not supported"
33
}

readthedocs/proxito/tests/test_hosting.py

+12-6
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,13 @@ def _normalize_datetime_fields(self, obj):
8080
def test_get_config_v0(self):
8181
r = self.client.get(
8282
reverse("proxito_readthedocs_docs_addons"),
83-
{"url": "https://project.dev.readthedocs.io/en/latest/"},
83+
{
84+
"url": "https://project.dev.readthedocs.io/en/latest/",
85+
"api-version": "0.1.0",
86+
},
8487
secure=True,
8588
headers={
8689
"host": "project.dev.readthedocs.io",
87-
"x-rtd-hosting-integrations-version": "0.1.0",
8890
},
8991
)
9092
assert r.status_code == 200
@@ -95,11 +97,13 @@ def test_get_config_v0(self):
9597
def test_get_config_v1(self):
9698
r = self.client.get(
9799
reverse("proxito_readthedocs_docs_addons"),
98-
{"url": "https://project.dev.readthedocs.io/en/latest/"},
100+
{
101+
"url": "https://project.dev.readthedocs.io/en/latest/",
102+
"api-version": "1.0.0",
103+
},
99104
secure=True,
100105
headers={
101106
"host": "project.dev.readthedocs.io",
102-
"x-rtd-hosting-integrations-version": "1.0.0",
103107
},
104108
)
105109
assert r.status_code == 200
@@ -108,11 +112,13 @@ def test_get_config_v1(self):
108112
def test_get_config_unsupported_version(self):
109113
r = self.client.get(
110114
reverse("proxito_readthedocs_docs_addons"),
111-
{"url": "https://project.dev.readthedocs.io/en/latest/"},
115+
{
116+
"url": "https://project.dev.readthedocs.io/en/latest/",
117+
"api-version": "2.0.0",
118+
},
112119
secure=True,
113120
headers={
114121
"host": "project.dev.readthedocs.io",
115-
"x-rtd-hosting-integrations-version": "2.0.0",
116122
},
117123
)
118124
assert r.status_code == 400

readthedocs/proxito/views/hosting.py

+6-10
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,9 @@
3131

3232
class ClientError(Exception):
3333
VERSION_NOT_CURRENTLY_SUPPORTED = (
34-
"The version specified in 'X-RTD-Hosting-Integrations-Version'"
35-
" is currently not supported"
36-
)
37-
VERSION_INVALID = "'X-RTD-Hosting-Integrations-Version' header version is invalid"
38-
VERSION_HEADER_MISSING = (
39-
"'X-RTD-Hosting-Integrations-Version' header attribute is required"
34+
"The version specified in 'api-version' is currently not supported"
4035
)
36+
VERSION_INVALID = "The version specifified in 'api-version' is invalid"
4137

4238

4339
class BaseReadTheDocsConfigJson(CDNCacheTagsMixin, APIView):
@@ -52,6 +48,8 @@ class BaseReadTheDocsConfigJson(CDNCacheTagsMixin, APIView):
5248
5349
url (required): absolute URL from where the request is performed
5450
(e.g. ``window.location.href``)
51+
52+
api-version (required): API JSON structure version (e.g. ``0``, ``1``, ``2``).
5553
"""
5654

5755
http_method_names = ["get"]
@@ -112,12 +110,10 @@ def get(self, request, format=None):
112110
status=400,
113111
)
114112

115-
addons_version = request.headers.get("X-RTD-Hosting-Integrations-Version")
113+
addons_version = request.GET.get("api-version")
116114
if not addons_version:
117115
return JsonResponse(
118-
{
119-
"error": ClientError.VERSION_HEADER_MISSING,
120-
},
116+
{"error": "'api-version' GET attribute is required"},
121117
status=400,
122118
)
123119
try:

0 commit comments

Comments
 (0)