HTTP service

The HTTPService and the HTTPDispatcher are responsible for exposing registered WSGI components to the world. While the HTTPService is just providing the raw HTTP service, the HTTPDispatcher is redirecting a path to a module.


class clacks.agent.httpd.HTTPDispatcher

The HTTPDispatcher can be used to register WSGI applications to a given path. It will inspect the path of an incoming request and decides which registered application it gets.

Analyzing the path can be configured to detect a subtree match or an exact match. If you need subtree matches, just add the class variable http_subtree to the WSGI class and set it to True.

class clacks.agent.httpd.HTTPService

Class to serve HTTP fragments to the interested client. It makes makes use of a couple of configuration flags provided by the clacks configuration files [http] section:

Key Description
url AMQP URL to connect to the broker
id User name to connect with
key Password to connect with
command-worker Number of worker processes

Example:

[http]
host = node1.intranet.gonicus.de
port = 8080
sslpemfile = /etc/clacks/host.pem

If you want to create a clacks agent module that is going to export functionality (i.e. static content or some RPC functionality) you can register such a component like this:

>>> from clacks.common.components import PluginRegistry
>>> class SomeTest(object):
...    http_subtree = True
...    path = '/test'
...
...    def __init__(self):
...        # Get http service instance
...        self.__http = PluginRegistry.getInstance('HTTPService')
...
...        # Register ourselves
...        self.__http.register(self.path, self)
...

When SomeTest is instantiated, it will register itself to the HTTPService - and will be served when the HTTPService starts up.

register(path, app)

Register the application app on path path.

Parameter Description
path Path part of an URL - i.e. ‘/rpc’
app WSGI application
register_static(path, local_path)

Register a static directory local_path in the web servers path.

Parameter Description
path Path part of an URL - i.e. ‘/static’
local_path Local path to serve from - i.e. ‘/var/www’
register_ws(path, app)

Register the websocket application app on path path.

Parameter Description
path Path part of an URL - i.e. ‘/ws’
app WSGI application
serve()

Start HTTP service thread.

stop()

Stop HTTP service thread.