diff --git a/swift/common/middleware/domain_remap.py b/swift/common/middleware/domain_remap.py index 81798303a9..f9fee98208 100644 --- a/swift/common/middleware/domain_remap.py +++ b/swift/common/middleware/domain_remap.py @@ -32,15 +32,18 @@ class DomainRemapMiddleware(object): def __init__(self, app, conf): self.app = app 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('/') def __call__(self, env, start_response): + if not self.storage_domain: + return self.app(env, start_response) given_domain = env['HTTP_HOST'] port = '' if ':' in given_domain: given_domain, port = given_domain.rsplit(':', 1) - if given_domain != self.storage_domain and \ - given_domain.endswith(self.storage_domain): + if given_domain.endswith(self.storage_domain): parts_to_parse = given_domain[:-len(self.storage_domain)] parts_to_parse = parts_to_parse.strip('.').split('.') len_parts_to_parse = len(parts_to_parse) diff --git a/test/unit/common/middleware/test_domain_remap.py b/test/unit/common/middleware/test_domain_remap.py index 35d6b2ed38..841680be38 100644 --- a/test/unit/common/middleware/test_domain_remap.py +++ b/test/unit/common/middleware/test_domain_remap.py @@ -87,5 +87,20 @@ class TestDomainRemap(unittest.TestCase): resp = self.app(req.environ, start_response) 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__': - unittest.main() \ No newline at end of file + unittest.main()