Service discovery

class ahoyhoy.servicediscovery.ServiceDiscoveryHttpClient(*args, **kwargs)[source]

Bases: ahoyhoy.servicediscovery.servicediscovery.ServiceDiscoveryAdapter, ahoyhoy.http.proxy.SessionProxy

An object that transparently allows Service Discovery while preserving the same API as a Requests Session object, so typical Requests methods take server-relative paths rather than full URLs.

For instance, here’s how you can make a Http GET request using Requests’s standard get method.

>>> from ahoyhoy.servicediscovery import ServiceDiscoveryHttpClient
>>> from ahoyhoy.utils import Host
>>> host = Host('google.com', '80')
>>> sdhc = ServiceDiscoveryHttpClient(host)
>>> sdhc.get('/')
<Response [200]>

Note the fact that we’re passing get a path, _not_ a URL.

Why?

When using a form of Service Discovery, host/port (and sometimes protocol) portions of the URL are resolved at runtime. This class adapts the a Requests Session in order to support this runtime service resolution.

class ahoyhoy.servicediscovery.servicediscovery.ServiceDiscoveryAdapter(host, *args, **kwargs)[source]

Adapter intended to be used as a mixin along with a SessionProxy in order to calculate a protocol://host:port string to be added to the path for a complete url.

address

Returns the endpoint’s address

calculate_protocol(port)[source]

Use port for calculating the protocol.

Parameters:port
host

Returns the endpoint’s host

port

Returns the endpoint’s port

pre_callback(urlpath)[source]

Calculate and return the url to be passed to the Requests Session, using self.url (calculated from self.[host|port|protocol]).

url

Returns the ‘protocol://host:port’ url