POST /servers with incorrect content-type returns 400, should be 415

Bug #1567977 reported by Chris Dent
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Compute (nova)
Fix Released
Low
Brandon Iz
Liberty
Fix Released
Undecided
Ghanshyam Mann
Mitaka
Fix Released
Undecided
Matt Riedemann

Bug Description

(master nova april 8, 2016)

POSTing to /servers with a content-type of text/plain and a text/plain body results in a response code of 400. This is incorrect. It should be 415: <https://httpstatuses.com/415>

Here's the gabbi demo:

- name: post bad content-type
  xfail: True
  POST: /servers
  request_headers:
      content-type: text/plain
  data: I want a server so badly
  status: 415

Tags: api gabbi
Revision history for this message
Chris Dent (cdent) wrote :

Presumably this is happening in part because the content type header is being ignored and the content is being treated as JSON and doesn't remotely begin to parse, spawning the 400 you'd expect then. However, there's an earlier stage of processing that should be checking the content-type.

Changed in nova:
status: New → Confirmed
importance: Undecided → Low
Chris Dent (cdent)
tags: added: gabbi
Brandon Iz (iz-brandon)
Changed in nova:
assignee: nobody → Brandon Iz (iz-brandon)
Revision history for this message
Brandon Iz (iz-brandon) wrote :

I was able to recreate the output listed above when sending said HTTP request. I believe I have found a potential easy fix for the bug in the code, however I am in the process of confirming this is an actual fix before posting anything for review.

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/304958

Changed in nova:
status: Confirmed → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to nova (master)

Reviewed: https://review.openstack.org/304958
Committed: https://git.openstack.org/cgit/openstack/nova/commit/?id=a7019a87ba696509d825c6c6f2220331e4ffb033
Submitter: Jenkins
Branch: master

commit a7019a87ba696509d825c6c6f2220331e4ffb033
Author: Brandon Irizarry <email address hidden>
Date: Wed Apr 13 05:18:25 2016 +0000

    Changed an HTTP exception to return proper code

    POSTing to /servers with a content-type of text/plain
    and a text/plain body results in a response code of 400.
    It should be 415. I found this line in the code that
    appears to handle this singular case and modified
    the HTTP exception used to the correct one. Tests were
    also updated accordingly.

    Change-Id: I5fa1fdba56803b2ef63b1efaaeeced6ceb7779d9
    Closes-Bug: 1567977

Changed in nova:
status: In Progress → Fix Released
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to nova (stable/mitaka)

Fix proposed to branch: stable/mitaka
Review: https://review.openstack.org/308474

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Related fix proposed to nova (master)

Related fix proposed to branch: master
Review: https://review.openstack.org/308519

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to nova (stable/liberty)

Fix proposed to branch: stable/liberty
Review: https://review.openstack.org/308823

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Related fix merged to nova (master)

Reviewed: https://review.openstack.org/308519
Committed: https://git.openstack.org/cgit/openstack/nova/commit/?id=e7811038417a34f59e7cbf6652c28914c4686ae9
Submitter: Jenkins
Branch: master

commit e7811038417a34f59e7cbf6652c28914c4686ae9
Author: Matt Riedemann <email address hidden>
Date: Wed Apr 20 14:15:49 2016 -0400

    Add 415 to list of exceptions for microversions devref

    There was some confusion/debate in reviewing
    I5fa1fdba56803b2ef63b1efaaeeced6ceb7779d9 and whether or
    not it required a microversion to change the response code.

    This was a pretty common sense scenario where 415 was a
    more appropriate error code for 400 and is a better client
    experience when hitting that error.

    This change updates the potentially confusing part of the
    devref about this and adds a note to ask the Nova API
    subteam when in doubt about whether or not a microversion
    is needed for changing error codes.

    Change-Id: I8a2836076b7fadc697bdc013578c3d777d02a833
    Related-Bug: #1567977

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to nova (stable/mitaka)

Reviewed: https://review.openstack.org/308474
Committed: https://git.openstack.org/cgit/openstack/nova/commit/?id=d627ae852618fff9eebfc27fdf73287e45b1a7c7
Submitter: Jenkins
Branch: stable/mitaka

commit d627ae852618fff9eebfc27fdf73287e45b1a7c7
Author: Brandon Irizarry <email address hidden>
Date: Wed Apr 13 05:18:25 2016 +0000

    Changed an HTTP exception to return proper code

    POSTing to /servers with a content-type of text/plain
    and a text/plain body results in a response code of 400.
    It should be 415. I found this line in the code that
    appears to handle this singular case and modified
    the HTTP exception used to the correct one. Tests were
    also updated accordingly.

    Change-Id: I5fa1fdba56803b2ef63b1efaaeeced6ceb7779d9
    Closes-Bug: 1567977
    (cherry picked from commit a7019a87ba696509d825c6c6f2220331e4ffb033)

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to nova (stable/liberty)

Reviewed: https://review.openstack.org/308823
Committed: https://git.openstack.org/cgit/openstack/nova/commit/?id=f6f0d1bae8b67c2d8617f87dbc453a60943883c3
Submitter: Jenkins
Branch: stable/liberty

commit f6f0d1bae8b67c2d8617f87dbc453a60943883c3
Author: Brandon Irizarry <email address hidden>
Date: Wed Apr 13 05:18:25 2016 +0000

    Changed an HTTP exception to return proper code

    POSTing to /servers with a content-type of text/plain
    and a text/plain body results in a response code of 400.
    It should be 415. I found this line in the code that
    appears to handle this singular case and modified
    the HTTP exception used to the correct one. Tests were
    also updated accordingly.

    Conflicts:
            nova/api/openstack/wsgi.py
            nova/tests/unit/api/openstack/compute/legacy_v2/test_servers.py

    Change-Id: I5fa1fdba56803b2ef63b1efaaeeced6ceb7779d9
    Closes-Bug: 1567977
    (cherry picked from commit a7019a87ba696509d825c6c6f2220331e4ffb033)

Revision history for this message
Davanum Srinivas (DIMS) (dims-v) wrote : Fix included in openstack/nova 14.0.0.0b1

This issue was fixed in the openstack/nova 14.0.0.0b1 development milestone.

Revision history for this message
Doug Hellmann (doug-hellmann) wrote : Fix included in openstack/nova 12.0.4

This issue was fixed in the openstack/nova 12.0.4 release.

Revision history for this message
Doug Hellmann (doug-hellmann) wrote : Fix included in openstack/nova 13.1.0

This issue was fixed in the openstack/nova 13.1.0 release.

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.