From de9b81baee2b9cbd87c28812ae85bc5020b06774 Mon Sep 17 00:00:00 2001 From: gholt Date: Tue, 31 Jul 2012 02:26:39 +0000 Subject: [PATCH] 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 --- swift/account/server.py | 3 --- swift/container/server.py | 3 --- test/unit/account/test_server.py | 13 +++++++++---- test/unit/container/test_server.py | 12 ++++++++---- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/swift/account/server.py b/swift/account/server.py index 038d8a13b1..783e093de4 100644 --- a/swift/account/server.py +++ b/swift/account/server.py @@ -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( diff --git a/swift/container/server.py b/swift/container/server.py index 6343e8674a..fee43194e8 100644 --- a/swift/container/server.py +++ b/swift/container/server.py @@ -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( diff --git a/test/unit/account/test_server.py b/test/unit/account/test_server.py index 8d66caf461..9451366c85 100644 --- a/test/unit/account/test_server.py +++ b/test/unit/account/test_server.py @@ -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', diff --git a/test/unit/container/test_server.py b/test/unit/container/test_server.py index 618038c3c9..61a71a8441 100644 --- a/test/unit/container/test_server.py +++ b/test/unit/container/test_server.py @@ -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',