From 0508842470ab27e5635d858bf0f9c8c14e1b300e Mon Sep 17 00:00:00 2001 From: Kota Tsuyuzaki Date: Tue, 23 Jul 2013 19:28:08 -0700 Subject: [PATCH] Fix incorrect status handling at staticweb Staticweb middleware always searchs html for error response when response status code is not redirect. It causes swift to return error response even if the request succeeded. (e.g. When finding index.html with 200, staticweb returns 200error.html if it exist) This patch modifies the constraint on response status and fix bug 1204319. Fixes bug #1204319. Change-Id: Ib83c303917da7fb94999f2d4d35063b450d0e992 --- swift/common/middleware/staticweb.py | 2 +- test/unit/common/middleware/test_staticweb.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/swift/common/middleware/staticweb.py b/swift/common/middleware/staticweb.py index f63bab62e1..8874096beb 100644 --- a/swift/common/middleware/staticweb.py +++ b/swift/common/middleware/staticweb.py @@ -349,7 +349,7 @@ class _StaticWebContext(WSGIContext): status_int = self._get_status_int() if status_int == HTTP_NOT_FOUND: return self._listing(env, start_response) - elif not is_success(self._get_status_int()) or \ + elif not is_success(self._get_status_int()) and \ not is_redirection(self._get_status_int()): return self._error_response(resp, env, start_response) start_response(self._response_status, self._response_headers, diff --git a/test/unit/common/middleware/test_staticweb.py b/test/unit/common/middleware/test_staticweb.py index 2771a2d142..e4d01addc2 100644 --- a/test/unit/common/middleware/test_staticweb.py +++ b/test/unit/common/middleware/test_staticweb.py @@ -54,6 +54,8 @@ meta_map = { 'c11': {'meta': {'web-index': 'index.html'}}, 'c11a': {'meta': {'web-index': 'index.html', 'web-directory-type': 'text/directory'}}, + 'c12': {'meta': {'web-index': 'index.html', + 'web-error': 'error.html'}}, } @@ -232,6 +234,12 @@ class FakeApp(object): 'not_a/directory'})(env, start_response) elif env['PATH_INFO'] == '/v1/a/c11a/subdir3/index.html': return Response(status='404 Not Found')(env, start_response) + elif env['PATH_INFO'] == '/v1/a/c12/index.html': + return Response(status='200 Ok', body='index file')(env, + start_response) + elif env['PATH_INFO'] == '/v1/a/c12/200error.html': + return Response(status='200 Ok', body='error file')(env, + start_response) else: raise Exception('Unknown path %r' % env['PATH_INFO']) @@ -652,6 +660,12 @@ class TestStaticWeb(unittest.TestCase): self.test_staticweb) self.assertEquals(resp.status_int, 200) + def test_container12unredirectedrequest(self): + resp = Request.blank('/v1/a/c12/').get_response( + self.test_staticweb) + self.assertEquals(resp.status_int, 200) + self.assert_('index file' in resp.body) + def test_subrequest_once_if_possible(self): resp = Request.blank( '/v1/a/c4/one.txt').get_response(self.test_staticweb)