diff --git a/swift/common/middleware/cname_lookup.py b/swift/common/middleware/cname_lookup.py index 87363b2308..86f7d9e15e 100644 --- a/swift/common/middleware/cname_lookup.py +++ b/swift/common/middleware/cname_lookup.py @@ -84,7 +84,10 @@ class CNAMELookupMiddleware(object): def __call__(self, env, start_response): if not self.storage_domain: return self.app(env, start_response) - given_domain = env['HTTP_HOST'] + if 'HTTP_HOST' in env: + given_domain = env['HTTP_HOST'] + else: + given_domain = env['SERVER_NAME'] port = '' if ':' in given_domain: given_domain, port = given_domain.rsplit(':', 1) diff --git a/swift/common/middleware/domain_remap.py b/swift/common/middleware/domain_remap.py index 025ae4b050..7f88435ff5 100644 --- a/swift/common/middleware/domain_remap.py +++ b/swift/common/middleware/domain_remap.py @@ -78,7 +78,10 @@ class DomainRemapMiddleware(object): def __call__(self, env, start_response): if not self.storage_domain: return self.app(env, start_response) - given_domain = env['HTTP_HOST'] + if 'HTTP_HOST' in env: + given_domain = env['HTTP_HOST'] + else: + given_domain = env['SERVER_NAME'] port = '' if ':' in given_domain: given_domain, port = given_domain.rsplit(':', 1) diff --git a/test/unit/common/middleware/test_cname_lookup.py b/test/unit/common/middleware/test_cname_lookup.py index 13a5e71bf1..d8df5cf21f 100644 --- a/test/unit/common/middleware/test_cname_lookup.py +++ b/test/unit/common/middleware/test_cname_lookup.py @@ -58,6 +58,11 @@ class TestCNAMELookup(unittest.TestCase): headers={'Host': 'foo.example.com:8080'}) resp = self.app(req.environ, start_response) self.assertEquals(resp, 'FAKE APP') + req = Request.blank('/', environ={'REQUEST_METHOD': 'GET', + 'SERVER_NAME': 'foo.example.com'}, + headers={'Host': None}) + resp = self.app(req.environ, start_response) + self.assertEquals(resp, 'FAKE APP') def test_good_lookup(self): req = Request.blank('/', environ={'REQUEST_METHOD': 'GET'}, @@ -73,6 +78,11 @@ class TestCNAMELookup(unittest.TestCase): headers={'Host': 'mysite.com:8080'}) resp = self.app(req.environ, start_response) self.assertEquals(resp, 'FAKE APP') + req = Request.blank('/', environ={'REQUEST_METHOD': 'GET', + 'SERVER_NAME': 'mysite.com'}, + headers={'Host': None}) + resp = self.app(req.environ, start_response) + self.assertEquals(resp, 'FAKE APP') def test_lookup_chain_too_long(self): req = Request.blank('/', environ={'REQUEST_METHOD': 'GET'}, diff --git a/test/unit/common/middleware/test_domain_remap.py b/test/unit/common/middleware/test_domain_remap.py index 897ce50baf..97c80d16aa 100644 --- a/test/unit/common/middleware/test_domain_remap.py +++ b/test/unit/common/middleware/test_domain_remap.py @@ -35,6 +35,11 @@ class TestDomainRemap(unittest.TestCase): self.app = domain_remap.DomainRemapMiddleware(FakeApp(), {}) def test_domain_remap_passthrough(self): + req = Request.blank('/', environ={'REQUEST_METHOD': 'GET', + 'SERVER_NAME': 'example.com'}, + headers={'Host': None}) + resp = self.app(req.environ, start_response) + self.assertEquals(resp, '/') req = Request.blank('/', environ={'REQUEST_METHOD': 'GET'}, headers={'Host': 'example.com'}) resp = self.app(req.environ, start_response) @@ -45,6 +50,11 @@ class TestDomainRemap(unittest.TestCase): self.assertEquals(resp, '/') def test_domain_remap_account(self): + req = Request.blank('/', environ={'REQUEST_METHOD': 'GET', + 'SERVER_NAME': 'AUTH_a.example.com'}, + headers={'Host': None}) + resp = self.app(req.environ, start_response) + self.assertEquals(resp, '/v1/AUTH_a') req = Request.blank('/', environ={'REQUEST_METHOD': 'GET'}, headers={'Host': 'AUTH_a.example.com'}) resp = self.app(req.environ, start_response)