23
23
24
24
class ClientError (Exception ):
25
25
VERSION_NOT_CURRENTLY_SUPPORTED = (
26
- "The version specified in 'X-RTD-Hosting-Integrations-Version'"
27
- " is currently not supported"
26
+ "The version specified in 'X-RTD-Hosting-Integrations-Version' "
27
+ "or 'X-RTD-Hosting-Integrations-API-Version' "
28
+ "is currently not supported"
29
+ )
30
+ VERSION_INVALID = (
31
+ "'X-RTD-Hosting-Integrations-Version' or 'X-RTD-Hosting-Integrations-API-Version' "
32
+ "header version is invalid"
28
33
)
29
- VERSION_INVALID = "'X-RTD-Hosting-Integrations-Version' header version is invalid"
30
34
VERSION_HEADER_MISSING = (
31
35
"'X-RTD-Hosting-Integrations-Version' header attribute is required"
32
36
)
@@ -44,6 +48,16 @@ class ReadTheDocsConfigJson(CDNCacheControlMixin, View):
44
48
45
49
url (required): absolute URL from where the request is performed
46
50
(e.g. ``window.location.href``)
51
+
52
+ Headers:
53
+
54
+ X-RTD-Hosting-Integrations-Version (required): javascript client version.
55
+ It's used by the endpoint to decide what's the JSON structure compatible with the client
56
+ (e.g. ``1.0.2``)
57
+
58
+ X-RTD-Hosting-Integrations-API-Version (optional): force the endpoint to return a specific
59
+ JSON structure in particular. Used by theme authors to keep compatibility with
60
+ their integration (e.g. ``1``)
47
61
"""
48
62
49
63
def get (self , request ):
@@ -63,10 +77,22 @@ def get(self, request):
63
77
},
64
78
status = 400 ,
65
79
)
80
+
81
+ addons_version_explicit = request .headers .get (
82
+ "X-RTD-Hosting-Integrations-API-Version"
83
+ )
66
84
try :
67
85
addons_version = packaging .version .parse (addons_version )
68
86
if addons_version .major not in ADDONS_VERSIONS_SUPPORTED :
69
87
raise ClientError
88
+
89
+ if addons_version_explicit :
90
+ addons_version_explicit = packaging .version .parse (
91
+ addons_version_explicit
92
+ )
93
+ if addons_version_explicit .major not in ADDONS_VERSIONS_SUPPORTED :
94
+ raise ClientError
95
+
70
96
except packaging .version .InvalidVersion :
71
97
return JsonResponse (
72
98
{
@@ -90,7 +116,13 @@ def get(self, request):
90
116
project .get_default_version ()
91
117
build = version .builds .last ()
92
118
93
- data = AddonsResponse ().get (addons_version , project , version , build , filename )
119
+ data = AddonsResponse ().get (
120
+ addons_version_explicit or addons_version ,
121
+ project ,
122
+ version ,
123
+ build ,
124
+ filename ,
125
+ )
94
126
return JsonResponse (data , json_dumps_params = dict (indent = 4 ))
95
127
96
128
@@ -160,6 +192,7 @@ def _v0(self, project, version, build, filename):
160
192
"""
161
193
162
194
data = {
195
+ "api_version" : "0" ,
163
196
"comment" : (
164
197
"THIS RESPONSE IS IN ALPHA FOR TEST PURPOSES ONLY"
165
198
" AND IT'S GOING TO CHANGE COMPLETELY -- DO NOT USE IT!"
@@ -270,5 +303,6 @@ def _v0(self, project, version, build, filename):
270
303
271
304
def _v1 (self , project , version , build , filename ):
272
305
return {
306
+ "api_version" : "1" ,
273
307
"comment" : "Undefined yet. Use v0 for now" ,
274
308
}
0 commit comments