Merge "Redirects requests from /v# to /v#/ with correct Location header"
This commit is contained in:
commit
00da1750d7
@ -58,7 +58,7 @@ class VersionNegotiationFilter(wsgi.Middleware):
|
||||
else:
|
||||
LOG.debug(_("Using url versioning"))
|
||||
# Remove version in url so it doesn't conflict later
|
||||
req_version = req.path_info_pop()
|
||||
req_version = self._pop_path_info(req)
|
||||
|
||||
try:
|
||||
version = self._match_version_string(req_version)
|
||||
@ -89,3 +89,20 @@ class VersionNegotiationFilter(wsgi.Middleware):
|
||||
raise ValueError()
|
||||
|
||||
return major_version
|
||||
|
||||
def _pop_path_info(self, req):
|
||||
"""
|
||||
'Pops' off the next segment of PATH_INFO, returns the popped
|
||||
segment. Do NOT push it onto SCRIPT_NAME.
|
||||
"""
|
||||
path = req.path_info
|
||||
if not path:
|
||||
return None
|
||||
while path.startswith('/'):
|
||||
path = path[1:]
|
||||
idx = path.find('/')
|
||||
if idx == -1:
|
||||
idx = len(path)
|
||||
r = path[:idx]
|
||||
req.path_info = path[idx:]
|
||||
return r
|
||||
|
@ -18,6 +18,7 @@ import testtools
|
||||
import webob
|
||||
|
||||
import glance.api.common
|
||||
from glance.common import config
|
||||
from glance.common import exception
|
||||
from glance.common import wsgi
|
||||
from glance.tests import utils as test_utils
|
||||
@ -130,14 +131,18 @@ class TestSizeCheckedIter(testtools.TestCase):
|
||||
self.assertRaises(exception.GlanceException, checked_image.next)
|
||||
|
||||
|
||||
class TestMalformedRequest(base.IsolatedUnitTest):
|
||||
class TestMalformedRequest(test_utils.BaseTestCase):
|
||||
def setUp(self):
|
||||
"""Establish a clean test environment"""
|
||||
super(TestMalformedRequest, self).setUp()
|
||||
self.api = test_utils.FakeAuthMiddleware(wsgi.Router.factory(None))
|
||||
self.config(flavor='',
|
||||
group='paste_deploy',
|
||||
config_file='etc/glance-api-paste.ini')
|
||||
self.api = config.load_paste_app('glance-api')
|
||||
|
||||
def test_redirect_incomplete_url(self):
|
||||
"""Test Glance redirects an empty url"""
|
||||
req = webob.Request.blank('')
|
||||
"""Test Glance redirects /v# to /v#/ with correct Location header"""
|
||||
req = webob.Request.blank('/v1.1')
|
||||
res = req.get_response(self.api)
|
||||
self.assertEquals(res.status_int, webob.exc.HTTPFound.code)
|
||||
self.assertEqual('http://localhost/v1/', res.location)
|
||||
|
Loading…
x
Reference in New Issue
Block a user