Fixes regression with format=somethingelse
The WebOb 1.2 support patch introduced a regression where an unknown format= query used to just default back to plain but now returns a 400. This will break anyone that uses format=text for instance, or anything else "invalid". Arguably, it makes the most sense to 400 in the case of an invalid format requested, but since it is also a backwards compatibility break, I recommend we keep the previous behavior. Retaining the previous behavior seems less damaging than enforcing the new behavior. Change-Id: I6db015b33a6f3ab239b8cb4a3562ebdba1f76590
This commit is contained in:
parent
ceaf7606fe
commit
de9b81baee
@ -253,9 +253,6 @@ class AccountController(object):
|
||||
content_type='text/plain', request=req)
|
||||
if query_format:
|
||||
qfmt_lower = query_format.lower()
|
||||
if qfmt_lower not in ['xml', 'json', 'plain']:
|
||||
return HTTPBadRequest(body='format not supported',
|
||||
content_type='text/plain', request=req)
|
||||
req.accept = 'application/%s' % qfmt_lower
|
||||
try:
|
||||
out_content_type = req.accept.best_match(
|
||||
|
@ -349,9 +349,6 @@ class ContainerController(object):
|
||||
content_type='text/plain', request=req)
|
||||
if query_format:
|
||||
qfmt_lower = query_format.lower()
|
||||
if qfmt_lower not in ['xml', 'json', 'plain']:
|
||||
return HTTPBadRequest(body='format not supported',
|
||||
content_type='text/plain', request=req)
|
||||
req.accept = 'application/%s' % qfmt_lower
|
||||
try:
|
||||
out_content_type = req.accept.best_match(
|
||||
|
@ -390,6 +390,15 @@ class TestAccountController(unittest.TestCase):
|
||||
self.assertEquals(resp.content_type, 'text/plain')
|
||||
self.assertEquals(resp.charset, 'utf-8')
|
||||
|
||||
# test unknown format uses default plain
|
||||
req = Request.blank('/sda1/p/a?format=somethinglese',
|
||||
environ={'REQUEST_METHOD': 'GET'})
|
||||
resp = self.controller.GET(req)
|
||||
self.assertEquals(resp.status_int, 200)
|
||||
self.assertEquals(resp.body.strip().split('\n'), ['c1', 'c2'])
|
||||
self.assertEquals(resp.content_type, 'text/plain')
|
||||
self.assertEquals(resp.charset, 'utf-8')
|
||||
|
||||
def test_GET_with_containers_json(self):
|
||||
req = Request.blank('/sda1/p/a', environ={'REQUEST_METHOD': 'PUT',
|
||||
'HTTP_X_TIMESTAMP': '0'})
|
||||
@ -995,10 +1004,6 @@ class TestAccountController(unittest.TestCase):
|
||||
environ={'REQUEST_METHOD': 'GET'})
|
||||
resp = self.controller.GET(req)
|
||||
self.assertEquals(resp.status_int, 200)
|
||||
req = Request.blank('/sda1/p/a?format=Foo!',
|
||||
environ={'REQUEST_METHOD': 'GET'})
|
||||
resp = self.controller.GET(req)
|
||||
self.assertEquals(resp.status_int, 400)
|
||||
|
||||
def test_params_utf8(self):
|
||||
self.controller.PUT(Request.blank('/sda1/p/a',
|
||||
|
@ -644,6 +644,14 @@ class TestContainerController(unittest.TestCase):
|
||||
self.assertEquals(resp.content_type, 'text/plain')
|
||||
self.assertEquals(resp.body, plain_body)
|
||||
|
||||
# test unknown format uses default plain
|
||||
req = Request.blank('/sda1/p/a/plainc?format=somethingelse',
|
||||
environ={'REQUEST_METHOD': 'GET'})
|
||||
resp = self.controller.GET(req)
|
||||
self.assertEquals(resp.status_int, 200)
|
||||
self.assertEquals(resp.content_type, 'text/plain')
|
||||
self.assertEquals(resp.body, plain_body)
|
||||
|
||||
def test_GET_json_last_modified(self):
|
||||
# make a container
|
||||
req = Request.blank('/sda1/p/a/jsonc', environ={'REQUEST_METHOD': 'PUT',
|
||||
@ -961,10 +969,6 @@ class TestContainerController(unittest.TestCase):
|
||||
environ={'REQUEST_METHOD': 'GET'})
|
||||
resp = self.controller.GET(req)
|
||||
self.assertEquals(resp.status_int, 200)
|
||||
req = Request.blank('/sda1/p/a/c?format=Foo!',
|
||||
environ={'REQUEST_METHOD': 'GET'})
|
||||
resp = self.controller.GET(req)
|
||||
self.assertEquals(resp.status_int, 400)
|
||||
|
||||
def test_params_utf8(self):
|
||||
self.controller.PUT(Request.blank('/sda1/p/a/c',
|
||||
|
Loading…
x
Reference in New Issue
Block a user