domain_remap bugfixes
This commit is contained in:
parent
00ff1d2c38
commit
d13b3b318d
@ -32,15 +32,18 @@ class DomainRemapMiddleware(object):
|
|||||||
def __init__(self, app, conf):
|
def __init__(self, app, conf):
|
||||||
self.app = app
|
self.app = app
|
||||||
self.storage_domain = conf.get('storage_domain', 'example.com')
|
self.storage_domain = conf.get('storage_domain', 'example.com')
|
||||||
|
if self.storage_domain and self.storage_domain[0] != '.':
|
||||||
|
self.storage_domain = '.' + self.storage_domain
|
||||||
self.path_root = conf.get('path_root', 'v1').strip('/')
|
self.path_root = conf.get('path_root', 'v1').strip('/')
|
||||||
|
|
||||||
def __call__(self, env, start_response):
|
def __call__(self, env, start_response):
|
||||||
|
if not self.storage_domain:
|
||||||
|
return self.app(env, start_response)
|
||||||
given_domain = env['HTTP_HOST']
|
given_domain = env['HTTP_HOST']
|
||||||
port = ''
|
port = ''
|
||||||
if ':' in given_domain:
|
if ':' in given_domain:
|
||||||
given_domain, port = given_domain.rsplit(':', 1)
|
given_domain, port = given_domain.rsplit(':', 1)
|
||||||
if given_domain != self.storage_domain and \
|
if given_domain.endswith(self.storage_domain):
|
||||||
given_domain.endswith(self.storage_domain):
|
|
||||||
parts_to_parse = given_domain[:-len(self.storage_domain)]
|
parts_to_parse = given_domain[:-len(self.storage_domain)]
|
||||||
parts_to_parse = parts_to_parse.strip('.').split('.')
|
parts_to_parse = parts_to_parse.strip('.').split('.')
|
||||||
len_parts_to_parse = len(parts_to_parse)
|
len_parts_to_parse = len(parts_to_parse)
|
||||||
|
@ -87,5 +87,20 @@ class TestDomainRemap(unittest.TestCase):
|
|||||||
resp = self.app(req.environ, start_response)
|
resp = self.app(req.environ, start_response)
|
||||||
self.assertEquals(resp, '/v1/a/c/obj')
|
self.assertEquals(resp, '/v1/a/c/obj')
|
||||||
|
|
||||||
|
def test_domain_remap_account_matching_ending_not_domain(self):
|
||||||
|
req = Request.blank('/dontchange', environ={'REQUEST_METHOD': 'GET'},
|
||||||
|
headers={'Host': 'c.aexample.com'})
|
||||||
|
resp = self.app(req.environ, start_response)
|
||||||
|
self.assertEquals(resp, '/dontchange')
|
||||||
|
|
||||||
|
def test_domain_remap_configured_with_empty_storage_domain(self):
|
||||||
|
self.app = domain_remap.DomainRemapMiddleware(FakeApp(),
|
||||||
|
{'storage_domain': ''})
|
||||||
|
req = Request.blank('/test', environ={'REQUEST_METHOD': 'GET'},
|
||||||
|
headers={'Host': 'c.a.example.com'})
|
||||||
|
resp = self.app(req.environ, start_response)
|
||||||
|
self.assertEquals(resp, '/test')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
Loading…
x
Reference in New Issue
Block a user