MCPcopy Index your code
hub / github.com/hugapi/hug / determine_version

Method determine_version

hug/api.py:291–315  ·  view source on GitHub ↗

Determines the appropriate version given the set api_version, the request header, and URL query params

(self, request, api_version=None)

Source from the content-addressed store, hash-verified

289 response.status = falcon.HTTP_NOT_FOUND
290
291 def determine_version(self, request, api_version=None):
292 """Determines the appropriate version given the set api_version, the request header, and URL query params"""
293 if api_version is False:
294 api_version = None
295 for version in self.versions:
296 if version and "v{0}".format(version) in request.path:
297 api_version = version
298 break
299
300 request_version = set()
301 if api_version is not None:
302 request_version.add(api_version)
303
304 version_header = request.get_header("X-API-VERSION")
305 if version_header:
306 request_version.add(version_header)
307
308 version_param = request.get_param("api_version")
309 if version_param is not None:
310 request_version.add(version_param)
311
312 if len(request_version) > 1:
313 raise ValueError("You are requesting conflicting versions")
314
315 return next(iter(request_version or (None,)))
316
317 def documentation_404(self, base_url=None):
318 """Returns a smart 404 page that contains documentation for the written API"""

Callers 2

handle_404Method · 0.95
version_routerMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected