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
This commit is contained in:
Kota Tsuyuzaki 2013-07-23 19:28:08 -07:00
parent d1eeab9560
commit 0508842470
2 changed files with 15 additions and 1 deletions

View File

@ -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,

View File

@ -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)