def _check_version_request(self, req, controller): """Set API version request based on the request header and controller. :param req: The webob.Request object. :param controller: The API version controller. :returns: ``None`` :raises: ``HTTPBadRequest`` if API version string is bad. """ api_version = mp.get_version(req.headers, service_type='clustering') if api_version is None: api_version = controller.DEFAULT_API_VERSION elif api_version.lower() == 'latest': req.version_request = controller.max_api_version() return try: ver = vr.APIVersionRequest(api_version) except exception.InvalidAPIVersionString as e: raise webob.exc.HTTPBadRequest(six.text_type(e)) if not ver.matches(controller.min_api_version(), controller.max_api_version()): raise exception.InvalidGlobalAPIVersion( req_ver=api_version, min_ver=six.text_type(controller.min_api_version()), max_ver=six.text_type(controller.max_api_version())) req.version_request = ver
def check_version_request(self, req): """Set API version request based on the request header.""" api_version = wsgi.DEFAULT_API_VERSION key = wsgi.API_VERSION_KEY if key in req.headers: versions = req.headers[key].split(',') for version in versions: svc_ver = version.strip().split(' ') if svc_ver[0].lower() in wsgi.SERVICE_ALIAS: api_version = svc_ver[1] break if api_version.lower() == 'latest': req.version_request = os_ver.max_api_version() return try: ver = vr.APIVersionRequest(api_version) except exception.InvalidAPIVersionString as e: raise webob.exc.HTTPBadRequest(six.text_type(e)) if not ver.matches(os_ver.min_api_version(), os_ver.max_api_version()): raise exception.InvalidGlobalAPIVersion( req_ver=api_version, min_ver=six.text_type(os_ver.min_api_version()), max_ver=six.text_type(os_ver.max_api_version())) req.version_request = ver