[placement] default to accept of application/json when */*
In change Ice27c7080fc2df097cb387f7438c0aaf32b4c63d the placement api was changed to set the accept header to application/json if the accept header was not set. This was done to ensure that error responses are formatted as JSON in the face of automation that webob does when formatting errors. That change was incomplete. Apparently many clients, notably requests, which backs keystoneauth1, sets a default Accept header of '*/*'. This is a reasonable default but means our error formatting default can go awry. This fixes it in the simplest way possible. See the referenced change above for discussion on why doing this with a microversion would be pointless. Tested with a simple gabbi confirmation. Change-Id: I3df5b9fb8fe7c0e41f7e1f495758973423485e11 Closes-Bug: #1771384
This commit is contained in:
parent
b2798b7c4d
commit
44e2d7ae8b
@ -36,9 +36,10 @@ class RequestLog(object):
|
||||
LOG.debug('Starting request: %s "%s %s"',
|
||||
environ['REMOTE_ADDR'], environ['REQUEST_METHOD'],
|
||||
self._get_uri(environ))
|
||||
# Set the accept header if it is not otherwise set. This
|
||||
# Set the accept header if it is not otherwise set or is '*/*'. This
|
||||
# ensures that error responses will be in JSON.
|
||||
if not environ.get('HTTP_ACCEPT'):
|
||||
accept = environ.get('HTTP_ACCEPT')
|
||||
if not accept or accept == '*/*':
|
||||
environ['HTTP_ACCEPT'] = 'application/json'
|
||||
if LOG.isEnabledFor(logging.INFO):
|
||||
return self._log_app(environ, start_response)
|
||||
|
@ -184,3 +184,13 @@ tests:
|
||||
response_forbidden_headers:
|
||||
- last-modified
|
||||
- cache-control
|
||||
|
||||
- name: test starred accept and errors
|
||||
GET: /resource_providers/foo
|
||||
request_headers:
|
||||
accept: "*/*"
|
||||
status: 404
|
||||
response_headers:
|
||||
content-type: application/json
|
||||
response_json_paths:
|
||||
$.errors[0].title: Not Found
|
||||
|
Loading…
x
Reference in New Issue
Block a user