Merge pull request #190 from minrk/bind_url

url logging
This commit is contained in:
Min RK
2015-03-24 11:52:33 -07:00
4 changed files with 30 additions and 8 deletions

View File

@@ -75,12 +75,16 @@ class Server(Base):
@property
def host(self):
ip = self.ip
if ip in {'', '0.0.0.0'}:
# when listening on all interfaces, connect to localhost
ip = 'localhost'
return "{proto}://{ip}:{port}".format(
proto=self.proto,
ip=self.ip or 'localhost',
ip=ip,
port=self.port,
)
@property
def url(self):
return "{host}{uri}".format(
@@ -88,6 +92,17 @@ class Server(Base):
uri=self.base_url,
)
@property
def bind_url(self):
"""representation of URL used for binding
Never used in APIs, only logging,
since it can be non-connectable value, such as '', meaning all interfaces.
"""
if self.ip in {'', '0.0.0.0'}:
return self.url.replace('localhost', self.ip or '*', 1)
return self.url
@gen.coroutine
def wait_up(self, timeout=10, http=False):
"""Wait for this server to come up"""