Fixed bug in domain_remap and cname_lookup middleware
If domain_remap and cname_lookup received request which has no host header, then returns 500 error. This fixes that problem. Change-Id: Ibb457e9b4cb21181d8243858c04ce255365690da Fixes: bug #1100632
This commit is contained in:
parent
d54a5a93dc
commit
04037aee5d
@ -84,7 +84,10 @@ class CNAMELookupMiddleware(object):
|
|||||||
def __call__(self, env, start_response):
|
def __call__(self, env, start_response):
|
||||||
if not self.storage_domain:
|
if not self.storage_domain:
|
||||||
return self.app(env, start_response)
|
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 = ''
|
port = ''
|
||||||
if ':' in given_domain:
|
if ':' in given_domain:
|
||||||
given_domain, port = given_domain.rsplit(':', 1)
|
given_domain, port = given_domain.rsplit(':', 1)
|
||||||
|
@ -78,7 +78,10 @@ class DomainRemapMiddleware(object):
|
|||||||
def __call__(self, env, start_response):
|
def __call__(self, env, start_response):
|
||||||
if not self.storage_domain:
|
if not self.storage_domain:
|
||||||
return self.app(env, start_response)
|
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 = ''
|
port = ''
|
||||||
if ':' in given_domain:
|
if ':' in given_domain:
|
||||||
given_domain, port = given_domain.rsplit(':', 1)
|
given_domain, port = given_domain.rsplit(':', 1)
|
||||||
|
@ -58,6 +58,11 @@ class TestCNAMELookup(unittest.TestCase):
|
|||||||
headers={'Host': 'foo.example.com:8080'})
|
headers={'Host': 'foo.example.com:8080'})
|
||||||
resp = self.app(req.environ, start_response)
|
resp = self.app(req.environ, start_response)
|
||||||
self.assertEquals(resp, 'FAKE APP')
|
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):
|
def test_good_lookup(self):
|
||||||
req = Request.blank('/', environ={'REQUEST_METHOD': 'GET'},
|
req = Request.blank('/', environ={'REQUEST_METHOD': 'GET'},
|
||||||
@ -73,6 +78,11 @@ class TestCNAMELookup(unittest.TestCase):
|
|||||||
headers={'Host': 'mysite.com:8080'})
|
headers={'Host': 'mysite.com:8080'})
|
||||||
resp = self.app(req.environ, start_response)
|
resp = self.app(req.environ, start_response)
|
||||||
self.assertEquals(resp, 'FAKE APP')
|
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):
|
def test_lookup_chain_too_long(self):
|
||||||
req = Request.blank('/', environ={'REQUEST_METHOD': 'GET'},
|
req = Request.blank('/', environ={'REQUEST_METHOD': 'GET'},
|
||||||
|
@ -35,6 +35,11 @@ class TestDomainRemap(unittest.TestCase):
|
|||||||
self.app = domain_remap.DomainRemapMiddleware(FakeApp(), {})
|
self.app = domain_remap.DomainRemapMiddleware(FakeApp(), {})
|
||||||
|
|
||||||
def test_domain_remap_passthrough(self):
|
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'},
|
req = Request.blank('/', environ={'REQUEST_METHOD': 'GET'},
|
||||||
headers={'Host': 'example.com'})
|
headers={'Host': 'example.com'})
|
||||||
resp = self.app(req.environ, start_response)
|
resp = self.app(req.environ, start_response)
|
||||||
@ -45,6 +50,11 @@ class TestDomainRemap(unittest.TestCase):
|
|||||||
self.assertEquals(resp, '/')
|
self.assertEquals(resp, '/')
|
||||||
|
|
||||||
def test_domain_remap_account(self):
|
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'},
|
req = Request.blank('/', environ={'REQUEST_METHOD': 'GET'},
|
||||||
headers={'Host': 'AUTH_a.example.com'})
|
headers={'Host': 'AUTH_a.example.com'})
|
||||||
resp = self.app(req.environ, start_response)
|
resp = self.app(req.environ, start_response)
|
||||||
|
Loading…
Reference in New Issue
Block a user