In placement api error responses choose poor default content-type

Bug #1674694 reported by Chris Dent
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Compute (nova)
Fix Released
Low
Chris Dent

Bug Description

Because the placement api (up to at least version 1.5) uses webob exceptions and response objects without much modification, when an error response is created it will have a content-type based on any guidance provided in an accept header. If no accept header is present then a textual default (either HTML or text/plain, can't remember right now and it is not relevant) is used.

For a web app that is served through the browser this is a reasonable default, but since the placement api is primarily a JSON-based thing, it would be better to have application/json as the default error format (while still allowing the accept header to be respected).

Now that we are using the wsgi_wrapper.PlacementWsgify decorator on all our handlers, there is now an easy place to make this happen by checking the req for an accept header and if it is not there setting it to application/json for the error response.

Care will need to taken to make sure that any error message that wants to use the value of accept isn't compromised.

Tags: placement
Changed in nova:
assignee: nobody → Pushkar Umaranikar (pushkar-umaranikar)
Sean Dague (sdague)
Changed in nova:
assignee: Pushkar Umaranikar (pushkar-umaranikar) → nobody
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to nova (master)

Fix proposed to branch: master
Review: https://review.openstack.org/518223

Changed in nova:
assignee: nobody → Chris Dent (cdent)
status: Triaged → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to nova (master)

Reviewed: https://review.openstack.org/518223
Committed: https://git.openstack.org/cgit/openstack/nova/commit/?id=f269023c49dcf24fd42a4933fc7d31f3aaa2e64d
Submitter: Zuul
Branch: master

commit f269023c49dcf24fd42a4933fc7d31f3aaa2e64d
Author: Chris Dent <email address hidden>
Date: Tue Nov 7 15:25:31 2017 +1100

    [placement] set accept to application/json if accept not set

    If an incoming request to placement does not set the accept header
    force it to 'application/json'. This not only ensures that error
    responses are in JSON but also that errors early in the middleware
    stack do not cause a key error (see the #1724065 bug).

    This fix is done by checking headers early in the middleware stack
    using the requestlog middleware as a convenient place to do the
    check. This overloads requestlog's purpose, but avoids adding yet
    more middleware (doing so has some small impact per request).

    Fixing bug 1724065 fixes a 500. Fixing bug 1674694 changes (for some
    requests) the content type of the bodies of 400-499 responses. This
    creates a bit of quandry for microversion handling. If a microversion
    is considered required here then it's not clear the global fix is
    worth doing and the 500 fix should be limited the microversion
    middleware. The intent all along has been that responses should
    strive to align with the API-WG errors guideline [1], which assumes
    application/json.

    [1] http://specs.openstack.org/openstack/api-wg/guidelines/errors.html

    Change-Id: Ice27c7080fc2df097cb387f7438c0aaf32b4c63d
    Closes-Bug: #1724065
    Closes-Bug: #1674694

Changed in nova:
status: In Progress → Fix Released
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/nova 17.0.0.0b2

This issue was fixed in the openstack/nova 17.0.0.0b2 development milestone.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.