Return 204 if there is no content
If after serializing the response we do not have a body or headers (for example after a delete), we should return a 204 code.
This commit is contained in:
parent
0b92038f62
commit
0c417288e6
|
@ -104,7 +104,7 @@ class TestComputeController(test_middleware.TestMiddleware):
|
|||
expected_result = ""
|
||||
self.assertContentType(resp)
|
||||
self.assertExpectedResult(expected_result, resp)
|
||||
self.assertEqual(200, resp.status_code)
|
||||
self.assertEqual(204, resp.status_code)
|
||||
|
||||
def test_list_vms_one_vm(self):
|
||||
tenant = fakes.tenants["foo"]
|
||||
|
|
|
@ -68,7 +68,7 @@ class TestMiddleware(base.TestCase):
|
|||
def test_show(self):
|
||||
result = webob.Request.blank("/foos/stop",
|
||||
method="GET").get_response(self.app)
|
||||
self.assertEqual(200, result.status_code)
|
||||
self.assertEqual(204, result.status_code)
|
||||
self.assertEqual("", result.text)
|
||||
|
||||
def test_post(self):
|
||||
|
|
|
@ -302,6 +302,11 @@ class ResponseObject(object):
|
|||
if body:
|
||||
response.body = body
|
||||
|
||||
# 204 should be used if there is no content
|
||||
if (not (headers or body) and
|
||||
response.status_int in [200, 201, 202]):
|
||||
response.status_int = 204
|
||||
|
||||
return response
|
||||
|
||||
@property
|
||||
|
|
Loading…
Reference in New Issue