summaryrefslogtreecommitdiff
path: root/nova/api/openstack/wsgi.py
diff options
context:
space:
mode:
authorChris Dent <cdent@anticdent.org>2016-03-31 17:16:51 +0100
committerChris Dent <cdent@anticdent.org>2016-05-25 21:41:27 +0000
commitbd199e3f9b7336b2cbc583fc6ab352f6e5b4d143 (patch)
treede4c72c2a877678f3d35c71b109d0130d7b1bf53 /nova/api/openstack/wsgi.py
parent14d6a424ff6f71c7bdd263436a3aff11d654252c (diff)
downloadnova-bd199e3f9b7336b2cbc583fc6ab352f6e5b4d143.tar.gz
Support for both microversion headers
In this change the new OpenStack-API-Version headers is allowed, but not required, for requesting a microversion. Both headers are accepted in the request and both headers are sent in the response (both the header and its value, and the addition to the Vary header). Many tests which explicitly use a microversion header have been updated to use both. This change is not 100% as most of the tests are testing the handling of the value of the header, not which header is involved. Partially-Implements: blueprint modern-microversions Change-Id: I68da13b5ba0c2f3357523e765a5b9db81899daf1
Diffstat (limited to 'nova/api/openstack/wsgi.py')
-rw-r--r--nova/api/openstack/wsgi.py19
1 files changed, 13 insertions, 6 deletions
diff --git a/nova/api/openstack/wsgi.py b/nova/api/openstack/wsgi.py
index eddf4cbf19..a9e6fe850a 100644
--- a/nova/api/openstack/wsgi.py
+++ b/nova/api/openstack/wsgi.py
@@ -71,9 +71,10 @@ DEFAULT_API_VERSION = "2.1"
# name of attribute to keep version method information
VER_METHOD_ATTR = 'versioned_methods'
-# Name of header used by clients to request a specific version
+# Names of headers used by clients to request a specific version
# of the REST API
-API_VERSION_REQUEST_HEADER = 'X-OpenStack-Nova-API-Version'
+API_VERSION_REQUEST_HEADER = 'OpenStack-API-Version'
+LEGACY_API_VERSION_REQUEST_HEADER = 'X-OpenStack-Nova-API-Version'
ENV_LEGACY_V2 = 'openstack.legacy_v2'
@@ -230,7 +231,7 @@ class Request(wsgi.Request):
"""Set API version request based on the request header information."""
hdr_string = microversion_parse.get_version(
self.headers, service_type='compute',
- legacy_headers=[API_VERSION_REQUEST_HEADER])
+ legacy_headers=[LEGACY_API_VERSION_REQUEST_HEADER])
if hdr_string is None:
self.api_version_request = api_version.APIVersionRequest(
@@ -767,8 +768,11 @@ class Resource(wsgi.Application):
if not request.api_version_request.is_null():
response.headers[API_VERSION_REQUEST_HEADER] = \
+ 'compute ' + request.api_version_request.get_string()
+ response.headers[LEGACY_API_VERSION_REQUEST_HEADER] = \
request.api_version_request.get_string()
- response.headers['Vary'] = API_VERSION_REQUEST_HEADER
+ response.headers.add('Vary', API_VERSION_REQUEST_HEADER)
+ response.headers.add('Vary', LEGACY_API_VERSION_REQUEST_HEADER)
return response
@@ -1121,9 +1125,12 @@ class Fault(webob.exc.HTTPException):
if not req.api_version_request.is_null():
self.wrapped_exc.headers[API_VERSION_REQUEST_HEADER] = \
+ 'compute ' + req.api_version_request.get_string()
+ self.wrapped_exc.headers[LEGACY_API_VERSION_REQUEST_HEADER] = \
req.api_version_request.get_string()
- self.wrapped_exc.headers['Vary'] = \
- API_VERSION_REQUEST_HEADER
+ self.wrapped_exc.headers.add('Vary', API_VERSION_REQUEST_HEADER)
+ self.wrapped_exc.headers.add('Vary',
+ LEGACY_API_VERSION_REQUEST_HEADER)
self.wrapped_exc.content_type = 'application/json'
self.wrapped_exc.charset = 'UTF-8'