Skip to content

Commit

Permalink
Return correct href if bind_host is 0.0.0.0.
Browse files Browse the repository at this point in the history
The existing code returns incorrect href= in the root document (aka
"version" document) if the default configuration is used. If a remote
system accesses Glance API, the netspec of href= contains 0.0.0.0,
which cannot be used for further remote accesses. This happens because
attempts to use local configuration or the bind address to reconstruct
URLs are futile.

The correct way resolve this problem is to use the Host: header
of the HTTP request. As a bonus, it works with IPv6, should we ever
support it.

Change-Id: I661351b679c695bd6ab310104a3246dd3069f9c6
Bug: 915621
  • Loading branch information
zaitcev committed Jan 12, 2012
1 parent c2c805b commit b46401a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions glance/api/versions.py
Expand Up @@ -46,14 +46,14 @@ def __call__(self, req):
"links": [
{
"rel": "self",
"href": self.get_href()}]},
"href": self.get_href(req)}]},
{
"id": "v1.0",
"status": "SUPPORTED",
"links": [
{
"rel": "self",
"href": self.get_href()}]}]
"href": self.get_href(req)}]}]

body = json.dumps(dict(versions=version_objs))

Expand All @@ -64,5 +64,5 @@ def __call__(self, req):

return response

def get_href(self):
return "http://%s:%s/v1/" % wsgi.get_bind_addr(self.conf, 9292)
def get_href(self, req):
return "%s/v1/" % req.host_url
4 changes: 2 additions & 2 deletions glance/tests/functional/test_ssl.py
Expand Up @@ -454,12 +454,12 @@ def test_version_variations(self):
"status": "CURRENT",
"links": [{
"rel": "self",
"href": "http://0.0.0.0:%d/v1/" % self.api_port}]}, {
"href": "https://0.0.0.0:%d/v1/" % self.api_port}]}, {
"id": "v1.0",
"status": "SUPPORTED",
"links": [{
"rel": "self",
"href": "http://0.0.0.0:%d/v1/" % self.api_port}]}]}
"href": "https://0.0.0.0:%d/v1/" % self.api_port}]}]}
versions_json = json.dumps(versions)
images = {'images': []}
images_json = json.dumps(images)
Expand Down
2 changes: 1 addition & 1 deletion glance/tests/unit/test_versions.py
Expand Up @@ -46,7 +46,7 @@ def tearDown(self):
self.stubs.UnsetAll()

def test_get_version_list(self):
req = webob.Request.blank('/')
req = webob.Request.blank('/', base_url="http://0.0.0.0:9292/")
req.accept = "application/json"
conf = utils.TestConfigOpts({
'bind_host': '0.0.0.0',
Expand Down

0 comments on commit b46401a

Please sign in to comment.