Merge "Small change to staticweb with container reques..."
This commit is contained in:
@@ -387,6 +387,8 @@ class StaticWeb(object):
|
|||||||
"""
|
"""
|
||||||
self._get_container_info(env, start_response)
|
self._get_container_info(env, start_response)
|
||||||
if not self._listings and not self._index:
|
if not self._listings and not self._index:
|
||||||
|
if env.get('HTTP_X_WEB_MODE', 'f').lower() in TRUE_VALUES:
|
||||||
|
return HTTPNotFound()(env, start_response)
|
||||||
return self.app(env, start_response)
|
return self.app(env, start_response)
|
||||||
if env['PATH_INFO'][-1] != '/':
|
if env['PATH_INFO'][-1] != '/':
|
||||||
resp = HTTPMovedPermanently(
|
resp = HTTPMovedPermanently(
|
||||||
|
|||||||
@@ -355,6 +355,16 @@ class TestStaticWeb(unittest.TestCase):
|
|||||||
resp = Request.blank('/v1/a/c1').get_response(self.test_staticweb)
|
resp = Request.blank('/v1/a/c1').get_response(self.test_staticweb)
|
||||||
self.assertEquals(resp.status_int, 401)
|
self.assertEquals(resp.status_int, 401)
|
||||||
|
|
||||||
|
def test_container1_web_mode_explicitly_off(self):
|
||||||
|
resp = Request.blank('/v1/a/c1',
|
||||||
|
headers={'x-web-mode': 'false'}).get_response(self.test_staticweb)
|
||||||
|
self.assertEquals(resp.status_int, 401)
|
||||||
|
|
||||||
|
def test_container1_web_mode_explicitly_on(self):
|
||||||
|
resp = Request.blank('/v1/a/c1',
|
||||||
|
headers={'x-web-mode': 'true'}).get_response(self.test_staticweb)
|
||||||
|
self.assertEquals(resp.status_int, 404)
|
||||||
|
|
||||||
def test_container2(self):
|
def test_container2(self):
|
||||||
resp = Request.blank('/v1/a/c2').get_response(self.test_staticweb)
|
resp = Request.blank('/v1/a/c2').get_response(self.test_staticweb)
|
||||||
self.assertEquals(resp.status_int, 200)
|
self.assertEquals(resp.status_int, 200)
|
||||||
@@ -362,6 +372,19 @@ class TestStaticWeb(unittest.TestCase):
|
|||||||
self.assertEquals(len(resp.body.split('\n')),
|
self.assertEquals(len(resp.body.split('\n')),
|
||||||
int(resp.headers['x-container-object-count']))
|
int(resp.headers['x-container-object-count']))
|
||||||
|
|
||||||
|
def test_container2_web_mode_explicitly_off(self):
|
||||||
|
resp = Request.blank('/v1/a/c2',
|
||||||
|
headers={'x-web-mode': 'false'}).get_response(self.test_staticweb)
|
||||||
|
self.assertEquals(resp.status_int, 200)
|
||||||
|
self.assertEquals(resp.content_type, 'text/plain')
|
||||||
|
self.assertEquals(len(resp.body.split('\n')),
|
||||||
|
int(resp.headers['x-container-object-count']))
|
||||||
|
|
||||||
|
def test_container2_web_mode_explicitly_on(self):
|
||||||
|
resp = Request.blank('/v1/a/c2',
|
||||||
|
headers={'x-web-mode': 'true'}).get_response(self.test_staticweb)
|
||||||
|
self.assertEquals(resp.status_int, 404)
|
||||||
|
|
||||||
def test_container2onetxt(self):
|
def test_container2onetxt(self):
|
||||||
resp = Request.blank(
|
resp = Request.blank(
|
||||||
'/v1/a/c2/one.txt').get_response(self.test_staticweb)
|
'/v1/a/c2/one.txt').get_response(self.test_staticweb)
|
||||||
@@ -375,6 +398,19 @@ class TestStaticWeb(unittest.TestCase):
|
|||||||
self.assertEquals(len(json.loads(resp.body)),
|
self.assertEquals(len(json.loads(resp.body)),
|
||||||
int(resp.headers['x-container-object-count']))
|
int(resp.headers['x-container-object-count']))
|
||||||
|
|
||||||
|
def test_container2json_web_mode_explicitly_off(self):
|
||||||
|
resp = Request.blank('/v1/a/c2?format=json',
|
||||||
|
headers={'x-web-mode': 'false'}).get_response(self.test_staticweb)
|
||||||
|
self.assertEquals(resp.status_int, 200)
|
||||||
|
self.assertEquals(resp.content_type, 'application/json')
|
||||||
|
self.assertEquals(len(json.loads(resp.body)),
|
||||||
|
int(resp.headers['x-container-object-count']))
|
||||||
|
|
||||||
|
def test_container2json_web_mode_explicitly_on(self):
|
||||||
|
resp = Request.blank('/v1/a/c2?format=json',
|
||||||
|
headers={'x-web-mode': 'true'}).get_response(self.test_staticweb)
|
||||||
|
self.assertEquals(resp.status_int, 404)
|
||||||
|
|
||||||
def test_container3(self):
|
def test_container3(self):
|
||||||
resp = Request.blank('/v1/a/c3').get_response(self.test_staticweb)
|
resp = Request.blank('/v1/a/c3').get_response(self.test_staticweb)
|
||||||
self.assertEquals(resp.status_int, 301)
|
self.assertEquals(resp.status_int, 301)
|
||||||
|
|||||||
Reference in New Issue
Block a user